Accept forms with arbitrary action

This commit is contained in:
Bohdan Horbeshko 2024-02-03 10:33:37 -05:00
parent 21dc5fa6c6
commit e7d5a2a266

View file

@ -706,39 +706,12 @@ func handleSetQueryCommand(s xmpp.Sender, iq *stanza.IQ, command *stanza.Command
if !ok {
return
}
_, toOk := toToID(iq.To)
var cmdString string
if command.Action == "" || command.Action == stanza.CommandActionExecute {
_, ok := toToID(iq.To)
if !ok {
cmd, ok := telegram.GetCommand(telegram.CommandTypeTransport, command.Node)
if ok && cmd.RequiredArgs > 0 {
var fields []*stanza.Field
for i, arg := range cmd.Arguments {
fields = append(fields, &stanza.Field{
Var: strconv.FormatInt(int64(i), 10),
Label: arg,
})
}
answer.Payload = &stanza.Command{
SessionId: command.Node,
Node: command.Node,
Status: stanza.CommandStatusExecuting,
CommandElement: &stanza.Form{
Title: command.Node,
Instructions: []string{cmd.Description},
Fields: fields,
},
}
} else {
cmdString = "/" + command.Node
}
}
} else if command.Action == stanza.CommandActionComplete {
_, ok := toToID(iq.To)
if !ok {
form, ok := command.CommandElement.(*stanza.Form)
if ok {
if !toOk {
form, formOk := command.CommandElement.(*stanza.Form)
if formOk {
// just for the case the client messed the order somehow
sort.Slice(form.Fields, func(i int, j int) bool {
iField := form.Fields[i]
@ -762,6 +735,31 @@ func handleSetQueryCommand(s xmpp.Sender, iq *stanza.IQ, command *stanza.Command
}
cmdString = cmd.String()
} else {
if command.Action == "" || command.Action == stanza.CommandActionExecute {
cmd, ok := telegram.GetCommand(telegram.CommandTypeTransport, command.Node)
if ok && cmd.RequiredArgs > 0 {
var fields []*stanza.Field
for i, arg := range cmd.Arguments {
fields = append(fields, &stanza.Field{
Var: strconv.FormatInt(int64(i), 10),
Label: arg,
})
}
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,
},
}
} else {
cmdString = "/" + command.Node
}
}
}
}