From 7c4260eed718961874fc0ea665263ea2ce59338b Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 21 Apr 2020 16:25:21 +0200 Subject: Remove features from service discovery module when detaching module from stream fixes #179 fixes #812 --- .../module/xep/0030_service_discovery/flag.vala | 36 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'xmpp-vala/src/module/xep/0030_service_discovery/flag.vala') diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala b/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala index 4661fede..d4874fca 100644 --- a/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala +++ b/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala @@ -6,11 +6,24 @@ public class Flag : XmppStreamFlag { public static FlagIdentity IDENTITY = new FlagIdentity(NS_URI, "service_discovery"); private HashMap?> entity_features = new HashMap?>(Jid.hash_func, Jid.equals_func); - private HashMap?> entity_identities = new HashMap?>(Jid.hash_func, Jid.equals_func); + private HashMap?> entity_identities = new HashMap?>(Jid.hash_func, Jid.equals_func); private HashMap?> entity_items = new HashMap?>(Jid.hash_func, Jid.equals_func); - public Gee.List features = new ArrayList(); - public Gee.List? get_entity_categories(Jid jid) { + private Gee.Set own_features_ = new HashSet(); + public Gee.List own_features { + owned get { + var ret = new ArrayList(); + foreach (var feature in own_features_) ret.add(feature); + return ret; + } + } + + private Gee.Set own_identities_ = new HashSet(Identity.hash_func, Identity.equals_func); + public Gee.Set own_identities { + owned get { return own_identities_.read_only_view; } + } + + public Gee.Set? get_entity_categories(Jid jid) { return entity_identities.has_key(jid) ? entity_identities[jid] : null; // TODO isn’t this default for hashmap } @@ -29,7 +42,7 @@ public class Flag : XmppStreamFlag { return entity_features[jid].contains(feature); } - public void set_entity_identities(Jid jid, Gee.List? identities) { + public void set_entity_identities(Jid jid, Gee.Set? identities) { entity_identities[jid] = identities; } @@ -41,7 +54,20 @@ public class Flag : XmppStreamFlag { entity_items[jid] = features; } - public void add_own_feature(string feature) { features.add(feature); } + public void add_own_feature(string feature) { + if (own_features_.contains(feature)) { + warning("Tried to add the feature %s a second time".printf(feature)); + return; + } + own_features_.add(feature); + } + + public void remove_own_feature(string feature) { + own_features_.remove(feature); + } + + public void add_own_identity(Identity identity) { own_identities_.add(identity); } + public void remove_own_identity(Identity identity) { own_identities_.remove(identity); } public override string get_ns() { return NS_URI; } -- cgit v1.2.3-54-g00ecf