Apply restrictions on muc#admin IQs

This commit is contained in:
Bohdan Horbeshko 2025-06-27 12:57:14 -04:00
parent de74787a48
commit 3b57895237

View file

@ -1194,6 +1194,11 @@ func handleGetQueryMucAdmin(s xmpp.Sender, iq *stanza.IQ, query *extensions.Quer
}
item := query.Items[0]
if item.Role != "" && item.Affiliation != "" {
iqAnswerSetError(answer, 400)
return
}
var membersList telegram.MembersList
switch item.Role {
case "moderator":
@ -1231,12 +1236,18 @@ func handleGetQueryMucAdmin(s xmpp.Sender, iq *stanza.IQ, query *extensions.Quer
if item.Affiliation != "" && affiliation != item.Affiliation {
continue
}
payload.Items = append(payload.Items, &extensions.QueryMucAdminItem{
Jid: gateway.CHATJID(senderId, true),
Nick: nickname,
Role: role,
Affiliation: affiliation,
})
newItem := extensions.QueryMucAdminItem{}
if item.Affiliation == "" || item.Affiliation != "outcast" {
newItem.Nick = nickname
}
if item.Role != "" {
newItem.Role = role
newItem.Jid = gateway.CHATJID(senderId, true)
} else {
newItem.Affiliation = affiliation
newItem.Jid = gateway.CHATJID(senderId, false)
}
payload.Items = append(payload.Items, &newItem)
}
}
}
@ -1798,6 +1809,14 @@ func handleSetQueryMucAdmin(s xmpp.Sender, iq *stanza.IQ, query *extensions.Quer
return
}
if (item.Role != "" && item.Affiliation != "") ||
(item.Role != "" && item.Nick == "") ||
(item.Affiliation != "" && item.Jid == "") {
iqAnswerSetError(answer, 400)
return
}
var userID int64
if item.Jid != "" {
userID, _, _ = toToID(item.Jid)
@ -1813,11 +1832,6 @@ func handleSetQueryMucAdmin(s xmpp.Sender, iq *stanza.IQ, query *extensions.Quer
var status telegram.ChatMemberStatus
if item.Role != "" && item.Affiliation != "" {
iqAnswerSetError(answer, 400)
return
}
switch item.Role {
case "none":
status = telegram.ChatMemberStatusKicked