| 1 |
namespace Xmpp.Xep.DirectMucInvitations { |
| 2 |
|
| 3 |
private const string NS_URI = "jabber:x:conference"; |
| 4 |
|
| 5 |
public class Module : XmppStreamModule { |
| 6 |
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0249_direct_muc_invitations"); |
| 7 |
|
| 8 |
public signal void invite_received(XmppStream stream, Jid room_jid, Jid from_jid, string? password, string? reason); |
| 9 |
|
| 10 |
public void invite(XmppStream stream, Jid to_muc, Jid jid) { |
| 11 |
MessageStanza message = new MessageStanza() { to=jid }; |
| 12 |
StanzaNode invite_node = new StanzaNode.build("x", NS_URI).add_self_xmlns() |
| 13 |
.put_attribute("jid", to_muc.to_string()); |
| 14 |
message.stanza.put_node(invite_node); |
| 15 |
stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, message); |
| 16 |
} |
| 17 |
|
| 18 |
private void received_message(XmppStream stream, MessageStanza message) { |
| 19 |
StanzaNode? x_node = message.stanza.get_subnode("x", NS_URI); |
| 20 |
if (x_node == null) return; |
| 21 |
|
| 22 |
string? room_str = x_node.get_attribute("jid", NS_URI); |
| 23 |
if (room_str == null) return; |
| 24 |
Jid? room_jid = null; |
| 25 |
try { |
| 26 |
room_jid = new Jid(room_str); |
| 27 |
} catch (Error e) { |
| 28 |
return; |
| 29 |
} |
| 30 |
if (room_jid == null) return; |
| 31 |
|
| 32 |
string? password = x_node.get_attribute("password", NS_URI); |
| 33 |
string? reason = x_node.get_attribute("reason", NS_URI); |
| 34 |
|
| 35 |
invite_received(stream, room_jid, message.from, password, reason); |
| 36 |
} |
| 37 |
|
| 38 |
public override void attach(XmppStream stream) { |
| 39 |
stream.get_module(MessageModule.IDENTITY).received_message.connect(received_message); |
| 40 |
} |
| 41 |
|
| 42 |
public override void detach(XmppStream stream) { |
| 43 |
stream.get_module(MessageModule.IDENTITY).received_message.connect(received_message); |
| 44 |
} |
| 45 |
|
| 46 |
public override string get_ns() { |
| 47 |
return NS_URI; |
| 48 |
} |
| 49 |
|
| 50 |
public override string get_id() { |
| 51 |
return IDENTITY.id; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
} |