2019-06-18 07:28:30 -07:00
|
|
|
package xmpp
|
2016-01-06 07:51:12 -08:00
|
|
|
|
|
|
|
import "encoding/xml"
|
|
|
|
|
2018-01-13 09:50:17 -08:00
|
|
|
// ============================================================================
|
|
|
|
// Presence Packet
|
|
|
|
|
|
|
|
type Presence struct {
|
|
|
|
XMLName xml.Name `xml:"presence"`
|
2018-01-13 08:54:07 -08:00
|
|
|
PacketAttrs
|
2019-02-09 06:18:37 -08:00
|
|
|
Show string `xml:"show,omitempty"` // away, chat, dnd, xa
|
|
|
|
Status string `xml:"status,omitempty"`
|
2019-06-20 09:36:57 -07:00
|
|
|
Priority int `xml:"priority,omitempty"`
|
2018-01-23 00:10:10 -08:00
|
|
|
Error Err `xml:"error,omitempty"`
|
2016-01-06 07:51:12 -08:00
|
|
|
}
|
2018-01-13 09:50:17 -08:00
|
|
|
|
|
|
|
func (Presence) Name() string {
|
|
|
|
return "presence"
|
|
|
|
}
|
|
|
|
|
2018-01-25 02:00:20 -08:00
|
|
|
func NewPresence(from, to, id, lang string) Presence {
|
|
|
|
return Presence{
|
|
|
|
XMLName: xml.Name{Local: "presence"},
|
|
|
|
PacketAttrs: PacketAttrs{
|
|
|
|
Id: id,
|
|
|
|
From: from,
|
|
|
|
To: to,
|
|
|
|
Lang: lang,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 09:50:17 -08:00
|
|
|
type presenceDecoder struct{}
|
|
|
|
|
|
|
|
var presence presenceDecoder
|
|
|
|
|
|
|
|
func (presenceDecoder) decode(p *xml.Decoder, se xml.StartElement) (Presence, error) {
|
|
|
|
var packet Presence
|
|
|
|
err := p.DecodeElement(&packet, &se)
|
2018-01-23 00:08:21 -08:00
|
|
|
// TODO Add default presence type (when omitted)
|
2018-01-13 09:50:17 -08:00
|
|
|
return packet, err
|
|
|
|
}
|