2
0
mirror of https://github.com/FluuxIO/go-xmpp synced 2024-11-17 15:29:37 +00:00
go-xmpp/message.go

41 lines
921 B
Go
Raw Normal View History

2018-01-01 17:12:33 +00:00
package xmpp // import "fluux.io/xmpp"
import (
"encoding/xml"
"fmt"
)
2018-01-13 17:50:17 +00:00
// ============================================================================
// Message Packet
type Message struct {
XMLName xml.Name `xml:"message"`
2018-01-13 16:54:07 +00:00
PacketAttrs
Subject string `xml:"subject,omitempty"`
Body string `xml:"body,omitempty"`
Thread string `xml:"thread,omitempty"`
}
2018-01-13 17:50:17 +00:00
func (Message) Name() string {
return "message"
}
type messageDecoder struct{}
var message messageDecoder
2018-01-13 17:50:17 +00:00
func (messageDecoder) decode(p *xml.Decoder, se xml.StartElement) (Message, error) {
var packet Message
err := p.DecodeElement(&packet, &se)
return packet, err
}
func (msg *Message) XMPPFormat() string {
return fmt.Sprintf("<message to='%s' type='chat' xml:lang='en'>"+
"<body>%s</body></message>",
2018-01-13 17:50:17 +00:00
msg.To,
xmlEscape(msg.Body))
}
2018-01-13 17:50:17 +00:00
// TODO: Func new message to create an empty message structure without the XML tag matching elements