diff options
author | fiaxh <git@mx.ax.lt> | 2017-03-19 12:55:36 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-03-20 22:28:27 +0100 |
commit | db57a973534f099af2b150f1a1307d1948553d9f (patch) | |
tree | 238ae1d4e53412a33e3febd07318dfd38b0eb2f8 /xmpp-vala/src/module/roster | |
parent | 233f2b35d033cd20d1ac648bf2d723bcb7a918fc (diff) | |
download | dino-db57a973534f099af2b150f1a1307d1948553d9f.tar.gz dino-db57a973534f099af2b150f1a1307d1948553d9f.zip |
Add typed identity to manager modules and stream flags
Diffstat (limited to 'xmpp-vala/src/module/roster')
-rw-r--r-- | xmpp-vala/src/module/roster/flag.vala | 11 | ||||
-rw-r--r-- | xmpp-vala/src/module/roster/module.vala | 13 |
2 files changed, 10 insertions, 14 deletions
diff --git a/xmpp-vala/src/module/roster/flag.vala b/xmpp-vala/src/module/roster/flag.vala index c3e35158..43d185d9 100644 --- a/xmpp-vala/src/module/roster/flag.vala +++ b/xmpp-vala/src/module/roster/flag.vala @@ -6,9 +6,11 @@ namespace Xmpp.Roster { public class Flag : XmppStreamFlag { public const string ID = "roster"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, ID); + public HashMap<string, Item> roster_items = new HashMap<string, Item>(); - internal string? iq_id; + public string? iq_id; public Collection<Item> get_roster() { return roster_items.values; @@ -18,13 +20,8 @@ public class Flag : XmppStreamFlag { return roster_items[jid]; } - public static Flag? get_flag(XmppStream stream) { return (Flag?) stream.get_flag(NS_URI, ID); } - - public static bool has_flag(XmppStream stream) { return get_flag(stream) != null; } - public override string get_ns() { return NS_URI; } - - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } }
\ No newline at end of file diff --git a/xmpp-vala/src/module/roster/module.vala b/xmpp-vala/src/module/roster/module.vala index f29b73f7..1ebb7f22 100644 --- a/xmpp-vala/src/module/roster/module.vala +++ b/xmpp-vala/src/module/roster/module.vala @@ -6,8 +6,7 @@ namespace Xmpp.Roster { private const string NS_URI = "jabber:iq:roster"; public class Module : XmppStreamModule, Iq.Handler { - public const string ID = "roster_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "roster_module"); public signal void received_roster(XmppStream stream, Collection<Item> roster); public signal void item_removed(XmppStream stream, Item roster_item); @@ -56,7 +55,7 @@ namespace Xmpp.Roster { StanzaNode? query_node = iq.stanza.get_subnode("query", NS_URI); if (query_node == null) return; - Flag flag = Flag.get_flag(stream); + Flag flag = stream.get_flag(Flag.IDENTITY); Item item = new Item.from_stanza_node(query_node.get_subnode("item", NS_URI)); switch (item.subscription) { case Item.SUBSCRIPTION_REMOVE: @@ -89,17 +88,17 @@ namespace Xmpp.Roster { } internal override string get_ns() { return NS_URI; } - internal override string get_id() { return ID; } + internal override string get_id() { return IDENTITY.id; } private void roster_get(XmppStream stream) { - Flag.get_flag(stream).iq_id = random_uuid(); + stream.get_flag(Flag.IDENTITY).iq_id = random_uuid(); StanzaNode query_node = new StanzaNode.build("query", NS_URI).add_self_xmlns(); - Iq.Stanza iq = new Iq.Stanza.get(query_node, Flag.get_flag(stream).iq_id); + Iq.Stanza iq = new Iq.Stanza.get(query_node, stream.get_flag(Flag.IDENTITY).iq_id); stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_roster_get_received); } private static void on_roster_get_received(XmppStream stream, Iq.Stanza iq) { - Flag flag = Flag.get_flag(stream); + Flag flag = stream.get_flag(Flag.IDENTITY); if (iq.id == flag.iq_id) { StanzaNode? query_node = iq.stanza.get_subnode("query", NS_URI); foreach (StanzaNode item_node in query_node.sub_nodes) { |