From 0bfab9d1d97d07679da4a2a1db5903782a74ae49 Mon Sep 17 00:00:00 2001 From: Samuel Hand Date: Sun, 5 Aug 2018 01:26:36 +0100 Subject: Fix bug where OMEMO not avaiable with a newly added contact --- xmpp-vala/src/module/presence/flag.vala | 2 +- xmpp-vala/src/module/presence/module.vala | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'xmpp-vala/src') diff --git a/xmpp-vala/src/module/presence/flag.vala b/xmpp-vala/src/module/presence/flag.vala index bb3562a4..77bc0b5f 100644 --- a/xmpp-vala/src/module/presence/flag.vala +++ b/xmpp-vala/src/module/presence/flag.vala @@ -57,4 +57,4 @@ public class Flag : XmppStreamFlag { } } -} \ No newline at end of file +} diff --git a/xmpp-vala/src/module/presence/module.vala b/xmpp-vala/src/module/presence/module.vala index 12b40245..2188d89d 100644 --- a/xmpp-vala/src/module/presence/module.vala +++ b/xmpp-vala/src/module/presence/module.vala @@ -1,3 +1,5 @@ +using Gee; + namespace Xmpp.Presence { private const string NS_URI = "jabber:client"; @@ -13,9 +15,13 @@ namespace Xmpp.Presence { public signal void received_subscription_request(XmppStream stream, Jid jid); public signal void received_subscription_approval(XmppStream stream, Jid jid); public signal void received_unsubscription(XmppStream stream, Jid jid); + public signal void mutual_subscription(XmppStream stream, Jid jid); public bool available_resource = true; + private Gee.List subscriptions = new ArrayList(Jid.equals_bare_func); + private Gee.List subscribers = new ArrayList(Jid.equals_bare_func); + public void request_subscription(XmppStream stream, Jid bare_jid) { Presence.Stanza presence = new Presence.Stanza(); presence.to = bare_jid; @@ -28,6 +34,8 @@ namespace Xmpp.Presence { presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_SUBSCRIBED; send_presence(stream, presence); + subscribers.add(bare_jid); + if (subscriptions.contains(bare_jid)) mutual_subscription(stream, bare_jid); } public void deny_subscription(XmppStream stream, Jid bare_jid) { @@ -39,6 +47,7 @@ namespace Xmpp.Presence { presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_UNSUBSCRIBED; send_presence(stream, presence); + subscribers.remove(bare_jid); } public void unsubscribe(XmppStream stream, Jid bare_jid) { @@ -46,6 +55,7 @@ namespace Xmpp.Presence { presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_UNSUBSCRIBE; send_presence(stream, presence); + subscriptions.remove(bare_jid); } public void send_presence(XmppStream stream, Presence.Stanza presence) { @@ -82,10 +92,16 @@ namespace Xmpp.Presence { break; case Presence.Stanza.TYPE_SUBSCRIBED: received_subscription_approval(stream, presence.from); + subscriptions.add(presence.from); + if (subscribers.contains(presence.from)) mutual_subscription(stream, presence.from); break; case Presence.Stanza.TYPE_UNSUBSCRIBE: stream.get_flag(Flag.IDENTITY).remove_presence(presence.from); received_unsubscription(stream, presence.from); + subscribers.remove(presence.from); + break; + case Presence.Stanza.TYPE_UNSUBSCRIBED: + subscriptions.remove(presence.from); break; } } -- cgit v1.2.3-70-g09d2 From 8ebc2c5dd333ce19c9e0592ee1feb8eed6e1a48f Mon Sep 17 00:00:00 2001 From: Samuel Hand Date: Fri, 10 Aug 2018 01:40:20 +0100 Subject: Fix mutual subscription detection --- libdino/src/service/presence_manager.vala | 4 ---- libdino/src/service/roster_manager.vala | 5 +++++ plugins/omemo/src/manager.vala | 4 ++-- xmpp-vala/src/module/presence/module.vala | 12 ------------ xmpp-vala/src/module/roster/module.vala | 5 +++++ 5 files changed, 12 insertions(+), 18 deletions(-) (limited to 'xmpp-vala/src') diff --git a/libdino/src/service/presence_manager.vala b/libdino/src/service/presence_manager.vala index 62100c2c..e832687d 100644 --- a/libdino/src/service/presence_manager.vala +++ b/libdino/src/service/presence_manager.vala @@ -11,7 +11,6 @@ public class PresenceManager : StreamInteractionModule, Object { public signal void show_received(Show show, Jid jid, Account account); public signal void received_subscription_request(Jid jid, Account account); public signal void received_subscription_approval(Jid jid, Account account); - public signal void mutual_subscription(Jid jid, Account account); private StreamInteractor stream_interactor; private HashMap>> shows = new HashMap>>(Jid.hash_bare_func, Jid.equals_bare_func); @@ -99,9 +98,6 @@ public class PresenceManager : StreamInteractionModule, Object { stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_approval.connect((stream, jid) => { received_subscription_approval(jid, account); }); - stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).mutual_subscription.connect((stream, jid) => { - mutual_subscription(jid, account); - }); } private void on_received_available_show(Account account, Jid jid, string show) { diff --git a/libdino/src/service/roster_manager.vala b/libdino/src/service/roster_manager.vala index 23bc8b76..5181b90e 100644 --- a/libdino/src/service/roster_manager.vala +++ b/libdino/src/service/roster_manager.vala @@ -11,6 +11,7 @@ public class RosterManager : StreamInteractionModule, Object { public signal void removed_roster_item(Account account, Jid jid, Roster.Item roster_item); public signal void updated_roster_item(Account account, Jid jid, Roster.Item roster_item); + public signal void mutual_subscription(Account account, Jid jid); private StreamInteractor stream_interactor; private Database db; @@ -66,6 +67,10 @@ public class RosterManager : StreamInteractionModule, Object { stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).item_updated.connect_after( (stream, roster_item) => { on_roster_item_updated(account, roster_item); }); + + stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).mutual_subscription.connect_after( (stream, jid) => { + mutual_subscription(account, jid); + }); } private void on_roster_item_updated(Account account, Roster.Item roster_item) { diff --git a/plugins/omemo/src/manager.vala b/plugins/omemo/src/manager.vala index bb8063b2..c75b15e2 100644 --- a/plugins/omemo/src/manager.vala +++ b/plugins/omemo/src/manager.vala @@ -70,7 +70,7 @@ public class Manager : StreamInteractionModule, Object { stream_interactor.account_added.connect(on_account_added); stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(received_message_listener); stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_send.connect(on_pre_message_send); - stream_interactor.get_module(PresenceManager.IDENTITY).mutual_subscription.connect(on_mutual_subscription); + stream_interactor.get_module(RosterManager.IDENTITY).mutual_subscription.connect(on_mutual_subscription); } private class ReceivedMessageListener : MessageListener { @@ -174,7 +174,7 @@ public class Manager : StreamInteractionModule, Object { } } - private void on_mutual_subscription(Jid jid, Account account) { + private void on_mutual_subscription(Account account, Jid jid) { XmppStream? stream = stream_interactor.get_stream(account); if(stream == null) return; diff --git a/xmpp-vala/src/module/presence/module.vala b/xmpp-vala/src/module/presence/module.vala index 2188d89d..4a9a72a3 100644 --- a/xmpp-vala/src/module/presence/module.vala +++ b/xmpp-vala/src/module/presence/module.vala @@ -15,13 +15,9 @@ namespace Xmpp.Presence { public signal void received_subscription_request(XmppStream stream, Jid jid); public signal void received_subscription_approval(XmppStream stream, Jid jid); public signal void received_unsubscription(XmppStream stream, Jid jid); - public signal void mutual_subscription(XmppStream stream, Jid jid); public bool available_resource = true; - private Gee.List subscriptions = new ArrayList(Jid.equals_bare_func); - private Gee.List subscribers = new ArrayList(Jid.equals_bare_func); - public void request_subscription(XmppStream stream, Jid bare_jid) { Presence.Stanza presence = new Presence.Stanza(); presence.to = bare_jid; @@ -34,8 +30,6 @@ namespace Xmpp.Presence { presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_SUBSCRIBED; send_presence(stream, presence); - subscribers.add(bare_jid); - if (subscriptions.contains(bare_jid)) mutual_subscription(stream, bare_jid); } public void deny_subscription(XmppStream stream, Jid bare_jid) { @@ -47,7 +41,6 @@ namespace Xmpp.Presence { presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_UNSUBSCRIBED; send_presence(stream, presence); - subscribers.remove(bare_jid); } public void unsubscribe(XmppStream stream, Jid bare_jid) { @@ -55,7 +48,6 @@ namespace Xmpp.Presence { presence.to = bare_jid; presence.type_ = Presence.Stanza.TYPE_UNSUBSCRIBE; send_presence(stream, presence); - subscriptions.remove(bare_jid); } public void send_presence(XmppStream stream, Presence.Stanza presence) { @@ -92,16 +84,12 @@ namespace Xmpp.Presence { break; case Presence.Stanza.TYPE_SUBSCRIBED: received_subscription_approval(stream, presence.from); - subscriptions.add(presence.from); - if (subscribers.contains(presence.from)) mutual_subscription(stream, presence.from); break; case Presence.Stanza.TYPE_UNSUBSCRIBE: stream.get_flag(Flag.IDENTITY).remove_presence(presence.from); received_unsubscription(stream, presence.from); - subscribers.remove(presence.from); break; case Presence.Stanza.TYPE_UNSUBSCRIBED: - subscriptions.remove(presence.from); break; } } diff --git a/xmpp-vala/src/module/roster/module.vala b/xmpp-vala/src/module/roster/module.vala index 5b15a43a..2d36211d 100644 --- a/xmpp-vala/src/module/roster/module.vala +++ b/xmpp-vala/src/module/roster/module.vala @@ -11,6 +11,7 @@ public class Module : XmppStreamModule, Iq.Handler { public signal void pre_get_roster(XmppStream stream, Iq.Stanza iq); public signal void item_removed(XmppStream stream, Item item, Iq.Stanza iq); public signal void item_updated(XmppStream stream, Item item, Iq.Stanza iq); + public signal void mutual_subscription(XmppStream stream, Jid jid); public bool interested_resource = true; @@ -55,8 +56,12 @@ public class Module : XmppStreamModule, Iq.Handler { item_removed(stream, item, iq); break; default: + bool is_new = false; + Item old = flag.get_item(item.jid); + is_new = item.subscription == Item.SUBSCRIPTION_BOTH && (old == null || old.subscription == Item.SUBSCRIPTION_BOTH); flag.roster_items[item.jid] = item; item_updated(stream, item, iq); + if(is_new) mutual_subscription(stream, item.jid); break; } } -- cgit v1.2.3-70-g09d2