From b4bb0912fc328bc44b13e190f59b347eb5d4310a Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 14 Dec 2017 02:01:55 +0100 Subject: Show subscription request in conversation summary --- libdino/src/application.vala | 13 +++++++++++++ libdino/src/service/presence_manager.vala | 25 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) (limited to 'libdino/src') diff --git a/libdino/src/application.vala b/libdino/src/application.vala index 55913a99..f6e651a4 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -38,6 +38,8 @@ public interface Dino.Application : GLib.Application { ChatInteraction.start(stream_interactor); FileManager.start(stream_interactor, db); + create_actions(); + activate.connect(() => { stream_interactor.connection_manager.log_options = print_xmpp; Idle.add(() => { @@ -93,6 +95,17 @@ public interface Dino.Application : GLib.Application { return (Dino.Application) GLib.Application.get_default(); } + public void create_actions() { + SimpleAction accept_subscription_action = new SimpleAction("accept-subscription", VariantType.INT32); + accept_subscription_action.activate.connect((variant) => { + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32()); + if (conversation == null) return; + stream_interactor.get_module(PresenceManager.IDENTITY).approve_subscription(conversation.account, conversation.counterpart); + stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(conversation.account, conversation.counterpart); + }); + add_action(accept_subscription_action); + } + protected void add_connection(Account account) { stream_interactor.connect(account); } diff --git a/libdino/src/service/presence_manager.vala b/libdino/src/service/presence_manager.vala index 298fa234..7e74f125 100644 --- a/libdino/src/service/presence_manager.vala +++ b/libdino/src/service/presence_manager.vala @@ -14,6 +14,7 @@ public class PresenceManager : StreamInteractionModule, Object { private StreamInteractor stream_interactor; private HashMap>> shows = new HashMap>>(Jid.hash_bare_func, Jid.equals_bare_func); private HashMap> resources = new HashMap>(Jid.hash_bare_func, Jid.equals_bare_func); + private Gee.List subscription_requests = new ArrayList(Jid.equals_func); public static void start(StreamInteractor stream_interactor) { PresenceManager m = new PresenceManager(stream_interactor); @@ -59,6 +60,10 @@ public class PresenceManager : StreamInteractionModule, Object { return null; } + public bool exists_subscription_request(Account account, Jid jid) { + return subscription_requests.contains(jid); + } + 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()); @@ -66,12 +71,18 @@ public class PresenceManager : StreamInteractionModule, Object { public void approve_subscription(Account account, Jid jid) { Core.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()); + if (stream != null) { + stream.get_module(Xmpp.Presence.Module.IDENTITY).approve_subscription(stream, jid.bare_jid.to_string()); + subscription_requests.remove(jid); + } } public void deny_subscription(Account account, Jid jid) { Core.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()); + if (stream != null) { + stream.get_module(Xmpp.Presence.Module.IDENTITY).deny_subscription(stream, jid.bare_jid.to_string()); + subscription_requests.remove(jid); + } } public void cancel_subscription(Account account, Jid jid) { @@ -86,9 +97,13 @@ public class PresenceManager : StreamInteractionModule, Object { stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_unavailable.connect((stream, presence) => on_received_unavailable(account, new Jid(presence.from)) ); - stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_request.connect((stream, jid) => - received_subscription_request(new Jid(jid), account) - ); + stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_request.connect((stream, jid_str) => { + Jid jid = new Jid(jid_str); + if (!subscription_requests.contains(jid)) { + subscription_requests.add(jid); + } + received_subscription_request(jid, account); + }); } private void on_received_available_show(Account account, Jid jid, string show) { -- cgit v1.2.3-70-g09d2