diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2024-02-18 10:48:02 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2024-02-18 10:48:02 +0300 |
commit | 0b1cbda1cc20361b90846b6e8534e016288c301f (patch) | |
tree | 14455753c1627b18be5c1ea5834c4c0fdf315df1 /xmpp/handlers.go | |
parent | 9b5fee88262f22ad14acf621e992167966af278a (diff) |
Show member dropdowns in chat administration forms
Diffstat (limited to 'xmpp/handlers.go')
-rw-r--r-- | xmpp/handlers.go | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/xmpp/handlers.go b/xmpp/handlers.go index 3554394..945f119 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -790,23 +790,59 @@ func handleSetQueryCommand(s xmpp.Sender, iq *stanza.IQ, command *stanza.Command dummyString := "" required = &dummyString } - fields = append(fields, &stanza.Field{ + + var fieldType string + var options []stanza.Option + if toOk && i == 0 { + switch command.Node { + case "mute", "kick", "ban", "promote", "unmute", "unban": + session, ok := sessions[bare] + if ok { + var membersList telegram.MembersList + switch command.Node { + case "unmute": + membersList = telegram.MembersListRestricted + case "unban": + membersList = telegram.MembersListBannedAndAdministrators + } + members, err := session.GetChatMembers(toId, true, "", membersList) + if err == nil { + fieldType = stanza.FieldTypeListSingle + for _, member := range members { + senderId := session.GetSenderId(member.MemberId) + options = append(options, stanza.Option{ + Label: session.FormatContact(senderId), + ValuesList: []string{strconv.FormatInt(senderId, 10)}, + }) + } + } + } + } + } + + field := stanza.Field{ Var: strconv.FormatInt(int64(i), 10), Label: arg, Required: required, - }) + Type: fieldType, + Options: options, + } + fields = append(fields, &field) + log.Debugf("field: %#v", field) + } + form := stanza.Form{ + Type: stanza.FormTypeForm, + Title: command.Node, + Instructions: []string{cmd.Description}, + Fields: fields, } answer.Payload = &stanza.Command{ SessionId: command.Node, Node: command.Node, Status: stanza.CommandStatusExecuting, - CommandElement: &stanza.Form{ - Type: stanza.FormTypeForm, - Title: command.Node, - Instructions: []string{cmd.Description}, - Fields: fields, - }, + CommandElement: &form, } + log.Debugf("form: %#v", form) } else { cmdString = "/" + command.Node } @@ -842,8 +878,9 @@ func handleSetQueryCommand(s xmpp.Sender, iq *stanza.IQ, command *stanza.Command }, } - log.Debugf("command response: %#v", answer.Payload) } + + log.Debugf("command response: %#v", answer.Payload) } func iqAnswerSetError(answer *stanza.IQ, payload *extensions.QueryRegister, code int) { |