|
|
|
@ -13,6 +13,8 @@ import (
|
|
|
|
|
"gosrc.io/xmpp/stanza"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const NSNick string = "http://jabber.org/protocol/nick"
|
|
|
|
|
|
|
|
|
|
// Queue stores presences to send later
|
|
|
|
|
var Queue = make(map[string]*stanza.Presence)
|
|
|
|
|
var QueueLock = sync.Mutex{}
|
|
|
|
@ -52,6 +54,46 @@ func SendMessage(to string, from string, body string, component *xmpp.Component)
|
|
|
|
|
Body: body,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendMessage(&message, component)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNickname sets a new nickname for a contact
|
|
|
|
|
func SetNickname(to string, from string, nickname string, component *xmpp.Component) {
|
|
|
|
|
componentJid := Jid.Bare()
|
|
|
|
|
messageFrom := from + "@" + componentJid
|
|
|
|
|
|
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
|
"from": from,
|
|
|
|
|
"to": to,
|
|
|
|
|
}).Warn("Set nickname")
|
|
|
|
|
|
|
|
|
|
message := stanza.Message{
|
|
|
|
|
Attrs: stanza.Attrs{
|
|
|
|
|
From: messageFrom,
|
|
|
|
|
To: to,
|
|
|
|
|
Type: "headline",
|
|
|
|
|
},
|
|
|
|
|
Extensions: []stanza.MsgExtension{
|
|
|
|
|
stanza.PubSubEvent{
|
|
|
|
|
EventElement: stanza.ItemsEvent{
|
|
|
|
|
Node: NSNick,
|
|
|
|
|
Items: []stanza.ItemEvent{
|
|
|
|
|
stanza.ItemEvent{
|
|
|
|
|
Any: &stanza.Node{
|
|
|
|
|
XMLName: xml.Name{Space: NSNick, Local: "nick"},
|
|
|
|
|
Content: nickname,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendMessage(&message, component)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sendMessage(message *stanza.Message, component *xmpp.Component) {
|
|
|
|
|
// explicit check, as marshalling is expensive
|
|
|
|
|
if log.GetLevel() == log.DebugLevel {
|
|
|
|
|
xmlMessage, err := xml.Marshal(message)
|
|
|
|
|