Fix returning MUC join errors

This commit is contained in:
Bohdan Horbeshko 2023-09-18 01:49:31 -04:00
parent 93abbe834e
commit c1887e5a1e

View file

@ -420,7 +420,9 @@ func handleMUCPresence(s xmpp.Sender, p stanza.Presence) {
return
}
reply := stanza.Presence{Attrs: stanza.Attrs{
// separate declaration is crucial for passing as pointer to defer
var reply *stanza.Presence
reply = &stanza.Presence{Attrs: stanza.Attrs{
From: toBare,
To: p.From,
Id: p.Id,
@ -428,31 +430,31 @@ func handleMUCPresence(s xmpp.Sender, p stanza.Presence) {
defer gateway.ResumableSend(component, reply)
if nickname == "" {
presenceReplySetError(&reply, 400)
presenceReplySetError(reply, 400)
return
}
chatId, ok := toToID(toBare)
if !ok {
presenceReplySetError(&reply, 404)
presenceReplySetError(reply, 404)
return
}
fromBare, _, ok := gateway.SplitJID(p.From)
if !ok {
presenceReplySetError(&reply, 400)
presenceReplySetError(reply, 400)
return
}
session, ok := sessions[fromBare]
if !ok || !session.Session.MUC {
presenceReplySetError(&reply, 401)
presenceReplySetError(reply, 401)
return
}
chat, _, err := session.GetContactByID(chatId, nil)
if err != nil || !session.IsGroup(chat) {
presenceReplySetError(&reply, 404)
presenceReplySetError(reply, 404)
return
}