aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/presence/flag.vala
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-10 17:01:45 +0100
committerfiaxh <git@mx.ax.lt>2017-03-10 17:11:25 +0100
commit2fe8489d368a371aefbfbe66e74621a8df14cdc2 (patch)
tree4dec90236b28101383753ffe4a1c7a34b09b0208 /xmpp-vala/src/module/presence/flag.vala
parent7a1aa8c806a63cfd031c082524501e26d4a181ee (diff)
downloaddino-2fe8489d368a371aefbfbe66e74621a8df14cdc2.tar.gz
dino-2fe8489d368a371aefbfbe66e74621a8df14cdc2.zip
Rename vala-xmpp library to xmpp-vala
Diffstat (limited to 'xmpp-vala/src/module/presence/flag.vala')
-rw-r--r--xmpp-vala/src/module/presence/flag.vala64
1 files changed, 64 insertions, 0 deletions
diff --git a/xmpp-vala/src/module/presence/flag.vala b/xmpp-vala/src/module/presence/flag.vala
new file mode 100644
index 00000000..a92c9405
--- /dev/null
+++ b/xmpp-vala/src/module/presence/flag.vala
@@ -0,0 +1,64 @@
+using Gee;
+
+using Xmpp.Core;
+
+namespace Xmpp.Presence {
+
+public class Flag : XmppStreamFlag {
+ public const string ID = "presence";
+
+ private HashMap<string, ConcurrentList<string>> resources = new HashMap<string, ConcurrentList<string>>();
+ private HashMap<string, Presence.Stanza> presences = new HashMap<string, Presence.Stanza>();
+
+ public Set<string> get_available_jids() {
+ return resources.keys;
+ }
+
+ public Gee.List<string>? get_resources(string bare_jid) {
+ return resources[bare_jid];
+ }
+
+ public Presence.Stanza? get_presence(string 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[bare_jid].contains(presence.from)) {
+ resources[bare_jid].remove(presence.from);
+ }
+ resources[bare_jid].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]) {
+ presences.unset(full_jid);
+ }
+ resources.unset(jid);
+ } else {
+ resources[bare_jid].remove(jid);
+ if (resources[bare_jid].size == 0) {
+ resources.unset(bare_jid);
+ }
+ presences.unset(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; }
+}
+
+} \ No newline at end of file