aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0045_muc/flag.vala
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/xep/0045_muc/flag.vala
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/xep/0045_muc/flag.vala')
-rw-r--r--xmpp-vala/src/module/xep/0045_muc/flag.vala119
1 files changed, 57 insertions, 62 deletions
diff --git a/xmpp-vala/src/module/xep/0045_muc/flag.vala b/xmpp-vala/src/module/xep/0045_muc/flag.vala
index da469a41..87e0930f 100644
--- a/xmpp-vala/src/module/xep/0045_muc/flag.vala
+++ b/xmpp-vala/src/module/xep/0045_muc/flag.vala
@@ -1,128 +1,123 @@
using Gee;
-using Xmpp.Core;
-
namespace Xmpp.Xep.Muc {
public class Flag : XmppStreamFlag {
public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "muc");
- private HashMap<string, Gee.List<Feature>> room_features = new HashMap<string, Gee.List<Feature>>();
- private HashMap<string, string> room_names = new HashMap<string, string>();
+ private HashMap<Jid, Gee.List<Feature>> room_features = new HashMap<Jid, Gee.List<Feature>>(Jid.hash_bare_func, Jid.equals_bare_func);
+ private HashMap<Jid, string> room_names = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func);
- private HashMap<string, string> enter_ids = new HashMap<string, string>();
- private HashMap<string, string> own_nicks = new HashMap<string, string>();
- private HashMap<string, string> subjects = new HashMap<string, string>();
- private HashMap<string, string> subjects_by = new HashMap<string, string>();
+ private HashMap<Jid, string> enter_ids = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func);
+ private HashMap<Jid, string> own_nicks = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func);
+ private HashMap<Jid, string> subjects = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func);
+ private HashMap<Jid, Jid> subjects_by = new HashMap<Jid, Jid>(Jid.hash_bare_func, Jid.equals_bare_func);
- private HashMap<string, string> occupant_real_jids = new HashMap<string, string>();
- private HashMap<string, HashMap<string, Affiliation>> affiliations = new HashMap<string, HashMap<string, Affiliation>>();
- private HashMap<string, Role> occupant_role = new HashMap<string, Role>();
+ private HashMap<Jid, Jid> occupant_real_jids = new HashMap<Jid, Jid>(Jid.hash_func, Jid.equals_bare_func);
+ private HashMap<Jid, HashMap<Jid, Affiliation>> affiliations = new HashMap<Jid, HashMap<Jid, Affiliation>>(Jid.hash_bare_func, Jid.equals_bare_func);
+ private HashMap<Jid, Role> occupant_role = new HashMap<Jid, Role>(Jid.hash_func, Jid.equals_func);
- public string? get_room_name(string jid) { return room_names.has_key(jid) ? room_names[jid] : null; }
+ public string? get_room_name(Jid muc_jid) { return room_names.has_key(muc_jid.bare_jid) ? room_names[muc_jid.bare_jid] : null; }
- public bool has_room_feature(string jid, Feature feature) {
- return room_features.has_key(jid) && room_features[jid].contains(feature);
+ public bool has_room_feature(Jid muc_jid, Feature feature) {
+ return room_features.has_key(muc_jid.bare_jid) && room_features[muc_jid.bare_jid].contains(feature);
}
- public string? get_real_jid(string full_jid) { return occupant_real_jids[full_jid]; }
+ public Jid? get_real_jid(Jid full_jid) { return occupant_real_jids[full_jid]; }
- public Gee.List<string> get_offline_members(string muc_jid) {
- Gee.List<string> ret = new ArrayList<string>();
- HashMap<string, Affiliation>? muc_affiliations = affiliations[muc_jid];
+ public Gee.List<Jid> get_offline_members(Jid muc_jid) {
+ Gee.List<Jid> ret = new ArrayList<Jid>(Jid.equals_func);
+ HashMap<Jid, Affiliation>? muc_affiliations = affiliations[muc_jid.bare_jid];
if (muc_affiliations != null) {
- foreach (string jid in muc_affiliations.keys) {
- if (!jid.has_prefix(muc_jid)) ret.add(jid);
+ foreach (Jid jid in muc_affiliations.keys) {
+ if (!jid.equals_bare(muc_jid)) ret.add(jid);
}
}
return ret;
}
- public Affiliation get_affiliation(string muc_jid, string full_jid) {
- HashMap<string, Affiliation>? muc_affiliations = affiliations[muc_jid];
+ public Affiliation get_affiliation(Jid muc_jid, Jid full_jid) {
+ HashMap<Jid, Affiliation>? muc_affiliations = affiliations[muc_jid.bare_jid];
if (muc_affiliations != null) return muc_affiliations[full_jid];
return Affiliation.NONE;
}
- public Role? get_occupant_role(string full_jid) {
+ public Role? get_occupant_role(Jid full_jid) {
if (occupant_role.has_key(full_jid)) return occupant_role[full_jid];
return Role.NONE;
}
- public string? get_muc_nick(string bare_jid) { return own_nicks[bare_jid]; }
+ public string? get_muc_nick(Jid muc_jid) { return own_nicks[muc_jid.bare_jid]; }
- public string? get_enter_id(string bare_jid) { return enter_ids[bare_jid]; }
+ public string? get_enter_id(Jid muc_jid) { return enter_ids[muc_jid.bare_jid]; }
- public bool is_muc(string jid) { return own_nicks[jid] != null; }
+ public bool is_muc(Jid jid) { return own_nicks[jid] != null; }
- public bool is_occupant(string jid) {
- string bare_jid = get_bare_jid(jid);
- return own_nicks.has_key(bare_jid) || enter_ids.has_key(bare_jid);
+ public bool is_occupant(Jid jid) {
+ return own_nicks.has_key(jid.bare_jid) || enter_ids.has_key(jid.bare_jid);
}
public bool is_muc_enter_outstanding() { return enter_ids.size != 0; }
- public string? get_muc_subject(string bare_jid) { return subjects[bare_jid]; }
+ public string? get_muc_subject(Jid muc_jid) { return subjects[muc_jid.bare_jid]; }
- internal void set_room_name(string jid, string name) {
- room_names[jid] = name;
+ internal void set_room_name(Jid muc_jid, string name) {
+ room_names[muc_jid.bare_jid] = name;
}
- internal void set_room_features(string jid, Gee.List<Feature> features) {
- room_features[jid] = features;
+ internal void set_room_features(Jid muc_jid, Gee.List<Feature> features) {
+ room_features[muc_jid.bare_jid] = features;
}
- internal void set_real_jid(string full_jid, string real_jid) { occupant_real_jids[full_jid] = real_jid; }
+ internal void set_real_jid(Jid full_jid, Jid real_jid) { occupant_real_jids[full_jid] = real_jid; }
- internal void set_offline_member(string muc_jid, string real_jid, Affiliation affiliation) {
- set_affiliation(muc_jid, real_jid, affiliation);
+ internal void set_offline_member(Jid muc_jid, Jid real_jid, Affiliation affiliation) {
+ set_affiliation(muc_jid.bare_jid, real_jid, affiliation);
}
- internal void set_affiliation(string muc_jid, string full_jid, Affiliation affiliation) {
- if (!affiliations.has_key(muc_jid)) affiliations[muc_jid] = new HashMap<string, Affiliation>();
+ internal void set_affiliation(Jid muc_jid, Jid full_jid, Affiliation affiliation) {
+ if (!affiliations.has_key(muc_jid.bare_jid)) affiliations[muc_jid.bare_jid] = new HashMap<Jid, Affiliation>(Jid.hash_func, Jid.equals_func);
if (affiliation == Affiliation.NONE) {
- affiliations[muc_jid].unset(full_jid);
+ affiliations[muc_jid.bare_jid].unset(full_jid);
} else {
- affiliations[muc_jid][full_jid] = affiliation;
+ affiliations[muc_jid.bare_jid][full_jid] = affiliation;
}
}
- internal void set_occupant_role(string full_jid, Role role) {
+ internal void set_occupant_role(Jid full_jid, Role role) {
occupant_role[full_jid] = role;
}
- internal void set_muc_subject(string full_jid, string? subject) {
- string bare_jid = get_bare_jid(full_jid);
- subjects[bare_jid] = subject;
- subjects_by[bare_jid] = full_jid;
+ internal void set_muc_subject(Jid full_jid, string? subject) {
+ subjects[full_jid.bare_jid] = subject;
+ subjects_by[full_jid.bare_jid] = full_jid;
}
- internal void start_muc_enter(string bare_jid, string presence_id) {
- enter_ids[bare_jid] = presence_id;
+ internal void start_muc_enter(Jid jid, string presence_id) {
+ enter_ids[jid.bare_jid] = presence_id;
}
- internal void finish_muc_enter(string bare_jid, string? nick = null) {
- if (nick != null) own_nicks[bare_jid] = nick;
- enter_ids.unset(bare_jid);
+ internal void finish_muc_enter(Jid jid, string? nick = null) {
+ if (nick != null) own_nicks[jid.bare_jid] = nick;
+ enter_ids.unset(jid.bare_jid);
}
- internal void left_muc(XmppStream stream, string muc) {
- own_nicks.unset(muc);
- subjects.unset(muc);
- subjects_by.unset(muc);
- Gee.List<string>? occupants = stream.get_flag(Presence.Flag.IDENTITY).get_resources(muc);
+ internal void left_muc(XmppStream stream, Jid muc_jid) {
+ own_nicks.unset(muc_jid);
+ subjects.unset(muc_jid);
+ subjects_by.unset(muc_jid);
+ Gee.List<Jid>? occupants = stream.get_flag(Presence.Flag.IDENTITY).get_resources(muc_jid);
if (occupants != null) {
- foreach (string occupant in occupants) {
+ foreach (Jid occupant in occupants) {
remove_occupant_info(occupant);
}
}
}
- internal void remove_occupant_info(string full_jid) {
- occupant_real_jids.unset(full_jid);
- string bare_jid = get_bare_jid(full_jid);
- if (affiliations.has_key(full_jid)) affiliations[bare_jid].unset(full_jid);
- occupant_role.unset(full_jid);
+ internal void remove_occupant_info(Jid jid) {
+ occupant_real_jids.unset(jid);
+ if (affiliations.has_key(jid)) affiliations[jid].unset(jid);
+ occupant_role.unset(jid);
}
internal override string get_ns() { return NS_URI; }