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/conversation_summary/conversation_view.vala | 23 +++++++++ .../subscription_notification.vala | 55 ++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 main/src/ui/conversation_summary/subscription_notification.vala (limited to 'main/src/ui/conversation_summary') 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); + } +} + +} -- cgit v1.2.3-70-g09d2