aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/presence
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2018-01-12 21:03:09 +0100
committerfiaxh <git@mx.ax.lt>2018-01-28 00:38:47 +0100
commit782ae4c049e2b6fab13d7453cbb0e74610e7d200 (patch)
tree1b4cd0a1689cee0c2e2cac2ae9a5fb8ebbe63621 /xmpp-vala/src/module/presence
parentd46d071e57e599e8cfb1780597cbecb36881c4d8 (diff)
downloaddino-782ae4c049e2b6fab13d7453cbb0e74610e7d200.tar.gz
dino-782ae4c049e2b6fab13d7453cbb0e74610e7d200.zip
Move Jid class to xmpp-vala, partially refactor namespace
Diffstat (limited to 'xmpp-vala/src/module/presence')
-rw-r--r--xmpp-vala/src/module/presence/flag.vala48
-rw-r--r--xmpp-vala/src/module/presence/module.vala18
-rw-r--r--xmpp-vala/src/module/presence/stanza.vala6
3 files changed, 34 insertions, 38 deletions
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<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "presence");
- private HashMap<string, ConcurrentList<string>> resources = new HashMap<string, ConcurrentList<string>>();
- private HashMap<string, Presence.Stanza> presences = new HashMap<string, Presence.Stanza>();
+ private HashMap<Jid, Gee.List<Jid>> resources = new HashMap<Jid, Gee.List<Jid>>(Jid.hash_bare_func, Jid.equals_bare_func);
+ private HashMap<Jid, Presence.Stanza> presences = new HashMap<Jid, Presence.Stanza>(Jid.hash_func, Jid.equals_func);
- public Set<string> get_available_jids() {
+ public Set<Jid> get_available_jids() {
return resources.keys;
}
- public Gee.List<string>? get_resources(string bare_jid) {
- return resources[bare_jid];
+ public Gee.List<Jid>? 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<string>();
+ if (!resources.has_key(presence.from)) {
+ resources[presence.from] = new ArrayList<Jid>(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
+}