| 1 |
namespace Xmpp.Xep.OccupantIds { |
| 2 |
|
| 3 |
public const string NS_URI = "urn:xmpp:occupant-id:0"; |
| 4 |
|
| 5 |
public static string? get_occupant_id(StanzaNode stanza) { |
| 6 |
StanzaNode? node = stanza.get_subnode("occupant-id", NS_URI); |
| 7 |
if (node == null) return null; |
| 8 |
|
| 9 |
return node.get_attribute("id"); |
| 10 |
} |
| 11 |
|
| 12 |
public class Module : XmppStreamModule { |
| 13 |
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0421_occupant_ids"); |
| 14 |
|
| 15 |
public signal void received_occupant_id(XmppStream stream, Jid jid, string occupant_id); |
| 16 |
public signal void received_own_occupant_id(XmppStream stream, Jid jid, string occupant_id); |
| 17 |
|
| 18 |
public override void attach(XmppStream stream) { |
| 19 |
stream.get_module(Presence.Module.IDENTITY).received_available.connect(parse_occupant_id_from_presence); |
| 20 |
} |
| 21 |
|
| 22 |
public override void detach(XmppStream stream) { |
| 23 |
stream.get_module(Presence.Module.IDENTITY).received_available.disconnect(parse_occupant_id_from_presence); |
| 24 |
} |
| 25 |
|
| 26 |
public override string get_ns() { return NS_URI; } |
| 27 |
public override string get_id() { return IDENTITY.id; } |
| 28 |
|
| 29 |
public void parse_occupant_id_from_presence(XmppStream stream, Presence.Stanza presence) { |
| 30 |
string? occupant_id = get_occupant_id(presence.stanza); |
| 31 |
if (occupant_id == null) return; |
| 32 |
|
| 33 |
received_occupant_id(stream, presence.from, occupant_id); |
| 34 |
|
| 35 |
StanzaNode? x_node = presence.stanza.get_subnode("x", "http://jabber.org/protocol/muc#user"); |
| 36 |
if (x_node == null) return; |
| 37 |
foreach (StanzaNode status_node in x_node.get_subnodes("status", "http://jabber.org/protocol/muc#user")) { |
| 38 |
if (int.parse(status_node.get_attribute("code")) == 110) { |
| 39 |
received_own_occupant_id(stream, presence.from, occupant_id); |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
} |