go-sendxmpp/iqhandling.go
Martin Dosch 2f2a2fd4fd Rework receiving stanzas.
Calling client.Recv() multiple times caused messages not appear
in `--listen` mode as calling Recv() for receiving IQs (e.g. for
receiving Ox keys) also received the messages so they were no longer
available for the Recv in the listening function.
2022-05-03 12:25:43 +02:00

36 lines
716 B
Go

// Copyright 2020 - 2021 Martin Dosch.
// Use of this source code is governed by the BSD-2-clause
// license that can be found in the LICENSE file.
package main
import (
"github.com/mattn/go-xmpp" // BSD-3-Clause
)
func sendIQ(client *xmpp.Client, iqc chan xmpp.IQ, target string,
iQtype string, content string) (xmpp.IQ, error) {
var iq xmpp.IQ
id := getID()
c := make(chan xmpp.IQ)
go getIQ(client, id, c, iqc)
_, err := client.RawInformation(client.JID(), target, id,
iQtype, content)
if err != nil {
return iq, err
}
iq = <-c
return iq, nil
}
func getIQ(client *xmpp.Client, id string, c chan xmpp.IQ,
iqc chan xmpp.IQ) {
for {
iq := <-iqc
if iq.ID == id {
c <- iq
return
}
}
}