mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-15 00:15:10 +00:00
2f2a2fd4fd
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.
36 lines
716 B
Go
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
|
|
}
|
|
}
|
|
}
|