From 26973c89e391de673b6ac1db024a3098b1191393 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 16 Jun 2017 14:29:02 +0200 Subject: Set jid handle in ContactDetails, use LabelHybrids more, remove edit from StartConversation --- xmpp-vala/src/module/roster/module.vala | 10 +++---- xmpp-vala/src/module/util.vala | 42 +-------------------------- xmpp-vala/src/module/xep/0045_muc/flag.vala | 9 +++++- xmpp-vala/src/module/xep/0045_muc/module.vala | 14 +++++++-- 4 files changed, 24 insertions(+), 51 deletions(-) (limited to 'xmpp-vala/src/module') diff --git a/xmpp-vala/src/module/roster/module.vala b/xmpp-vala/src/module/roster/module.vala index e0d8aeb3..4c1028fb 100644 --- a/xmpp-vala/src/module/roster/module.vala +++ b/xmpp-vala/src/module/roster/module.vala @@ -38,13 +38,11 @@ public class Module : XmppStreamModule, Iq.Handler { * @param handle Handle to be set. If null, any handle will be removed. */ public void set_jid_handle(XmppStream stream, string jid, string? handle) { - Item roster_item = new Item(); - roster_item.jid = jid; - if (handle != null) { - roster_item.name = handle; - } + Flag flag = stream.get_flag(Flag.IDENTITY); + Item item = flag.get_item(jid) ?? new Item() { jid=jid }; + item.name = handle != null ? handle : ""; - roster_set(stream, roster_item); + roster_set(stream, item); } public void on_iq_set(XmppStream stream, Iq.Stanza iq) { diff --git a/xmpp-vala/src/module/util.vala b/xmpp-vala/src/module/util.vala index a0621225..365170b0 100644 --- a/xmpp-vala/src/module/util.vala +++ b/xmpp-vala/src/module/util.vala @@ -20,44 +20,4 @@ namespace Xmpp { uint32 b5_2 = Random.next_int(); return "%08x-%04x-%04x-%04x-%04x%08x".printf(b1, b2, b3, b4, b5_1, b5_2); } - - public class Tuple : Object { - public A a { get; private set; } - public B b { get; private set; } - - public Tuple(A a, B b) { - this.a = a; - this.b = b; - } - - public static Tuple create(A a, B b) { - return new Tuple(a,b); - } - } - - public class Triple : Tuple { - public C c { get; private set; } - - public Triple(A a, B b, C c) { - base(a, b); - this.c = c; - } - - public static new Triple create(A a, B b, C c) { - return new Triple(a, b, c); - } - } - - public class Quadruple : Triple { - public D d { get; private set; } - - public Quadruple(A a, B b, C c, D d) { - base (a, b, c); - this.d = d; - } - - public static new Quadruple create(A a, B b, C c, D d) { - return new Quadruple(a, b, c, d); - } - } -} \ No newline at end of file +} diff --git a/xmpp-vala/src/module/xep/0045_muc/flag.vala b/xmpp-vala/src/module/xep/0045_muc/flag.vala index cf729bf9..00383407 100644 --- a/xmpp-vala/src/module/xep/0045_muc/flag.vala +++ b/xmpp-vala/src/module/xep/0045_muc/flag.vala @@ -8,6 +8,7 @@ public class Flag : XmppStreamFlag { public static FlagIdentity IDENTITY = new FlagIdentity(NS_URI, "muc"); private HashMap> room_features = new HashMap>(); + private HashMap room_names = new HashMap(); private HashMap enter_ids = new HashMap(); private HashMap own_nicks = new HashMap(); @@ -18,6 +19,8 @@ public class Flag : XmppStreamFlag { private HashMap> affiliations = new HashMap>(); private HashMap occupant_role = new HashMap(); + public string? get_room_name(string jid) { return room_names.has_key(jid) ? room_names[jid] : null; } + public bool has_room_feature(string jid, Feature feature) { return room_features.has_key(jid) && room_features[jid].contains(feature); } @@ -59,6 +62,10 @@ public class Flag : XmppStreamFlag { public string? get_muc_subject(string bare_jid) { return subjects[bare_jid]; } + internal void set_room_name(string jid, string name) { + room_names[jid] = name; + } + internal void set_room_features(string jid, Gee.List features) { room_features[jid] = features; } @@ -121,4 +128,4 @@ public class Flag : XmppStreamFlag { internal override string get_id() { return IDENTITY.id; } } -} \ No newline at end of file +} diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala index 82a7d7a6..951ec7d1 100644 --- a/xmpp-vala/src/module/xep/0045_muc/module.vala +++ b/xmpp-vala/src/module/xep/0045_muc/module.vala @@ -10,6 +10,7 @@ private const string NS_URI_OWNER = NS_URI + "#owner"; private const string NS_URI_USER = NS_URI + "#user"; public enum MucEnterError { + NONE, PASSWORD_REQUIRED, BANNED, ROOM_DOESNT_EXIST, @@ -64,7 +65,7 @@ public class Module : XmppStreamModule { public signal void room_configuration_changed(XmppStream stream, string jid, StatusCode code); public signal void room_entered(XmppStream stream, string jid, string nick); - public signal void room_enter_error(XmppStream stream, string jid, MucEnterError error); + public signal void room_enter_error(XmppStream stream, string jid, MucEnterError? error); // TODO "?" shoudln't be necessary (vala bug), remove someday public signal void self_removed_from_room(XmppStream stream, string jid, StatusCode code); public signal void removed_from_room(XmppStream stream, string jid, StatusCode? code); @@ -213,7 +214,7 @@ public class Module : XmppStreamModule { string bare_jid = get_bare_jid(presence.from); ErrorStanza? error_stanza = presence.get_error(); if (flag.get_enter_id(bare_jid) == presence.id) { - MucEnterError? error = null; + MucEnterError error = MucEnterError.NONE; switch (error_stanza.condition) { case ErrorStanza.CONDITION_NOT_AUTHORIZED: if (ErrorStanza.TYPE_AUTH == error_stanza.type_) error = MucEnterError.PASSWORD_REQUIRED; @@ -240,7 +241,7 @@ public class Module : XmppStreamModule { if (ErrorStanza.TYPE_CANCEL == error_stanza.type_) error = MucEnterError.USE_RESERVED_ROOMNICK; break; } - if (error != null) room_enter_error(stream, bare_jid, error); + if (error != MucEnterError.NONE) room_enter_error(stream, bare_jid, error); flag.finish_muc_enter(bare_jid); } } @@ -312,6 +313,13 @@ public class Module : XmppStreamModule { Gee.List features = new ArrayList(); if (query_result != null) { + + foreach (ServiceDiscovery.Identity identity in query_result.identities) { + if (identity.category == "conference") { + stream.get_flag(Flag.IDENTITY).set_room_name(jid, identity.name); + } + } + foreach (string feature in query_result.features) { Feature? parsed = null; switch (feature) { -- cgit v1.2.3-70-g09d2