From db57a973534f099af2b150f1a1307d1948553d9f Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 19 Mar 2017 12:55:36 +0100 Subject: Add typed identity to manager modules and stream flags --- xmpp-vala/src/module/roster/flag.vala | 11 ++++------- xmpp-vala/src/module/roster/module.vala | 13 ++++++------- 2 files changed, 10 insertions(+), 14 deletions(-) (limited to 'xmpp-vala/src/module/roster') 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 IDENTITY = new FlagIdentity(NS_URI, ID); + public HashMap roster_items = new HashMap(); - internal string? iq_id; + public string? iq_id; public Collection 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 IDENTITY = new ModuleIdentity(NS_URI, ID); + public static ModuleIdentity IDENTITY = new ModuleIdentity(NS_URI, "roster_module"); public signal void received_roster(XmppStream stream, Collection 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) { -- cgit v1.2.3-70-g09d2