From 782ae4c049e2b6fab13d7453cbb0e74610e7d200 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Fri, 12 Jan 2018 21:03:09 +0100 Subject: Move Jid class to xmpp-vala, partially refactor namespace --- xmpp-vala/src/module/presence/flag.vala | 48 +++++++++++++++---------------- xmpp-vala/src/module/presence/module.vala | 18 ++++++------ xmpp-vala/src/module/presence/stanza.vala | 6 ++-- 3 files changed, 34 insertions(+), 38 deletions(-) (limited to 'xmpp-vala/src/module/presence') diff --git a/xmpp-vala/src/module/presence/flag.vala b/xmpp-vala/src/module/presence/flag.vala index 8fb44e13..bb3562a4 100644 --- a/xmpp-vala/src/module/presence/flag.vala +++ b/xmpp-vala/src/module/presence/flag.vala @@ -1,60 +1,60 @@ using Gee; -using Xmpp.Core; - namespace Xmpp.Presence { public class Flag : XmppStreamFlag { public static FlagIdentity IDENTITY = new FlagIdentity(NS_URI, "presence"); - private HashMap> resources = new HashMap>(); - private HashMap presences = new HashMap(); + private HashMap> resources = new HashMap>(Jid.hash_bare_func, Jid.equals_bare_func); + private HashMap presences = new HashMap(Jid.hash_func, Jid.equals_func); - public Set get_available_jids() { + public Set get_available_jids() { return resources.keys; } - public Gee.List? get_resources(string bare_jid) { - return resources[bare_jid]; + public Gee.List? get_resources(Jid jid) { + return resources[jid]; } - public Presence.Stanza? get_presence(string full_jid) { + public Presence.Stanza? get_presence(Jid full_jid) { return presences[full_jid]; } public void add_presence(Presence.Stanza presence) { - string bare_jid = get_bare_jid(presence.from); - if (!resources.has_key(bare_jid)) { - resources[bare_jid] = new ConcurrentList(); + if (!resources.has_key(presence.from)) { + resources[presence.from] = new ArrayList(Jid.equals_func); } - if (resources[bare_jid].contains(presence.from)) { - resources[bare_jid].remove(presence.from); + if (resources[presence.from].contains(presence.from)) { + resources[presence.from].remove(presence.from); } - resources[bare_jid].add(presence.from); + resources[presence.from].add(presence.from); presences[presence.from] = presence; } - public void remove_presence(string jid) { - string bare_jid = get_bare_jid(jid); - if (resources.has_key(bare_jid)) { - if (is_bare_jid(jid)) { - foreach (string full_jid in resources[jid]) { + public void remove_presence(Jid jid) { + if (resources.has_key(jid)) { + if (jid.is_bare()) { + foreach (Jid full_jid in resources[jid]) { presences.unset(full_jid); } resources.unset(jid); } else { - resources[bare_jid].remove(jid); - if (resources[bare_jid].size == 0) { - resources.unset(bare_jid); + resources[jid].remove(jid); + if (resources[jid].size == 0) { + resources.unset(jid); } presences.unset(jid); } } } - public override string get_ns() { return NS_URI; } + public override string get_ns() { + return NS_URI; + } - public override string get_id() { return IDENTITY.id; } + public override string get_id() { + return IDENTITY.id; + } } } \ No newline at end of file diff --git a/xmpp-vala/src/module/presence/module.vala b/xmpp-vala/src/module/presence/module.vala index 3488f532..cbc7d365 100644 --- a/xmpp-vala/src/module/presence/module.vala +++ b/xmpp-vala/src/module/presence/module.vala @@ -1,5 +1,3 @@ -using Xmpp.Core; - namespace Xmpp.Presence { private const string NS_URI = "jabber:client"; @@ -10,39 +8,39 @@ namespace Xmpp.Presence { public signal void pre_send_presence_stanza(XmppStream stream, Presence.Stanza presence); public signal void initial_presence_sent(XmppStream stream, Presence.Stanza presence); public signal void received_available(XmppStream stream, Presence.Stanza presence); - public signal void received_available_show(XmppStream stream, string jid, string show); + public signal void received_available_show(XmppStream stream, Jid jid, string show); public signal void received_unavailable(XmppStream stream, Presence.Stanza presence); - public signal void received_subscription_request(XmppStream stream, string jid); - public signal void received_unsubscription(XmppStream stream, string jid); + public signal void received_subscription_request(XmppStream stream, Jid jid); + public signal void received_unsubscription(XmppStream stream, Jid jid); public bool available_resource = true; - public void request_subscription(XmppStream stream, string bare_jid) { + public void request_subscription(XmppStream stream, Jid bare_jid) { Presence.Stanza presence = new Presence.Stanza(); presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_SUBSCRIBE; send_presence(stream, presence); } - public void approve_subscription(XmppStream stream, string bare_jid) { + public void approve_subscription(XmppStream stream, Jid bare_jid) { Presence.Stanza presence = new Presence.Stanza(); presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_SUBSCRIBED; send_presence(stream, presence); } - public void deny_subscription(XmppStream stream, string bare_jid) { + public void deny_subscription(XmppStream stream, Jid bare_jid) { cancel_subscription(stream, bare_jid); } - public void cancel_subscription(XmppStream stream, string bare_jid) { + public void cancel_subscription(XmppStream stream, Jid bare_jid) { Presence.Stanza presence = new Presence.Stanza(); presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_UNSUBSCRIBED; send_presence(stream, presence); } - public void unsubscribe(XmppStream stream, string bare_jid) { + public void unsubscribe(XmppStream stream, Jid bare_jid) { Presence.Stanza presence = new Presence.Stanza(); presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_UNSUBSCRIBE; diff --git a/xmpp-vala/src/module/presence/stanza.vala b/xmpp-vala/src/module/presence/stanza.vala index 0926555e..a7bcbb56 100644 --- a/xmpp-vala/src/module/presence/stanza.vala +++ b/xmpp-vala/src/module/presence/stanza.vala @@ -1,5 +1,3 @@ -using Xmpp.Core; - namespace Xmpp.Presence { public class Stanza : Xmpp.Stanza { @@ -85,9 +83,9 @@ public class Stanza : Xmpp.Stanza { this.id = id ?? random_uuid(); } - public Stanza.from_stanza(StanzaNode stanza_node, string my_jid) { + public Stanza.from_stanza(StanzaNode stanza_node, Jid my_jid) { base.incoming(stanza_node, my_jid); } } -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2