go-xmpp/presence.go

43 lines
968 B
Go
Raw Normal View History

package xmpp // import "gosrc.io/xmpp"
import "encoding/xml"
2018-01-13 17:50:17 +00:00
// ============================================================================
// Presence Packet
type Presence struct {
XMLName xml.Name `xml:"presence"`
2018-01-13 16:54:07 +00:00
PacketAttrs
Show string `xml:"show,omitempty"` // away, chat, dnd, xa
Status string `xml:"status,omitempty"`
Priority string `xml:"priority,omitempty"`
Error Err `xml:"error,omitempty"`
}
2018-01-13 17:50:17 +00:00
func (Presence) Name() string {
return "presence"
}
2018-01-25 10:00:20 +00: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 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
}