2019-06-18 14:28:30 +00:00
|
|
|
package xmpp
|
2016-01-06 15:51:12 +00:00
|
|
|
|
|
|
|
import "encoding/xml"
|
|
|
|
|
2018-01-13 17:50:17 +00:00
|
|
|
// ============================================================================
|
|
|
|
// Presence Packet
|
|
|
|
|
2019-06-22 09:13:33 +00:00
|
|
|
// Presence implements RFC 6120 - A.5 Client Namespace (a part)
|
2018-01-13 17:50:17 +00:00
|
|
|
type Presence struct {
|
|
|
|
XMLName xml.Name `xml:"presence"`
|
2019-06-22 09:13:33 +00:00
|
|
|
Attrs
|
|
|
|
Show PresenceShow `xml:"show,omitempty"`
|
|
|
|
Status string `xml:"status,omitempty"`
|
|
|
|
Priority int8 `xml:"priority,omitempty"` // default: 0
|
|
|
|
Error Err `xml:"error,omitempty"`
|
2016-01-06 15:51:12 +00:00
|
|
|
}
|
2018-01-13 17:50:17 +00:00
|
|
|
|
|
|
|
func (Presence) Name() string {
|
|
|
|
return "presence"
|
|
|
|
}
|
|
|
|
|
2019-06-22 09:13:33 +00:00
|
|
|
func NewPresence(a Attrs) Presence {
|
2018-01-25 10:00:20 +00:00
|
|
|
return Presence{
|
|
|
|
XMLName: xml.Name{Local: "presence"},
|
2019-06-22 09:13:33 +00:00
|
|
|
Attrs: a,
|
2018-01-25 10:00:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 17:50:17 +00: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 08:08:21 +00:00
|
|
|
// TODO Add default presence type (when omitted)
|
2018-01-13 17:50:17 +00:00
|
|
|
return packet, err
|
|
|
|
}
|