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 --- .../ui/add_conversation/add_contact_dialog.vala | 5 +- main/src/ui/application.vala | 24 ++++++++- .../ui/conversation_summary/conversation_view.vala | 23 ++++++++ .../subscription_notification.vala | 55 +++++++++++++++++++ main/src/ui/notifications.vala | 61 ++++++---------------- 5 files changed, 118 insertions(+), 50 deletions(-) create mode 100644 main/src/ui/conversation_summary/subscription_notification.vala (limited to 'main/src/ui') 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(); } - }); - 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(); + string subscription_id = focused_conversation.id.to_string() + "-subscription"; + if (active_ids.contains(subscription_id)) { + GLib.Application.get_default().withdraw_notification(subscription_id); } }); - 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) { -- cgit v1.2.3-54-g00ecf