From b4bb0912fc328bc44b13e190f59b347eb5d4310a Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 14 Dec 2017 02:01:55 +0100 Subject: [PATCH] Show subscription request in conversation summary --- .tito/packages/.readme | 3 - .tito/packages/dino | 1 - .tito/tito.props | 5 -- libdino/src/application.vala | 13 ++++ libdino/src/service/presence_manager.vala | 25 +++++-- main/CMakeLists.txt | 1 + .../add_conversation/add_contact_dialog.ui | 15 +---- main/data/contact_details_dialog.ui | 2 +- main/data/conversation_summary/view.ui | 57 +++++++++++++--- .../add_conversation/add_contact_dialog.vala | 5 +- main/src/ui/application.vala | 24 ++++++- .../conversation_view.vala | 23 +++++++ .../subscription_notification.vala | 55 ++++++++++++++++ main/src/ui/notifications.vala | 65 ++++++------------- xmpp-vala/src/module/presence/module.vala | 1 + 15 files changed, 204 insertions(+), 91 deletions(-) delete mode 100644 .tito/packages/.readme delete mode 100644 .tito/packages/dino delete mode 100644 .tito/tito.props create mode 100644 main/src/ui/conversation_summary/subscription_notification.vala diff --git a/.tito/packages/.readme b/.tito/packages/.readme deleted file mode 100644 index b9411e2d..00000000 --- a/.tito/packages/.readme +++ /dev/null @@ -1,3 +0,0 @@ -the .tito/packages directory contains metadata files -named after their packages. Each file has the latest tagged -version and the project's relative directory. diff --git a/.tito/packages/dino b/.tito/packages/dino deleted file mode 100644 index 3738ee1f..00000000 --- a/.tito/packages/dino +++ /dev/null @@ -1 +0,0 @@ -0.0-1 ./ diff --git a/.tito/tito.props b/.tito/tito.props deleted file mode 100644 index eab3f190..00000000 --- a/.tito/tito.props +++ /dev/null @@ -1,5 +0,0 @@ -[buildconfig] -builder = tito.builder.Builder -tagger = tito.tagger.VersionTagger -changelog_do_not_remove_cherrypick = 0 -changelog_format = %s (%ae) 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) { diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 4a799758..b9b6fa29 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -109,6 +109,7 @@ SOURCES src/ui/conversation_summary/message_populator.vala src/ui/conversation_summary/message_textview.vala src/ui/conversation_summary/slashme_message_display.vala + src/ui/conversation_summary/subscription_notification.vala src/ui/conversation_titlebar/file_entry.vala src/ui/conversation_titlebar/menu_entry.vala src/ui/conversation_titlebar/occupants_entry.vala diff --git a/main/data/add_conversation/add_contact_dialog.ui b/main/data/add_conversation/add_contact_dialog.ui index abf9d892..6185c5ba 100644 --- a/main/data/add_conversation/add_contact_dialog.ui +++ b/main/data/add_conversation/add_contact_dialog.ui @@ -5,6 +5,7 @@ True + Add Contact True @@ -123,20 +124,6 @@ 1 - - - True - Request presence updates - 0 - True - - - 1 - 3 - 1 - 1 - - diff --git a/main/data/contact_details_dialog.ui b/main/data/contact_details_dialog.ui index 8fa62398..0903b260 100644 --- a/main/data/contact_details_dialog.ui +++ b/main/data/contact_details_dialog.ui @@ -4,7 +4,7 @@ True - Conversation Details + Conversation Details True True diff --git a/main/data/conversation_summary/view.ui b/main/data/conversation_summary/view.ui index 9139da56..2bc13752 100644 --- a/main/data/conversation_summary/view.ui +++ b/main/data/conversation_summary/view.ui @@ -10,26 +10,63 @@ crossfade True - - never + True - - 15 - vertical + + never True - - False + + 15 vertical - 15 True + + + False + vertical + 15 + True + + + + + True + True + + + + + -1 + + + + + True + False + center + start - - True + True + False + 0 + none + + + + False + vertical + True + + + + + diff --git a/main/src/ui/add_conversation/add_contact_dialog.vala b/main/src/ui/add_conversation/add_contact_dialog.vala index 2e7830a3..decc588d 100644 --- a/main/src/ui/add_conversation/add_contact_dialog.vala +++ b/main/src/ui/add_conversation/add_contact_dialog.vala @@ -23,7 +23,6 @@ protected class AddContactDialog : Gtk.Dialog { [GtkChild] private Button cancel_button; [GtkChild] private Entry jid_entry; [GtkChild] private Entry alias_entry; - [GtkChild] private CheckButton subscribe_checkbutton; private StreamInteractor stream_interactor; @@ -41,9 +40,7 @@ protected class AddContactDialog : Gtk.Dialog { string? alias = alias_entry.text == "" ? null : alias_entry.text; Jid jid = new Jid(jid_entry.text); stream_interactor.get_module(RosterManager.IDENTITY).add_jid(account, jid, alias); - if (subscribe_checkbutton.active) { - stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid); - } + stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid); close(); } diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index a506f511..3ebe3cff 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -23,6 +23,8 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { provider.load_from_resource("/im/dino/Dino/theme.css"); StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider, STYLE_PROVIDER_PRIORITY_APPLICATION); + create_actions(); + activate.connect(() => { if (window == null) { create_set_app_menu(); @@ -76,9 +78,27 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { } } + private void create_actions() { + SimpleAction open_conversation_action = new SimpleAction("open-conversation", VariantType.INT32); + open_conversation_action.activate.connect((variant) => { + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32()); + if (conversation != null) window.on_conversation_selected(conversation); + window.present(); + }); + add_action(open_conversation_action); + + SimpleAction deny_subscription_action = new SimpleAction("deny-subscription", VariantType.INT32); + deny_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).deny_subscription(conversation.account, conversation.counterpart); + }); + add_action(deny_subscription_action); + } + private void show_accounts_window() { ManageAccounts.Dialog dialog = new ManageAccounts.Dialog(stream_interactor, db); - dialog.set_transient_for(window); + dialog.set_transient_for(get_active_window()); dialog.account_enabled.connect(add_connection); dialog.account_disabled.connect(remove_connection); dialog.present(); @@ -86,7 +106,7 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { private void show_settings_window() { SettingsDialog dialog = new SettingsDialog(); - dialog.set_transient_for(window); + dialog.set_transient_for(get_active_window()); dialog.present(); } diff --git a/main/src/ui/conversation_summary/conversation_view.vala b/main/src/ui/conversation_summary/conversation_view.vala index 7924da57..874605c8 100644 --- a/main/src/ui/conversation_summary/conversation_view.vala +++ b/main/src/ui/conversation_summary/conversation_view.vala @@ -12,6 +12,8 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { public Conversation? conversation { get; private set; } [GtkChild] private ScrolledWindow scrolled; + [GtkChild] private Revealer notification_revealer; + [GtkChild] private Box notifications; [GtkChild] private Box main; [GtkChild] private Stack stack; @@ -22,6 +24,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { private Gee.HashMap widgets = new Gee.HashMap(); private Gee.List item_skeletons = new Gee.ArrayList(); private MessagePopulator message_item_populator; + private SubscriptionNotitication subscription_notification; private double? was_value; private double? was_upper; @@ -36,6 +39,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { scrolled.vadjustment.notify["value"].connect(on_value_notify); message_item_populator = new MessagePopulator(stream_interactor); + subscription_notification = new SubscriptionNotitication(stream_interactor); insert_item.connect(on_insert_item); remove_item.connect(on_remove_item); @@ -77,6 +81,8 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { message_item_populator.populate_latest(conversation, 40); Idle.add(() => { on_value_notify(); return false; }); + subscription_notification.init(conversation, this); + stack.set_visible_child_name("main"); } @@ -104,6 +110,20 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { } } + public void add_notification(Widget widget) { + notifications.add(widget); + Timeout.add(20, () => { + notification_revealer.transition_duration = 200; + notification_revealer.reveal_child = true; + return false; + }); + } + + public void remove_notification(Widget widget) { + notification_revealer.reveal_child = false; + widget.destroy(); + } + private bool merge_back(Plugins.MetaConversationItem item) { Plugins.MetaConversationItem? lower_item = meta_items.lower(item); if (lower_item != null) { @@ -246,6 +266,9 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { item_item_skeletons.clear(); widgets.clear(); main.@foreach((widget) => { widget.destroy(); }); + notifications.@foreach((widget) => { widget.destroy(); }); + notification_revealer.transition_duration = 0; + notification_revealer.set_reveal_child(false); } } diff --git a/main/src/ui/conversation_summary/subscription_notification.vala b/main/src/ui/conversation_summary/subscription_notification.vala new file mode 100644 index 00000000..225e4b00 --- /dev/null +++ b/main/src/ui/conversation_summary/subscription_notification.vala @@ -0,0 +1,55 @@ +using Gee; +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui.ConversationSummary { + +public class SubscriptionNotitication : Object { + + private StreamInteractor stream_interactor; + private Conversation conversation; + private ConversationView conversation_view; + + public SubscriptionNotitication(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + + stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect((jid, account) => { + Conversation relevant_conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); + stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(relevant_conversation, true); + if (conversation != null && account.equals(conversation.account) && jid.equals(conversation.counterpart)) { + show_notification(); + } + }); + } + + public void init(Conversation conversation, ConversationView conversation_view) { + this.conversation = conversation; + this.conversation_view = conversation_view; + + if (stream_interactor.get_module(PresenceManager.IDENTITY).exists_subscription_request(conversation.account, conversation.counterpart)) { + show_notification(); + } + } + + private void show_notification() { + Box box = new Box(Orientation.HORIZONTAL, 5) { visible=true }; + Button accept_button = new Button() { label=_("Accept"), visible=true }; + Button deny_button = new Button() { label=_("Deny"), visible=true }; + GLib.Application app = GLib.Application.get_default(); + accept_button.clicked.connect(() => { + app.activate_action("accept-subscription", conversation.id); + conversation_view.remove_notification(box); + }); + deny_button.clicked.connect(() => { + app.activate_action("deny-subscription", conversation.id); + conversation_view.remove_notification(box); + }); + box.add(new Label(_("This contact would like to add you to their contact list")) { margin_end=10, visible=true }); + box.add(accept_button); + box.add(deny_button); + conversation_view.add_notification(box); + } +} + +} diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index 464f5b0d..d9f70668 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -12,63 +12,32 @@ public class Notifications : Object { private StreamInteractor stream_interactor; private Gtk.Window window; private HashMap notifications = new HashMap(Conversation.hash_func, Conversation.equals_func); - private Set? active_notification_ids = null; - - private enum ClosedReason { // org.freedesktop.Notifications.NotificationClosed - EXPIRED = 1, - USER_DISMISSED = 2, - CLOSE_NOTIFICATION = 3, - UNDEFINED = 4 - } + private Set? active_conversation_ids = null; + private Set? active_ids = new HashSet(); public Notifications(StreamInteractor stream_interactor, Gtk.Window window) { this.stream_interactor = stream_interactor; this.window = window; - stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect(() => { - if (active_notification_ids == null) { + stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect((focused_conversation) => { + if (active_conversation_ids == null) { Gee.List conversations = stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations(); foreach (Conversation conversation in conversations) { GLib.Application.get_default().withdraw_notification(conversation.id.to_string()); } - active_notification_ids = new HashSet(); + active_conversation_ids = new HashSet(); } else { - foreach (string id in active_notification_ids) { + foreach (string id in active_conversation_ids) { GLib.Application.get_default().withdraw_notification(id); } - active_notification_ids.clear(); + active_conversation_ids.clear(); + } + + string subscription_id = focused_conversation.id.to_string() + "-subscription"; + if (active_ids.contains(subscription_id)) { + GLib.Application.get_default().withdraw_notification(subscription_id); } }); - - SimpleAction open_conversation_action = new SimpleAction("open-conversation", VariantType.INT32); - open_conversation_action.activate.connect((variant) => { - Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32()); - if (conversation != null) conversation_selected(conversation); - window.present(); - }); - GLib.Application.get_default().add_action(open_conversation_action); - - 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); - if (stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(conversation.account, conversation.counterpart) == null) { - AddContactDialog dialog = new AddContactDialog(stream_interactor); - dialog.jid = conversation.counterpart.bare_jid.to_string(); - dialog.account = conversation.account; - dialog.present(); - } - }); - GLib.Application.get_default().add_action(accept_subscription_action); - - SimpleAction deny_subscription_action = new SimpleAction("deny-subscription", VariantType.INT32); - deny_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).deny_subscription(conversation.account, conversation.counterpart); - }); - GLib.Application.get_default().add_action(deny_subscription_action); } public void start() { @@ -96,21 +65,25 @@ public class Notifications : Object { notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation))); } catch (Error e) { } window.get_application().send_notification(conversation.id.to_string(), notifications[conversation]); - active_notification_ids.add(conversation.id.to_string()); + active_conversation_ids.add(conversation.id.to_string()); window.urgency_hint = true; } } private void on_received_subscription_request(Jid jid, Account account) { + Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); + if (stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus(conversation)) return; + Notification notification = new Notification(_("Subscription request")); notification.set_body(jid.bare_jid.to_string()); try { notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account))); } catch (Error e) { } - Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); + notification.set_default_action_and_target_value("app.open-conversation", new Variant.int32(conversation.id)); notification.add_button_with_target_value(_("Accept"), "app.accept-subscription", conversation.id); notification.add_button_with_target_value(_("Deny"), "app.deny-subscription", conversation.id); - window.get_application().send_notification(null, notification); + window.get_application().send_notification(conversation.id.to_string() + "-subscription", notification); + active_ids.add(conversation.id.to_string() + "-subscription"); } private bool should_notify_message(Entities.Message message, Conversation conversation) { diff --git a/xmpp-vala/src/module/presence/module.vala b/xmpp-vala/src/module/presence/module.vala index ef5f4d74..3488f532 100644 --- a/xmpp-vala/src/module/presence/module.vala +++ b/xmpp-vala/src/module/presence/module.vala @@ -82,6 +82,7 @@ namespace Xmpp.Presence { received_subscription_request(stream, presence.from); break; case Presence.Stanza.TYPE_UNSUBSCRIBE: + stream.get_flag(Flag.IDENTITY).remove_presence(presence.from); received_unsubscription(stream, presence.from); break; }