aboutsummaryrefslogtreecommitdiff
path: root/xmpp/gateway
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-06-30 03:10:39 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-06-30 03:10:39 +0300
commit5628a15ac496d72c840a265c3dace720e2547728 (patch)
tree7a4a1c68cb320fc58738bb5da23620b8d790c143 /xmpp/gateway
parent38ffdb9e4791652b09d59643c8e0b200c2566e1c (diff)
Update the contact nickname when a chat title has changed
Diffstat (limited to 'xmpp/gateway')
-rw-r--r--xmpp/gateway/gateway.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go
index 4edaec4..367a406 100644
--- a/xmpp/gateway/gateway.go
+++ b/xmpp/gateway/gateway.go
@@ -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)