Accept forms with arbitrary action
This commit is contained in:
parent
21dc5fa6c6
commit
e7d5a2a266
|
@ -706,62 +706,60 @@ func handleSetQueryCommand(s xmpp.Sender, iq *stanza.IQ, command *stanza.Command
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_, toOk := toToID(iq.To)
|
||||||
|
|
||||||
var cmdString string
|
var cmdString string
|
||||||
if command.Action == "" || command.Action == stanza.CommandActionExecute {
|
if !toOk {
|
||||||
_, ok := toToID(iq.To)
|
form, formOk := command.CommandElement.(*stanza.Form)
|
||||||
if !ok {
|
if formOk {
|
||||||
cmd, ok := telegram.GetCommand(telegram.CommandTypeTransport, command.Node)
|
// just for the case the client messed the order somehow
|
||||||
if ok && cmd.RequiredArgs > 0 {
|
sort.Slice(form.Fields, func(i int, j int) bool {
|
||||||
var fields []*stanza.Field
|
iField := form.Fields[i]
|
||||||
for i, arg := range cmd.Arguments {
|
jField := form.Fields[j]
|
||||||
fields = append(fields, &stanza.Field{
|
if iField != nil && jField != nil {
|
||||||
Var: strconv.FormatInt(int64(i), 10),
|
ii, iErr := strconv.ParseInt(iField.Var, 10, 64)
|
||||||
Label: arg,
|
ji, jErr := strconv.ParseInt(jField.Var, 10, 64)
|
||||||
})
|
return iErr == nil && jErr == nil && ii < ji
|
||||||
}
|
}
|
||||||
answer.Payload = &stanza.Command{
|
return false
|
||||||
SessionId: command.Node,
|
})
|
||||||
Node: command.Node,
|
|
||||||
Status: stanza.CommandStatusExecuting,
|
var cmd strings.Builder
|
||||||
CommandElement: &stanza.Form{
|
cmd.WriteString("/")
|
||||||
Title: command.Node,
|
cmd.WriteString(command.Node)
|
||||||
Instructions: []string{cmd.Description},
|
for _, field := range form.Fields {
|
||||||
Fields: fields,
|
cmd.WriteString(" ")
|
||||||
},
|
if len(field.ValuesList) > 0 {
|
||||||
|
cmd.WriteString(field.ValuesList[0])
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cmdString = "/" + command.Node
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if command.Action == stanza.CommandActionComplete {
|
|
||||||
_, ok := toToID(iq.To)
|
|
||||||
if !ok {
|
|
||||||
form, ok := command.CommandElement.(*stanza.Form)
|
|
||||||
if ok {
|
|
||||||
// just for the case the client messed the order somehow
|
|
||||||
sort.Slice(form.Fields, func(i int, j int) bool {
|
|
||||||
iField := form.Fields[i]
|
|
||||||
jField := form.Fields[j]
|
|
||||||
if iField != nil && jField != nil {
|
|
||||||
ii, iErr := strconv.ParseInt(iField.Var, 10, 64)
|
|
||||||
ji, jErr := strconv.ParseInt(jField.Var, 10, 64)
|
|
||||||
return iErr == nil && jErr == nil && ii < ji
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
var cmd strings.Builder
|
cmdString = cmd.String()
|
||||||
cmd.WriteString("/")
|
} else {
|
||||||
cmd.WriteString(command.Node)
|
if command.Action == "" || command.Action == stanza.CommandActionExecute {
|
||||||
for _, field := range form.Fields {
|
cmd, ok := telegram.GetCommand(telegram.CommandTypeTransport, command.Node)
|
||||||
cmd.WriteString(" ")
|
if ok && cmd.RequiredArgs > 0 {
|
||||||
if len(field.ValuesList) > 0 {
|
var fields []*stanza.Field
|
||||||
cmd.WriteString(field.ValuesList[0])
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdString = cmd.String()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue