aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0410_muc_self_ping.vala
blob: 6511789e4382f7848c5d91ac15cd82c30cc80a85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
namespace Xmpp.Xep.MucSelfPing {

    public static async bool is_joined(XmppStream stream, Jid jid) {
        try {
            Iq.Stanza iq_result = yield stream.get_module(Xmpp.Xep.Ping.Module.IDENTITY).send_ping(stream, jid);

            if (!iq_result.is_error()) {
                return true;
            } else {
                var error_stanza = iq_result.get_error();
                if (error_stanza.condition in new string[] {ErrorStanza.CONDITION_SERVICE_UNAVAILABLE, ErrorStanza.CONDITION_FEATURE_NOT_IMPLEMENTED}) {
                    // the client is joined, but the pinged client does not implement XMPP Ping
                    return true;
                }
            }
        } catch (IOError e) {
            // Ignoring, same as if ping failed
        }
        return false;
    }

}