aboutsummaryrefslogtreecommitdiff
path: root/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp')
-rw-r--r--xmpp/handlers.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index 3ab79c7..eea14be 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -324,7 +324,9 @@ func HandlePresence(s xmpp.Sender, p stanza.Packet) {
prs.Get(&mucExt)
if mucExt.XMLName.Space != "" {
handleMUCPresence(s, prs, mucExt)
+ return
}
+ tryHandleMUCNicknameChange(s, prs)
}
func handleSubscription(s xmpp.Sender, p stanza.Presence) {
@@ -498,6 +500,77 @@ func handleMUCPresence(s xmpp.Sender, p stanza.Presence, mucExt stanza.MucPresen
}
}
+func tryHandleMUCNicknameChange(s xmpp.Sender, p stanza.Presence) {
+ log.WithFields(log.Fields{
+ "type": p.Type,
+ "from": p.From,
+ "to": p.To,
+ }).Warn("Nickname change presence?")
+ log.Debugf("%#v", p)
+
+ if p.Type != "" {
+ return
+ }
+
+ toBare, nickname, ok := gateway.SplitJID(p.To)
+ if !ok || nickname == "" {
+ return
+ }
+
+ fromBare, fromResource, ok := gateway.SplitJID(p.From)
+ if !ok {
+ return
+ }
+
+ session, ok := sessions[fromBare]
+ if !ok || !session.Session.MUC {
+ return
+ }
+
+ chatId, ok := toToID(toBare)
+ if !ok {
+ return
+ }
+
+ chat, _, err := session.GetContactByID(chatId, nil)
+ if err != nil || !session.IsGroup(chat) {
+ return
+ }
+
+ if !session.MUCHasResource(chatId, fromResource) {
+ return
+ }
+
+ log.Warn("🗿 Yes")
+
+ component, ok := s.(*xmpp.Component)
+ if !ok {
+ log.Error("Not a component")
+ return
+ }
+
+ from := toBare
+ nickname, ok = session.GetMyMUCNickname(chatId)
+ if ok {
+ from = from+"/"+nickname
+ }
+ reply := &stanza.Presence{
+ Attrs: stanza.Attrs{
+ From: from,
+ To: p.From,
+ Id: p.Id,
+ Type: stanza.PresenceTypeError,
+ },
+ Error: stanza.Err{
+ Code: 406,
+ Type: stanza.ErrorTypeModify,
+ Reason: "not-acceptable",
+ Text: "Telegram does not support changing nicknames per-chat. Issue a /setname command to the transport if you wish to change the global name",
+ },
+ }
+ gateway.ResumableSend(component, reply)
+}
+
func handleGetVcardIq(s xmpp.Sender, iq *stanza.IQ, typ byte) {
log.WithFields(log.Fields{
"from": iq.From,