2017-03-02 14:37:32 +00:00
|
|
|
using Gee;
|
|
|
|
|
|
|
|
using Xmpp.Core;
|
|
|
|
|
|
|
|
namespace Xmpp.Presence {
|
|
|
|
|
|
|
|
public class Flag : XmppStreamFlag {
|
2017-03-19 11:55:36 +00:00
|
|
|
public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "presence");
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-03 18:22:45 +00:00
|
|
|
private HashMap<string, ConcurrentList<string>> resources = new HashMap<string, ConcurrentList<string>>();
|
2017-03-02 14:37:32 +00:00
|
|
|
private HashMap<string, Presence.Stanza> presences = new HashMap<string, Presence.Stanza>();
|
|
|
|
|
|
|
|
public Set<string> get_available_jids() {
|
|
|
|
return resources.keys;
|
|
|
|
}
|
|
|
|
|
2017-03-03 18:22:45 +00:00
|
|
|
public Gee.List<string>? get_resources(string bare_jid) {
|
2017-03-02 14:37:32 +00:00
|
|
|
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)) {
|
2017-03-03 18:22:45 +00:00
|
|
|
resources[bare_jid] = new ConcurrentList<string>();
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
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 override string get_ns() { return NS_URI; }
|
|
|
|
|
2017-03-19 11:55:36 +00:00
|
|
|
public override string get_id() { return IDENTITY.id; }
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|