From 782ae4c049e2b6fab13d7453cbb0e74610e7d200 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Fri, 12 Jan 2018 21:03:09 +0100 Subject: Move Jid class to xmpp-vala, partially refactor namespace --- libdino/src/entity/account.vala | 1 + libdino/src/entity/conversation.vala | 14 +- libdino/src/entity/file_transfer.vala | 7 +- libdino/src/entity/jid.vala | 89 ------------- libdino/src/entity/message.vala | 21 +-- libdino/src/plugin/interfaces.vala | 1 + libdino/src/service/avatar_manager.vala | 68 ++++------ libdino/src/service/blocking_manager.vala | 8 +- libdino/src/service/chat_interaction.vala | 10 +- libdino/src/service/connection_manager.vala | 26 ++-- libdino/src/service/conversation_manager.vala | 14 +- .../service/counterpart_interaction_manager.vala | 6 +- libdino/src/service/database.vala | 16 +-- libdino/src/service/message_processor.vala | 49 ++++--- libdino/src/service/module_manager.vala | 18 +-- libdino/src/service/muc_manager.vala | 141 ++++++++++----------- libdino/src/service/presence_manager.vala | 41 +++--- libdino/src/service/roster_manager.vala | 26 ++-- libdino/src/service/stream_interactor.vala | 8 +- 19 files changed, 225 insertions(+), 339 deletions(-) delete mode 100644 libdino/src/entity/jid.vala (limited to 'libdino/src') diff --git a/libdino/src/entity/account.vala b/libdino/src/entity/account.vala index f0628ca4..111fbf08 100644 --- a/libdino/src/entity/account.vala +++ b/libdino/src/entity/account.vala @@ -1,4 +1,5 @@ using Gee; +using Xmpp; namespace Dino.Entities { diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala index 83c5ac22..fe9cf9ad 100644 --- a/libdino/src/entity/conversation.vala +++ b/libdino/src/entity/conversation.vala @@ -1,3 +1,5 @@ +using Xmpp; + namespace Dino.Entities { public class Conversation : Object { @@ -11,6 +13,7 @@ public class Conversation : Object { } public int id { get; set; } + public Type type_ { get; set; } public Account account { get; private set; } public Jid counterpart { get; private set; } public bool active { get; set; default = false; } @@ -25,7 +28,6 @@ public class Conversation : Object { } } public Encryption encryption { get; set; default = Encryption.NONE; } - public Type type_ { get; set; } public Message? read_up_to { get; set; } public enum NotifySetting { DEFAULT, ON, OFF, HIGHLIGHT } @@ -48,14 +50,14 @@ public class Conversation : Object { this.db = db; id = row[db.conversation.id]; + type_ = (Conversation.Type) row[db.conversation.type_]; account = db.get_account_by_id(row[db.conversation.account_id]); string? resource = row[db.conversation.resource]; - string jid = db.get_jid_by_id(row[db.conversation.jid_id]); - counterpart = resource != null ? new Jid.with_resource(jid, resource) : new Jid(jid); + counterpart = Jid.parse(db.get_jid_by_id(row[db.conversation.jid_id])); + if (type_ == Conversation.Type.GROUPCHAT_PM) counterpart = counterpart.with_resource(resource); active = row[db.conversation.active]; int64? last_active = row[db.conversation.last_active]; if (last_active != null) this.last_active = new DateTime.from_unix_utc(last_active); - type_ = (Conversation.Type) row[db.conversation.type_]; encryption = (Encryption) row[db.conversation.encryption]; int? read_up_to = row[db.conversation.read_up_to]; if (read_up_to != null) this.read_up_to = db.get_message_by_id(read_up_to); @@ -95,10 +97,10 @@ public class Conversation : Object { } public NotifySetting get_notification_default_setting(StreamInteractor stream_interactor) { - Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(account); + Xmpp.XmppStream? stream = stream_interactor.get_stream(account); if (!Application.get_default().settings.notifications) return NotifySetting.OFF; if (type_ == Type.GROUPCHAT) { - bool members_only = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY).has_room_feature(counterpart.bare_jid.to_string(), Xmpp.Xep.Muc.Feature.MEMBERS_ONLY); + bool members_only = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY).has_room_feature(counterpart.bare_jid, Xmpp.Xep.Muc.Feature.MEMBERS_ONLY); return members_only ? NotifySetting.ON : NotifySetting.HIGHLIGHT; } return NotifySetting.ON; diff --git a/libdino/src/entity/file_transfer.vala b/libdino/src/entity/file_transfer.vala index 120d3b38..22474396 100644 --- a/libdino/src/entity/file_transfer.vala +++ b/libdino/src/entity/file_transfer.vala @@ -1,3 +1,5 @@ +using Xmpp; + namespace Dino.Entities { public class FileTransfer : Object { @@ -48,11 +50,12 @@ public class FileTransfer : Object { string counterpart_jid = db.get_jid_by_id(row[db.file_transfer.counterpart_id]); string counterpart_resource = row[db.file_transfer.counterpart_resource]; - counterpart = counterpart_resource != null ? new Jid.with_resource(counterpart_jid, counterpart_resource) : new Jid(counterpart_jid); + counterpart = Jid.parse(counterpart_jid); + if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource); string our_resource = row[db.file_transfer.our_resource]; if (our_resource != null) { - ourpart = new Jid.with_resource(account.bare_jid.to_string(), our_resource); + ourpart = account.bare_jid.with_resource(our_resource); } else { ourpart = account.bare_jid; } diff --git a/libdino/src/entity/jid.vala b/libdino/src/entity/jid.vala deleted file mode 100644 index 42218fb2..00000000 --- a/libdino/src/entity/jid.vala +++ /dev/null @@ -1,89 +0,0 @@ -public class Dino.Entities.Jid : Object { - public string? localpart { get; set; } - public string domainpart { get; set; } - public string? resourcepart { get; set; } - - public Jid bare_jid { - owned get { return localpart != null ? new Jid(@"$localpart@$domainpart") : new Jid(domainpart); } - } - - private string jid { get; private set; } - - public Jid(string jid) { - Jid? parsed = Jid.parse(jid); - string? localpart = parsed != null ? parsed.localpart : null; - string domainpart = parsed != null ? parsed.domainpart : jid; - string? resourcepart = parsed != null ? parsed.resourcepart : null; - this.components(localpart, domainpart, resourcepart); - } - - public Jid.with_resource(string bare_jid, string resource) { - Jid? parsed = Jid.parse(bare_jid); - this.components(parsed.localpart, parsed.domainpart, resource); - } - - public Jid.components(string? localpart, string domainpart, string? resourcepart) { - string jid = domainpart; - if (localpart != null) { - jid = @"$localpart@$jid"; - } - if (resourcepart != null) { - jid = @"$jid/$resourcepart"; - } - this.jid = jid; - this.localpart = localpart; - this.domainpart = domainpart; - this.resourcepart = resourcepart; - } - - public static Jid? parse(string jid) { - int slash_index = jid.index_of("/"); - string resourcepart = slash_index == -1 ? null : jid.slice(slash_index + 1, jid.length); - string bare_jid = slash_index == -1 ? jid : jid.slice(0, slash_index); - int at_index = bare_jid.index_of("@"); - string localpart = at_index == -1 ? null : bare_jid.slice(0, at_index); - string domainpart = at_index == -1 ? bare_jid : bare_jid.slice(at_index + 1, bare_jid.length); - - if (domainpart == "") return null; - if (slash_index != -1 && resourcepart == "") return null; - if (at_index != -1 && localpart == "") return null; - - return new Jid.components(localpart, domainpart, resourcepart); - } - - public bool is_bare() { - return localpart != null && resourcepart == null; - } - - public bool is_full() { - return localpart != null && resourcepart != null; - } - - public string to_string() { - return jid; - } - - public bool equals_bare(Jid? jid) { - return jid != null && equals_bare_func(this, jid); - } - - public bool equals(Jid? jid) { - return jid != null && equals_func(this, jid); - } - - public static new bool equals_bare_func(Jid jid1, Jid jid2) { - return jid1.bare_jid.to_string() == jid2.bare_jid.to_string(); - } - - public static bool equals_func(Jid jid1, Jid jid2) { - return jid1.to_string() == jid2.to_string(); - } - - public static new uint hash_bare_func(Jid jid) { - return jid.bare_jid.to_string().hash(); - } - - public static new uint hash_func(Jid jid) { - return jid.to_string().hash(); - } -} diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala index 27bd08d8..6e34e458 100644 --- a/libdino/src/entity/message.vala +++ b/libdino/src/entity/message.vala @@ -1,4 +1,5 @@ using Gee; +using Xmpp; namespace Dino.Entities { @@ -51,7 +52,7 @@ public class Message : Object { marked_ = value; } } - public Xmpp.Message.Stanza stanza { get; set; } + public Xmpp.MessageStanza stanza { get; set; } private Database? db; @@ -67,15 +68,15 @@ public class Message : Object { stanza_id = row[db.message.stanza_id]; type_ = (Message.Type) row[db.message.type_]; - string counterpart_jid = db.get_jid_by_id(row[db.message.counterpart_id]); + counterpart = Jid.parse(db.get_jid_by_id(row[db.message.counterpart_id])); string counterpart_resource = row[db.message.counterpart_resource]; - counterpart = counterpart_resource != null ? new Jid.with_resource(counterpart_jid, counterpart_resource) : new Jid(counterpart_jid); + if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource); string our_resource = row[db.message.our_resource]; if (type_ == Type.GROUPCHAT && our_resource != null) { - ourpart = new Jid.with_resource(counterpart_jid, our_resource); + ourpart = counterpart.with_resource(our_resource); } else if (our_resource != null) { - ourpart = new Jid.with_resource(account.bare_jid.to_string(), our_resource); + ourpart = account.bare_jid.with_resource(our_resource); } else { ourpart = account.bare_jid; } @@ -121,9 +122,9 @@ public class Message : Object { public void set_type_string(string type) { switch (type) { - case Xmpp.Message.Stanza.TYPE_CHAT: + case Xmpp.MessageStanza.TYPE_CHAT: type_ = Type.CHAT; break; - case Xmpp.Message.Stanza.TYPE_GROUPCHAT: + case Xmpp.MessageStanza.TYPE_GROUPCHAT: type_ = Type.GROUPCHAT; break; } } @@ -131,11 +132,11 @@ public class Message : Object { public new string get_type_string() { switch (type_) { case Type.CHAT: - return Xmpp.Message.Stanza.TYPE_CHAT; + return Xmpp.MessageStanza.TYPE_CHAT; case Type.GROUPCHAT: - return Xmpp.Message.Stanza.TYPE_GROUPCHAT; + return Xmpp.MessageStanza.TYPE_GROUPCHAT; default: - return Xmpp.Message.Stanza.TYPE_NORMAL; + return Xmpp.MessageStanza.TYPE_NORMAL; } } diff --git a/libdino/src/plugin/interfaces.vala b/libdino/src/plugin/interfaces.vala index 07cc759c..62260076 100644 --- a/libdino/src/plugin/interfaces.vala +++ b/libdino/src/plugin/interfaces.vala @@ -1,4 +1,5 @@ using Dino.Entities; +using Xmpp; namespace Dino.Plugins { diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index 61e1faef..40115345 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -41,22 +41,18 @@ public class AvatarManager : StreamInteractionModule, Object { stream_interactor.module_manager.initialize_account_modules.connect(initialize_avatar_modules); } - private void initialize_avatar_modules(Account account, ArrayList modules) { + private void initialize_avatar_modules(Account account, ArrayList modules) { modules.add(new Xep.UserAvatars.Module(avatar_storage)); modules.add(new Xep.VCard.Module(avatar_storage)); } private Pixbuf? get_avatar_by_hash(string hash) { - lock (cached_pixbuf) { - if (cached_pixbuf.has_key(hash)) { - return cached_pixbuf[hash]; - } + if (cached_pixbuf.has_key(hash)) { + return cached_pixbuf[hash]; } Pixbuf? image = avatar_storage.get_image(hash); if (image != null) { - lock (cached_pixbuf) { - cached_pixbuf[hash] = image; - } + cached_pixbuf[hash] = image; } return image; } @@ -66,17 +62,13 @@ public class AvatarManager : StreamInteractionModule, Object { if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { jid_ = jid.bare_jid; } - lock(user_avatars) { - string? user_avatars_id = user_avatars[jid_]; - if (user_avatars_id != null) { - return get_avatar_by_hash(user_avatars_id); - } + string? user_avatars_id = user_avatars[jid_]; + if (user_avatars_id != null) { + return get_avatar_by_hash(user_avatars_id); } - lock(vcard_avatars) { - string? vcard_avatars_id = vcard_avatars[jid_]; - if (vcard_avatars_id != null) { - return get_avatar_by_hash(vcard_avatars_id); - } + string? vcard_avatars_id = vcard_avatars[jid_]; + if (vcard_avatars_id != null) { + return get_avatar_by_hash(vcard_avatars_id); } return null; } @@ -93,7 +85,7 @@ public class AvatarManager : StreamInteractionModule, Object { } uint8[] buffer; pixbuf.save_to_buffer(out buffer, "png"); - Core.XmppStream stream = stream_interactor.get_stream(account); + XmppStream stream = stream_interactor.get_stream(account); if (stream != null) { stream.get_module(Xep.UserAvatars.Module.IDENTITY).publish_png(stream, buffer, pixbuf.width, pixbuf.height); on_user_avatar_received(account, account.bare_jid, Base64.encode(buffer)); @@ -105,32 +97,26 @@ public class AvatarManager : StreamInteractionModule, Object { private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Xep.UserAvatars.Module.IDENTITY).received_avatar.connect((stream, jid, id) => - on_user_avatar_received(account, new Jid(jid), id) + on_user_avatar_received(account, jid, id) ); stream_interactor.module_manager.get_module(account, Xep.VCard.Module.IDENTITY).received_avatar.connect((stream, jid, id) => - on_vcard_avatar_received(account, new Jid(jid), id) + on_vcard_avatar_received(account, jid, id) ); - lock (user_avatars) { - user_avatars = db.get_avatar_hashes(Source.USER_AVATARS); - foreach (Jid jid in user_avatars.keys) { - on_user_avatar_received(account, jid, user_avatars[jid]); - } + user_avatars = db.get_avatar_hashes(Source.USER_AVATARS); + foreach (Jid jid in user_avatars.keys) { + on_user_avatar_received(account, jid, user_avatars[jid]); } - lock (vcard_avatars) { - vcard_avatars = db.get_avatar_hashes(Source.VCARD); - foreach (Jid jid in vcard_avatars.keys) { - on_vcard_avatar_received(account, jid, vcard_avatars[jid]); - } + vcard_avatars = db.get_avatar_hashes(Source.VCARD); + foreach (Jid jid in vcard_avatars.keys) { + on_vcard_avatar_received(account, jid, vcard_avatars[jid]); } } private void on_user_avatar_received(Account account, Jid jid, string id) { - lock (user_avatars) { - if (!user_avatars.has_key(jid) || user_avatars[jid] != id) { - user_avatars[jid] = id; - db.set_avatar_hash(jid, id, Source.USER_AVATARS); - } + if (!user_avatars.has_key(jid) || user_avatars[jid] != id) { + user_avatars[jid] = id; + db.set_avatar_hash(jid, id, Source.USER_AVATARS); } Pixbuf? avatar = avatar_storage.get_image(id); if (avatar != null) { @@ -139,12 +125,10 @@ public class AvatarManager : StreamInteractionModule, Object { } private void on_vcard_avatar_received(Account account, Jid jid, string id) { - lock (vcard_avatars) { - if (!vcard_avatars.has_key(jid) || vcard_avatars[jid] != id) { - vcard_avatars[jid] = id; - if (!jid.is_full()) { // don't save muc avatars - db.set_avatar_hash(jid, id, Source.VCARD); - } + if (!vcard_avatars.has_key(jid) || vcard_avatars[jid] != id) { + vcard_avatars[jid] = id; + if (!jid.is_full()) { // don't save muc avatars + db.set_avatar_hash(jid, id, Source.VCARD); } } Pixbuf? avatar = avatar_storage.get_image(id); diff --git a/libdino/src/service/blocking_manager.vala b/libdino/src/service/blocking_manager.vala index de79b4d4..183c8a9e 100644 --- a/libdino/src/service/blocking_manager.vala +++ b/libdino/src/service/blocking_manager.vala @@ -21,22 +21,22 @@ public class BlockingManager : StreamInteractionModule, Object { } public bool is_blocked(Account account, Jid jid) { - Core.XmppStream stream = stream_interactor.get_stream(account); + XmppStream stream = stream_interactor.get_stream(account); return stream != null && stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).is_blocked(stream, jid.to_string()); } public void block(Account account, Jid jid) { - Core.XmppStream stream = stream_interactor.get_stream(account); + XmppStream stream = stream_interactor.get_stream(account); stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).block(stream, new ArrayList.wrap(new string[] {jid.to_string()})); } public void unblock(Account account, Jid jid) { - Core.XmppStream stream = stream_interactor.get_stream(account); + XmppStream stream = stream_interactor.get_stream(account); stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).unblock(stream, new ArrayList.wrap(new string[] {jid.to_string()})); } public bool is_supported(Account account) { - Core.XmppStream stream = stream_interactor.get_stream(account); + XmppStream stream = stream_interactor.get_stream(account); return stream != null && stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).is_supported(stream); } } diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala index 036d9e59..fe008439 100644 --- a/libdino/src/service/chat_interaction.vala +++ b/libdino/src/service/chat_interaction.vala @@ -138,7 +138,7 @@ public class ChatInteraction : StreamInteractionModule, Object { } private void send_chat_marker(Conversation conversation, Entities.Message message, string marker) { - Core.XmppStream stream = stream_interactor.get_stream(conversation.account); + XmppStream stream = stream_interactor.get_stream(conversation.account); if (stream != null && (marker == Xep.ChatMarkers.MARKER_RECEIVED || conversation.get_send_marker_setting() == Conversation.Setting.ON) && Xep.ChatMarkers.Module.requests_marking(message.stanza)) { @@ -147,17 +147,17 @@ public class ChatInteraction : StreamInteractionModule, Object { } private void send_delivery_receipt(Conversation conversation, Entities.Message message) { - Core.XmppStream stream = stream_interactor.get_stream(conversation.account); + XmppStream stream = stream_interactor.get_stream(conversation.account); if (stream != null && Xep.MessageDeliveryReceipts.Module.requests_receipt(message.stanza)) { - stream.get_module(Xep.MessageDeliveryReceipts.Module.IDENTITY).send_received(stream, message.from.to_string(), message.stanza_id); + stream.get_module(Xep.MessageDeliveryReceipts.Module.IDENTITY).send_received(stream, message.from, message.stanza_id); } } private void send_chat_state_notification(Conversation conversation, string state) { - Core.XmppStream stream = stream_interactor.get_stream(conversation.account); + XmppStream stream = stream_interactor.get_stream(conversation.account); if (stream != null && conversation.get_send_typing_setting() == Conversation.Setting.ON && conversation.type_ != Conversation.Type.GROUPCHAT) { - stream.get_module(Xep.ChatStateNotifications.Module.IDENTITY).send_state(stream, conversation.counterpart.to_string(), state); + stream.get_module(Xep.ChatStateNotifications.Module.IDENTITY).send_state(stream, conversation.counterpart, state); } } } diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala index 70877233..943dcbad 100644 --- a/libdino/src/service/connection_manager.vala +++ b/libdino/src/service/connection_manager.vala @@ -7,7 +7,7 @@ namespace Dino { public class ConnectionManager { - public signal void stream_opened(Account account, Core.XmppStream stream); + public signal void stream_opened(Account account, XmppStream stream); public signal void connection_state_changed(Account account, ConnectionState state); public signal void connection_error(Account account, ConnectionError error); @@ -53,11 +53,11 @@ public class ConnectionManager { } private class Connection { - public Core.XmppStream stream { get; set; } + public XmppStream stream { get; set; } public ConnectionState connection_state { get; set; default = ConnectionState.DISCONNECTED; } public DateTime established { get; set; } public DateTime last_activity { get; set; } - public class Connection(Core.XmppStream stream, DateTime established) { + public class Connection(XmppStream stream, DateTime established) { this.stream = stream; this.established = established; } @@ -85,7 +85,7 @@ public class ConnectionManager { }); } - public Core.XmppStream? get_stream(Account account) { + public XmppStream? get_stream(Account account) { if (get_state(account) == ConnectionState.CONNECTED) { return connections[account].stream; } @@ -110,7 +110,7 @@ public class ConnectionManager { return connection_todo; } - public Core.XmppStream? connect(Account account) { + public XmppStream? connect(Account account) { if (!connection_todo.contains(account)) connection_todo.add(account); if (!connections.has_key(account)) { return connect_(account); @@ -144,16 +144,16 @@ public class ConnectionManager { } } - private Core.XmppStream? connect_(Account account, string? resource = null) { + private XmppStream? connect_(Account account, string? resource = null) { if (connections.has_key(account)) connections[account].stream.detach_modules(); connection_errors.unset(account); if (resource == null) resource = account.resourcepart; - Core.XmppStream stream = new Core.XmppStream(); - foreach (Core.XmppStreamModule module in module_manager.get_modules(account, resource)) { + XmppStream stream = new XmppStream(); + foreach (XmppStreamModule module in module_manager.get_modules(account, resource)) { stream.add_module(module); } - stream.log = new Core.XmppLog(account.bare_jid.to_string(), log_options); + stream.log = new XmppLog(account.bare_jid.to_string(), log_options); Connection connection = new Connection(stream, new DateTime.now_utc()); connections[account] = connection; @@ -174,7 +174,7 @@ public class ConnectionManager { return stream; } - private async void connect_async(Account account, Core.XmppStream stream) { + private async void connect_async(Account account, XmppStream stream) { try { yield stream.connect(account.domainpart); } catch (Error e) { @@ -184,7 +184,7 @@ public class ConnectionManager { connections.unset(account); return; } - if (e is Core.IOStreamError.TLS) { + if (e is IOStreamError.TLS) { set_connection_error(account, new ConnectionError(ConnectionError.Source.TLS, e.message) { reconnect_recomendation=ConnectionError.Reconnect.NEVER}); return; } @@ -236,8 +236,8 @@ public class ConnectionManager { private void check_reconnect(Account account) { bool acked = false; - Core.XmppStream stream = connections[account].stream; - stream.get_module(Xep.Ping.Module.IDENTITY).send_ping(stream, account.domainpart, (stream) => { + XmppStream stream = connections[account].stream; + stream.get_module(Xep.Ping.Module.IDENTITY).send_ping(stream, account.bare_jid.domain_jid, (stream) => { acked = true; change_connection_state(account, ConnectionState.CONNECTED); }); diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index 986cb0f1..e66ecca0 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -33,9 +33,10 @@ public class ConversationManager : StreamInteractionModule, Object { public Conversation create_conversation(Jid jid, Account account, Conversation.Type? type = null) { assert(conversations.has_key(account)); - if (conversations[account].has_key(jid)) { - conversations[account][jid].type_ = type; - return conversations[account][jid]; + Jid store_jid = type == Conversation.Type.GROUPCHAT ? jid.bare_jid : jid; + if (conversations[account].has_key(store_jid)) { + conversations[account][store_jid].type_ = type; + return conversations[account][store_jid]; } else { Conversation conversation = new Conversation(jid, account, type); add_conversation(conversation); @@ -84,10 +85,11 @@ public class ConversationManager : StreamInteractionModule, Object { return null; } - public Gee.List get_active_conversations() { + public Gee.List get_active_conversations(Account? account = null) { Gee.List ret = new ArrayList(Conversation.equals_func); - foreach (Account account in conversations.keys) { - foreach (Conversation conversation in conversations[account].values) { + foreach (Account account_ in conversations.keys) { + if (account != null && !account_.equals(account)) continue; + foreach (Conversation conversation in conversations[account_].values) { if(conversation.active) ret.add(conversation); } } diff --git a/libdino/src/service/counterpart_interaction_manager.vala b/libdino/src/service/counterpart_interaction_manager.vala index e4207a1c..eeb7f773 100644 --- a/libdino/src/service/counterpart_interaction_manager.vala +++ b/libdino/src/service/counterpart_interaction_manager.vala @@ -37,13 +37,13 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Xep.ChatMarkers.Module.IDENTITY).marker_received.connect( (stream, jid, marker, id) => { - on_chat_marker_received(account, new Jid(jid), marker, id); + on_chat_marker_received(account, jid, marker, id); }); stream_interactor.module_manager.get_module(account, Xep.MessageDeliveryReceipts.Module.IDENTITY).receipt_received.connect((stream, jid, id) => { - on_receipt_received(account, new Jid(jid), id); + on_receipt_received(account, jid, id); }); stream_interactor.module_manager.get_module(account, Xep.ChatStateNotifications.Module.IDENTITY).chat_state_received.connect((stream, jid, state) => { - on_chat_state_received(account, new Jid(jid), state); + on_chat_state_received(account, jid, state); }); } diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 6b75b800..c668ce17 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -232,7 +232,7 @@ public class Database : Qlite.Database { } } - public Gee.List get_messages(Jid jid, Account account, Message.Type? type, int count, DateTime? before) { + public Gee.List get_messages(Xmpp.Jid jid, Account account, Message.Type? type, int count, DateTime? before) { QueryBuilder select = message.select() .with(message.counterpart_id, "=", get_jid_id(jid)) .with(message.account_id, "=", account.id) @@ -255,7 +255,7 @@ public class Database : Qlite.Database { return ret; } - public Gee.List get_unsend_messages(Account account, Jid? jid = null) { + public Gee.List get_unsend_messages(Account account, Xmpp.Jid? jid = null) { Gee.List ret = new ArrayList(); var select = message.select() .with(message.account_id, "=", account.id) @@ -308,7 +308,7 @@ public class Database : Qlite.Database { return ret; } - public void set_avatar_hash(Jid jid, string hash, int type) { + public void set_avatar_hash(Xmpp.Jid jid, string hash, int type) { avatar.insert().or("REPLACE") .value(avatar.jid, jid.to_string()) .value(avatar.hash, hash) @@ -316,10 +316,10 @@ public class Database : Qlite.Database { .perform(); } - public HashMap get_avatar_hashes(int type) { - HashMap ret = new HashMap(Jid.hash_func, Jid.equals_func); + public HashMap get_avatar_hashes(int type) { + HashMap ret = new HashMap(Xmpp.Jid.hash_func, Xmpp.Jid.equals_func); foreach (Row row in avatar.select({avatar.jid, avatar.hash}).with(avatar.type_, "=", type)) { - ret[new Jid(row[avatar.jid])] = row[avatar.hash]; + ret[Xmpp.Jid.parse(row[avatar.jid])] = row[avatar.hash]; } return ret; } @@ -342,7 +342,7 @@ public class Database : Qlite.Database { } - public int get_jid_id(Jid jid_obj) { + public int get_jid_id(Xmpp.Jid jid_obj) { string bare_jid = jid_obj.bare_jid.to_string(); if (jid_table_reverse.has_key(bare_jid)) { return jid_table_reverse[bare_jid]; @@ -372,7 +372,7 @@ public class Database : Qlite.Database { } } - private int add_jid(Jid jid_obj) { + private int add_jid(Xmpp.Jid jid_obj) { string bare_jid = jid_obj.bare_jid.to_string(); int id = (int) jid.insert().value(jid.bare_jid, bare_jid).perform(); jid_table_cache[id] = bare_jid; diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index 1a9b1872..ec6316a0 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -9,10 +9,10 @@ public class MessageProcessor : StreamInteractionModule, Object { public static ModuleIdentity IDENTITY = new ModuleIdentity("message_processor"); public string id { get { return IDENTITY.id; } } - public signal void pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation); + public signal void pre_message_received(Entities.Message message, Xmpp.MessageStanza message_stanza, Conversation conversation); public signal void message_received(Entities.Message message, Conversation conversation); - public signal void build_message_stanza(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation); - public signal void pre_message_send(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation); + public signal void build_message_stanza(Entities.Message message, Xmpp.MessageStanza message_stanza, Conversation conversation); + public signal void pre_message_send(Entities.Message message, Xmpp.MessageStanza message_stanza, Conversation conversation); public signal void message_sent(Entities.Message message, Conversation conversation); private StreamInteractor stream_interactor; @@ -51,7 +51,7 @@ public class MessageProcessor : StreamInteractionModule, Object { } private void on_account_added(Account account) { - stream_interactor.module_manager.get_module(account, Xmpp.Message.Module.IDENTITY).received_message.connect( (stream, message) => { + stream_interactor.module_manager.get_module(account, Xmpp.MessageModule.IDENTITY).received_message.connect( (stream, message) => { on_message_received(account, message); }); stream_interactor.module_manager.get_module(account, Xmpp.Xep.MessageArchiveManagement.Module.IDENTITY).feature_available.connect( (stream) => { @@ -60,7 +60,7 @@ public class MessageProcessor : StreamInteractionModule, Object { }); } - private void on_message_received(Account account, Xmpp.Message.Stanza message) { + private void on_message_received(Account account, Xmpp.MessageStanza message) { if (message.body == null) return; Entities.Message new_message = create_in_message(account, message); @@ -68,19 +68,18 @@ public class MessageProcessor : StreamInteractionModule, Object { determine_message_type(account, message, new_message); } - private Entities.Message create_in_message(Account account, Xmpp.Message.Stanza message) { + private Entities.Message? create_in_message(Account account, Xmpp.MessageStanza message) { Entities.Message new_message = new Entities.Message(message.body); new_message.account = account; new_message.stanza_id = message.id; - Jid from_jid = new Jid(message.from); - if (!account.bare_jid.equals_bare(from_jid) || - from_jid.equals(stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(from_jid.bare_jid, account))) { + if (!account.bare_jid.equals_bare(message.from) || + message.from.equals(stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(message.from.bare_jid, account))) { new_message.direction = Entities.Message.DIRECTION_RECEIVED; } else { new_message.direction = Entities.Message.DIRECTION_SENT; } - new_message.counterpart = new_message.direction == Entities.Message.DIRECTION_SENT ? new Jid(message.to) : new Jid(message.from); - new_message.ourpart = new_message.direction == Entities.Message.DIRECTION_SENT ? new Jid(message.from) : new Jid(message.to); + new_message.counterpart = new_message.direction == Entities.Message.DIRECTION_SENT ? message.to : message.from; + new_message.ourpart = new_message.direction == Entities.Message.DIRECTION_SENT ? message.from : message.to; new_message.stanza = message; Xep.MessageArchiveManagement.MessageFlag? mam_message_flag = Xep.MessageArchiveManagement.MessageFlag.get_flag(message); @@ -94,7 +93,7 @@ public class MessageProcessor : StreamInteractionModule, Object { return new_message; } - private void process_message(Entities.Message new_message, Xmpp.Message.Stanza stanza) { + private void process_message(Entities.Message new_message, Xmpp.MessageStanza stanza) { Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_for_message(new_message); if (conversation != null) { pre_message_received(new_message, stanza, conversation); @@ -111,7 +110,7 @@ public class MessageProcessor : StreamInteractionModule, Object { } bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null; - Core.XmppStream? stream = stream_interactor.get_stream(conversation.account); + XmppStream? stream = stream_interactor.get_stream(conversation.account); Xep.MessageArchiveManagement.Flag? mam_flag = stream != null ? stream.get_flag(Xep.MessageArchiveManagement.Flag.IDENTITY) : null; if (is_mam_message || (mam_flag != null && mam_flag.cought_up == true)) { conversation.account.mam_earliest_synced = new_message.local_time; @@ -120,11 +119,11 @@ public class MessageProcessor : StreamInteractionModule, Object { } } - private void determine_message_type(Account account, Xmpp.Message.Stanza message_stanza, Entities.Message message) { - if (message_stanza.type_ == Xmpp.Message.Stanza.TYPE_GROUPCHAT) { + private void determine_message_type(Account account, Xmpp.MessageStanza message_stanza, Entities.Message message) { + if (message_stanza.type_ == Xmpp.MessageStanza.TYPE_GROUPCHAT) { message.type_ = Entities.Message.Type.GROUPCHAT; process_message(message, message_stanza); - } else if (message_stanza.type_ == Xmpp.Message.Stanza.TYPE_CHAT) { + } else if (message_stanza.type_ == Xmpp.MessageStanza.TYPE_CHAT) { Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(message.counterpart.bare_jid, account); if (conversation != null) { if (conversation.type_ == Conversation.Type.CHAT) { @@ -134,8 +133,8 @@ public class MessageProcessor : StreamInteractionModule, Object { } process_message(message, message_stanza); } else { - Core.XmppStream stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xep.ServiceDiscovery.Module.IDENTITY).get_entity_categories(stream, message.counterpart.bare_jid.to_string(), (stream, identities) => { + XmppStream stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xep.ServiceDiscovery.Module.IDENTITY).get_entity_categories(stream, message.counterpart.bare_jid, (stream, identities) => { if (identities == null) { message.type_ = Entities.Message.Type.CHAT; process_message(message, message_stanza); @@ -168,7 +167,7 @@ public class MessageProcessor : StreamInteractionModule, Object { message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid; message.real_jid = conversation.account.bare_jid; } else { - message.ourpart = new Jid.with_resource(conversation.account.bare_jid.to_string(), conversation.account.resourcepart); + message.ourpart = conversation.account.bare_jid.with_resource(conversation.account.resourcepart); } message.marked = Entities.Message.Marked.UNSENT; message.encryption = conversation.encryption; @@ -177,16 +176,16 @@ public class MessageProcessor : StreamInteractionModule, Object { public void send_xmpp_message(Entities.Message message, Conversation conversation, bool delayed = false) { lock (lock_send_unsent) { - Core.XmppStream stream = stream_interactor.get_stream(conversation.account); + XmppStream stream = stream_interactor.get_stream(conversation.account); message.marked = Entities.Message.Marked.NONE; if (stream != null) { - Xmpp.Message.Stanza new_message = new Xmpp.Message.Stanza(message.stanza_id); - new_message.to = message.counterpart.to_string(); + Xmpp.MessageStanza new_message = new Xmpp.MessageStanza(message.stanza_id); + new_message.to = message.counterpart; new_message.body = message.body; if (conversation.type_ == Conversation.Type.GROUPCHAT) { - new_message.type_ = Xmpp.Message.Stanza.TYPE_GROUPCHAT; + new_message.type_ = Xmpp.MessageStanza.TYPE_GROUPCHAT; } else { - new_message.type_ = Xmpp.Message.Stanza.TYPE_CHAT; + new_message.type_ = Xmpp.MessageStanza.TYPE_CHAT; } build_message_stanza(message, new_message, conversation); pre_message_send(message, new_message, conversation); @@ -194,7 +193,7 @@ public class MessageProcessor : StreamInteractionModule, Object { if (delayed) { Xmpp.Xep.DelayedDelivery.Module.set_message_delay(new_message, message.time); } - stream.get_module(Xmpp.Message.Module.IDENTITY).send_message(stream, new_message); + stream.get_module(Xmpp.MessageModule.IDENTITY).send_message(stream, new_message); message.stanza_id = new_message.id; message.stanza = new_message; } else { diff --git a/libdino/src/service/module_manager.vala b/libdino/src/service/module_manager.vala index 0f89f532..f5f3b63e 100644 --- a/libdino/src/service/module_manager.vala +++ b/libdino/src/service/module_manager.vala @@ -6,17 +6,17 @@ using Xmpp; namespace Dino { public class ModuleManager { - private HashMap> module_map = new HashMap>(); + private HashMap> module_map = new HashMap>(); private EntityCapabilitiesStorage entity_capabilities_storage; - public signal void initialize_account_modules(Account account, ArrayList modules); + public signal void initialize_account_modules(Account account, ArrayList modules); public ModuleManager(Database db) { entity_capabilities_storage = new EntityCapabilitiesStorage(db); } - public T? get_module(Account account, Core.ModuleIdentity identity) { + public T? get_module(Account account, Xmpp.ModuleIdentity identity) { if (identity == null) return null; lock (module_map) { if (!module_map.has_key(account)) { @@ -30,15 +30,15 @@ public class ModuleManager { return null; } - public ArrayList get_modules(Account account, string? resource = null) { - ArrayList modules = new ArrayList(); + public ArrayList get_modules(Account account, string? resource = null) { + ArrayList modules = new ArrayList(); lock (module_map) { if (!module_map.has_key(account)) initialize(account); - foreach (Core.XmppStreamModule module in module_map[account]) modules.add(module); + foreach (XmppStreamModule module in module_map[account]) modules.add(module); } - foreach (Core.XmppStreamModule module in module_map[account]) { + foreach (XmppStreamModule module in module_map[account]) { if (module.get_id() == Bind.Module.IDENTITY.id) { (module as Bind.Module).requested_resource == null ? account.resourcepart : resource; } else if (module.get_id() == PlainSasl.Module.IDENTITY.id) { @@ -50,7 +50,7 @@ public class ModuleManager { public void initialize(Account account) { lock(module_map) { - module_map[account] = new ArrayList(); + module_map[account] = new ArrayList(); module_map[account].add(new Iq.Module()); module_map[account].add(new Tls.Module()); module_map[account].add(new Xep.SrvRecordsTls.Module()); @@ -63,7 +63,7 @@ public class ModuleManager { module_map[account].add(new Xep.PrivateXmlStorage.Module()); module_map[account].add(new Xep.Bookmarks.Module()); module_map[account].add(new Presence.Module()); - module_map[account].add(new Xmpp.Message.Module()); + module_map[account].add(new Xmpp.MessageModule()); module_map[account].add(new Xep.MessageArchiveManagement.Module()); module_map[account].add(new Xep.MessageCarbons.Module()); module_map[account].add(new Xep.Muc.Module()); diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index 331065f1..4689bdcf 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -30,7 +30,7 @@ public class MucManager : StreamInteractionModule, Object { } public void join(Account account, Jid jid, string? nick, string? password) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream == null) return; string nick_ = nick ?? account.bare_jid.localpart ?? account.bare_jid.domainpart; @@ -41,14 +41,14 @@ public class MucManager : StreamInteractionModule, Object { if (last_message != null) history_since = last_message.time; } - stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid.to_string(), nick_, password, history_since); + stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid, nick_, password, history_since); } public void part(Account account, Jid jid) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream == null) return; unset_autojoin(stream, jid); - stream.get_module(Xep.Muc.Module.IDENTITY).exit(stream, jid.bare_jid.to_string()); + stream.get_module(Xep.Muc.Module.IDENTITY).exit(stream, jid.bare_jid); Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account); if (conversation != null) stream_interactor.get_module(ConversationManager.IDENTITY).close_conversation(conversation); @@ -56,53 +56,53 @@ public class MucManager : StreamInteractionModule, Object { public delegate void OnResult(Jid jid, Xep.DataForms.DataForm data_form); public void get_config_form(Account account, Jid jid, owned OnResult listener) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream == null) return; - stream.get_module(Xep.Muc.Module.IDENTITY).get_config_form(stream, jid.to_string(), (stream, jid, data_form) => { - listener(new Jid(jid), data_form); + stream.get_module(Xep.Muc.Module.IDENTITY).get_config_form(stream, jid, (stream, jid, data_form) => { + listener(jid, data_form); }); } public void change_subject(Account account, Jid jid, string subject) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).change_subject(stream, jid.bare_jid.to_string(), subject); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).change_subject(stream, jid.bare_jid, subject); } public void change_nick(Account account, Jid jid, string new_nick) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).change_nick(stream, jid.bare_jid.to_string(), new_nick); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).change_nick(stream, jid.bare_jid, new_nick); } public void invite(Account account, Jid muc, Jid invitee) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).invite(stream, muc.bare_jid.to_string(), invitee.bare_jid.to_string()); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).invite(stream, muc.bare_jid, invitee.bare_jid); } public void kick(Account account, Jid jid, string nick) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).kick(stream, jid.bare_jid.to_string(), nick); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).kick(stream, jid.bare_jid, nick); } public void change_affiliation(Account account, Jid jid, string nick, string role) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).change_affiliation(stream, jid.bare_jid.to_string(), nick, role); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).change_affiliation(stream, jid.bare_jid, nick, role); } public bool kick_possible(Account account, Jid occupant) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) return stream.get_module(Xep.Muc.Module.IDENTITY).kick_possible(stream, occupant.to_string()); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) return stream.get_module(Xep.Muc.Module.IDENTITY).kick_possible(stream, occupant); return false; } - public ArrayList? get_occupants(Jid jid, Account account) { + public Gee.List? get_occupants(Jid jid, Account account) { if (is_groupchat(jid, account)) { return stream_interactor.get_module(PresenceManager.IDENTITY).get_full_jids(jid, account); } return null; } - public ArrayList? get_other_occupants(Jid jid, Account account) { - ArrayList? occupants = get_occupants(jid, account); + public Gee.List? get_other_occupants(Jid jid, Account account) { + Gee.List? occupants = get_occupants(jid, account); Jid? own_jid = get_own_jid(jid, account); if (occupants != null && own_jid != null) { occupants.remove(own_jid); @@ -120,87 +120,79 @@ public class MucManager : StreamInteractionModule, Object { } public void get_bookmarks(Account account, owned Xep.Bookmarks.Module.OnResult listener) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (owned)listener); } public void add_bookmark(Account account, Xep.Bookmarks.Conference conference) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { stream.get_module(Xep.Bookmarks.Module.IDENTITY).add_conference(stream, conference); } } public void replace_bookmark(Account account, Xep.Bookmarks.Conference was, Xep.Bookmarks.Conference replace) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { stream.get_module(Xep.Bookmarks.Module.IDENTITY).replace_conference(stream, was, replace); } } public void remove_bookmark(Account account, Xep.Bookmarks.Conference conference) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { stream.get_module(Xep.Bookmarks.Module.IDENTITY).remove_conference(stream, conference); } } public string? get_room_name(Account account, Jid jid) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - return stream != null ? stream.get_flag(Xep.Muc.Flag.IDENTITY).get_room_name(jid.to_string()) : null; + XmppStream? stream = stream_interactor.get_stream(account); + return stream != null ? stream.get_flag(Xep.Muc.Flag.IDENTITY).get_room_name(jid) : null; } public string? get_groupchat_subject(Jid jid, Account account) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_subject(jid.bare_jid.to_string()); + return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_subject(jid.bare_jid); } return null; } public Jid? get_real_jid(Jid jid, Account account) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - string? real_jid = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(jid.to_string()); - if (real_jid != null) { - return new Jid(real_jid); - } + return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(jid); } return null; } public Xep.Muc.Role? get_role(Jid jid, Account account) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_occupant_role(jid.to_string()); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_occupant_role(jid); return null; } public Xep.Muc.Affiliation? get_affiliation(Jid muc_jid, Jid jid, Account account) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_affiliation(muc_jid.to_string(), jid.to_string()); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_affiliation(muc_jid, jid); return null; } public Gee.List? get_offline_members(Jid jid, Account account) { - Gee.List ret = new ArrayList(Jid.equals_func); - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - Gee.List? members = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_offline_members(jid.to_string()); - if (members == null) return null; - foreach (string member in members) { - ret.add(new Jid(member)); - } + return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_offline_members(jid); } - return ret; + return null; } public Jid? get_own_jid(Jid muc_jid, Account account) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { Xep.Muc.Flag? flag = stream.get_flag(Xep.Muc.Flag.IDENTITY); if (flag == null) return null; - string? nick = flag.get_muc_nick(muc_jid.bare_jid.to_string()); - if (nick != null) return new Jid.with_resource(muc_jid.bare_jid.to_string(), nick); + string? nick = flag.get_muc_nick(muc_jid); + if (nick != null) return muc_jid.with_resource(nick); } return null; } @@ -210,23 +202,21 @@ public class MucManager : StreamInteractionModule, Object { } private void on_account_added(Account account) { - stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_entered.connect( (stream, jid_string, nick) => { - Jid jid = new Jid(jid_string); + stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_entered.connect( (stream, jid, nick) => { enter_errors.unset(jid); set_autojoin(stream, jid, nick, null); // TODO password joined(account, jid, nick); stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_messages(account, jid); }); - stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_enter_error.connect( (stream, jid_str, error) => { - Jid jid = new Jid(jid_str); + stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_enter_error.connect( (stream, jid, error) => { enter_errors[jid] = error; enter_error(account, jid, error); }); stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).self_removed_from_room.connect( (stream, jid, code) => { - left(account, new Jid(jid)); + left(account, jid); }); stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).subject_set.connect( (stream, subject, jid) => { - subject_set(account, new Jid(jid), subject); + subject_set(account, jid, subject); }); stream_interactor.module_manager.get_module(account, Xep.Bookmarks.Module.IDENTITY).received_conferences.connect( (stream, conferences) => { sync_autojoin_active(account, conferences); @@ -234,29 +224,28 @@ public class MucManager : StreamInteractionModule, Object { }); } - private void on_stream_negotiated(Account account, Core.XmppStream stream) { + private void on_stream_negotiated(Account account, XmppStream stream) { stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences) => { foreach (Xep.Bookmarks.Conference bookmark in conferences) { - Jid jid = new Jid(bookmark.jid); if (bookmark.autojoin) { - join(account, jid, bookmark.nick, bookmark.password); + join(account, bookmark.jid, bookmark.nick, bookmark.password); } } }); } - private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { + private void on_pre_message_received(Entities.Message message, Xmpp.MessageStanza message_stanza, Conversation conversation) { if (conversation.type_ != Conversation.Type.GROUPCHAT) return; - Core.XmppStream stream = stream_interactor.get_stream(conversation.account); + XmppStream stream = stream_interactor.get_stream(conversation.account); if (stream == null) return; if (Xep.DelayedDelivery.MessageFlag.get_flag(message.stanza) == null) { - string? real_jid = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(message.counterpart.to_string()); - if (real_jid != null && real_jid != message.counterpart.to_string()) { - message.real_jid = new Jid(real_jid).bare_jid; + Jid? real_jid = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(message.counterpart); + if (real_jid != null && !real_jid.equals(message.counterpart)) { + message.real_jid = real_jid.bare_jid; } } - string? muc_nick = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_nick(conversation.counterpart.bare_jid.to_string()); - if (muc_nick != null && message.from.equals(new Jid(@"$(message.from.bare_jid)/$muc_nick"))) { // TODO better from own + string? muc_nick = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_nick(conversation.counterpart.bare_jid); + if (muc_nick != null && message.from.equals(message.from.with_resource(muc_nick))) { // TODO better from own Gee.List messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages(conversation); foreach (Entities.Message m in messages) { // TODO not here if (m.equals(message)) { @@ -267,7 +256,7 @@ public class MucManager : StreamInteractionModule, Object { } private void sync_autojoin_active(Account account, Gee.List conferences) { - Gee.List conversations = stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations(); + Gee.List conversations = stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations(account); leave_non_autojoin(account, conferences, conversations); join_autojoin(account, conferences, conversations); } @@ -277,7 +266,7 @@ public class MucManager : StreamInteractionModule, Object { if (conversation.type_ != Conversation.Type.GROUPCHAT || !conversation.account.equals(account)) continue; bool is_autojoin = false; foreach (Xep.Bookmarks.Conference conference in conferences) { - if (conference.jid == conversation.counterpart.to_string()) { + if (conference.jid.equals(conversation.counterpart)) { if (conference.autojoin) is_autojoin = true; } } @@ -292,19 +281,20 @@ public class MucManager : StreamInteractionModule, Object { if (!conference.autojoin) continue; bool is_active = false; foreach (Conversation conversation in conversations) { - if (conference.jid == conversation.counterpart.to_string()) is_active = true; + if (conference.jid.equals(conversation.counterpart)) is_active = true; } if (!is_active) { - join(account, new Jid(conference.jid), conference.nick, conference.password); + join(account, conference.jid, conference.nick, conference.password); } } } - private void set_autojoin(Core.XmppStream stream, Jid jid, string? nick, string? password) { + private void set_autojoin(XmppStream stream, Jid jid, string? nick, string? password) { stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences) => { - Xep.Bookmarks.Conference changed = new Xep.Bookmarks.Conference(jid.to_string()) { nick=nick, password=password, autojoin=true }; + if (conferences == null) return; + Xep.Bookmarks.Conference changed = new Xep.Bookmarks.Conference(jid) { nick=nick, password=password, autojoin=true }; foreach (Xep.Bookmarks.Conference conference in conferences) { - if (conference.jid == jid.bare_jid.to_string() && conference.nick == nick && conference.password == password) { + if (conference.jid.equals_bare(jid) && conference.nick == nick && conference.password == password) { if (!conference.autojoin) { stream.get_module(Xep.Bookmarks.Module.IDENTITY).replace_conference(stream, conference, changed); } @@ -315,10 +305,11 @@ public class MucManager : StreamInteractionModule, Object { }); } - private void unset_autojoin(Core.XmppStream stream, Jid jid) { + private void unset_autojoin(XmppStream stream, Jid jid) { stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences) => { + if (conferences == null) return; foreach (Xep.Bookmarks.Conference conference in conferences) { - if (conference.jid == jid.bare_jid.to_string()) { + if (conference.jid.equals_bare(jid)) { if (conference.autojoin) { Xep.Bookmarks.Conference change = new Xep.Bookmarks.Conference(conference.jid) { nick=conference.nick, password=conference.password, autojoin=false }; stream.get_module(Xep.Bookmarks.Module.IDENTITY).replace_conference(stream, conference, change); diff --git a/libdino/src/service/presence_manager.vala b/libdino/src/service/presence_manager.vala index e3ece45f..0525100b 100644 --- a/libdino/src/service/presence_manager.vala +++ b/libdino/src/service/presence_manager.vala @@ -27,9 +27,9 @@ public class PresenceManager : StreamInteractionModule, Object { } public Show get_last_show(Jid jid, Account account) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - Xmpp.Presence.Stanza? presence = stream.get_flag(Presence.Flag.IDENTITY).get_presence(jid.to_string()); + Xmpp.Presence.Stanza? presence = stream.get_flag(Presence.Flag.IDENTITY).get_presence(jid); if (presence != null) { return new Show(jid, presence.show, new DateTime.now_utc()); } @@ -41,20 +41,12 @@ public class PresenceManager : StreamInteractionModule, Object { return shows[jid]; } - public ArrayList? get_full_jids(Jid jid, Account account) { - Core.XmppStream? stream = stream_interactor.get_stream(account); + public Gee.List? get_full_jids(Jid jid, Account account) { + XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { Xmpp.Presence.Flag flag = stream.get_flag(Presence.Flag.IDENTITY); if (flag == null) return null; - Gee.List? resources = flag.get_resources(jid.bare_jid.to_string()); - if (resources == null) { - return null; - } - ArrayList ret = new ArrayList(Jid.equals_func); - foreach (string resource in resources) { - ret.add(new Jid(resource)); - } - return ret; + return flag.get_resources(jid.bare_jid); } return null; } @@ -64,40 +56,39 @@ public class PresenceManager : StreamInteractionModule, Object { } public void request_subscription(Account account, Jid jid) { - Core.XmppStream stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).request_subscription(stream, jid.bare_jid.to_string()); + XmppStream stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).request_subscription(stream, jid.bare_jid); } public void approve_subscription(Account account, Jid jid) { - Core.XmppStream stream = stream_interactor.get_stream(account); + XmppStream stream = stream_interactor.get_stream(account); if (stream != null) { - stream.get_module(Xmpp.Presence.Module.IDENTITY).approve_subscription(stream, jid.bare_jid.to_string()); + stream.get_module(Xmpp.Presence.Module.IDENTITY).approve_subscription(stream, jid.bare_jid); subscription_requests.remove(jid); } } public void deny_subscription(Account account, Jid jid) { - Core.XmppStream stream = stream_interactor.get_stream(account); + XmppStream stream = stream_interactor.get_stream(account); if (stream != null) { - stream.get_module(Xmpp.Presence.Module.IDENTITY).deny_subscription(stream, jid.bare_jid.to_string()); + stream.get_module(Xmpp.Presence.Module.IDENTITY).deny_subscription(stream, jid.bare_jid); subscription_requests.remove(jid); } } public void cancel_subscription(Account account, Jid jid) { - Core.XmppStream stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).cancel_subscription(stream, jid.bare_jid.to_string()); + XmppStream stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).cancel_subscription(stream, jid.bare_jid); } private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_available_show.connect((stream, jid, show) => - on_received_available_show(account, new Jid(jid), show) + on_received_available_show(account, jid, show) ); stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_unavailable.connect((stream, presence) => - on_received_unavailable(account, new Jid(presence.from)) + on_received_unavailable(account, presence.from) ); - stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_request.connect((stream, jid_str) => { - Jid jid = new Jid(jid_str); + stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_request.connect((stream, jid) => { if (!subscription_requests.contains(jid)) { subscription_requests.add(jid); } diff --git a/libdino/src/service/roster_manager.vala b/libdino/src/service/roster_manager.vala index 51a64625..3c96778d 100644 --- a/libdino/src/service/roster_manager.vala +++ b/libdino/src/service/roster_manager.vala @@ -40,18 +40,18 @@ public class RosterManager : StreamInteractionModule, Object { } public void remove_jid(Account account, Jid jid) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).remove_jid(stream, jid.bare_jid.to_string()); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).remove_jid(stream, jid.bare_jid); } public void add_jid(Account account, Jid jid, string? handle) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).add_jid(stream, jid.bare_jid.to_string(), handle); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).add_jid(stream, jid.bare_jid, handle); } public void set_jid_handle(Account account, Jid jid, string? handle) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).set_jid_handle(stream, jid.bare_jid.to_string(), handle); + XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).set_jid_handle(stream, jid.bare_jid, handle); } private void on_account_added(Account account) { @@ -61,7 +61,7 @@ public class RosterManager : StreamInteractionModule, Object { } }); stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).item_removed.connect( (stream, roster_item) => { - removed_roster_item(account, new Jid(roster_item.jid), roster_item); + removed_roster_item(account, roster_item.jid, roster_item); }); stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).item_updated.connect( (stream, roster_item) => { on_roster_item_updated(account, roster_item); @@ -69,7 +69,7 @@ public class RosterManager : StreamInteractionModule, Object { } private void on_roster_item_updated(Account account, Roster.Item roster_item) { - updated_roster_item(account, new Jid(roster_item.jid), roster_item); + updated_roster_item(account, roster_item.jid, roster_item); } } @@ -77,7 +77,7 @@ public class RosterStoreImpl : Roster.Storage, Object { private Account account; private Database db; - private HashMap items = new HashMap(); + private HashMap items = new HashMap(Jid.hash_bare_func, Jid.equals_bare_func); public class RosterStoreImpl(Account account, Database db) { this.account = account; @@ -85,7 +85,7 @@ public class RosterStoreImpl : Roster.Storage, Object { foreach (Qlite.Row row in db.roster.select().with(db.roster.account_id, "=", account.id)) { Roster.Item item = new Roster.Item(); - item.jid = row[db.roster.jid]; + item.jid = Jid.parse(row[db.roster.jid]); item.name = row[db.roster.handle]; item.subscription = row[db.roster.subscription]; items[item.jid] = item; @@ -101,7 +101,7 @@ public class RosterStoreImpl : Roster.Storage, Object { } public Roster.Item? get_item(Jid jid) { - return items.has_key(jid.bare_jid.to_string()) ? items[jid.bare_jid.to_string()] : null; + return items.has_key(jid) ? items[jid] : null; } public void set_roster_version(string version) { @@ -119,7 +119,7 @@ public class RosterStoreImpl : Roster.Storage, Object { items[item.jid] = item; db.roster.insert().or("REPLACE") .value(db.roster.account_id, account.id) - .value(db.roster.jid, item.jid) + .value(db.roster.jid, item.jid.to_string()) .value(db.roster.handle, item.name) .value(db.roster.subscription, item.subscription) .perform(); @@ -129,7 +129,7 @@ public class RosterStoreImpl : Roster.Storage, Object { items.unset(item.jid); db.roster.delete() .with(db.roster.account_id, "=", account.id) - .with(db.roster.jid, "=", item.jid).perform(); + .with(db.roster.jid, "=", item.jid.to_string()).perform(); } } diff --git a/libdino/src/service/stream_interactor.vala b/libdino/src/service/stream_interactor.vala index f97eb482..d9f3f0ec 100644 --- a/libdino/src/service/stream_interactor.vala +++ b/libdino/src/service/stream_interactor.vala @@ -9,8 +9,8 @@ public class StreamInteractor { public signal void account_added(Account account); public signal void account_removed(Account account); - public signal void stream_negotiated(Account account, Core.XmppStream stream); - public signal void attached_modules(Account account, Core.XmppStream stream); + public signal void stream_negotiated(Account account, XmppStream stream); + public signal void attached_modules(Account account, XmppStream stream); public ModuleManager module_manager; public ConnectionManager connection_manager; @@ -42,7 +42,7 @@ public class StreamInteractor { return ret; } - public Core.XmppStream? get_stream(Account account) { + public XmppStream? get_stream(Account account) { return connection_manager.get_stream(account); } @@ -58,7 +58,7 @@ public class StreamInteractor { return null; } - private void on_stream_opened(Account account, Core.XmppStream stream) { + private void on_stream_opened(Account account, XmppStream stream) { stream.stream_negotiated.connect( (stream) => { stream_negotiated(account, stream); }); -- cgit v1.2.3-70-g09d2