aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/notifications.vala
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-12-14 02:01:55 +0100
committerfiaxh <git@mx.ax.lt>2017-12-30 13:10:06 +0100
commitb4bb0912fc328bc44b13e190f59b347eb5d4310a (patch)
treea18f680f8349eb758dd54fd44321837bcd228545 /main/src/ui/notifications.vala
parentf25fadde2d6c9492b9cafe2cddbcc7b966942e47 (diff)
downloaddino-b4bb0912fc328bc44b13e190f59b347eb5d4310a.tar.gz
dino-b4bb0912fc328bc44b13e190f59b347eb5d4310a.zip
Show subscription request in conversation summary
Diffstat (limited to 'main/src/ui/notifications.vala')
-rw-r--r--main/src/ui/notifications.vala61
1 files changed, 17 insertions, 44 deletions
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<Conversation, Notification> notifications = new HashMap<Conversation, Notification>(Conversation.hash_func, Conversation.equals_func);
- private Set<string>? active_notification_ids = null;
-
- private enum ClosedReason { // org.freedesktop.Notifications.NotificationClosed
- EXPIRED = 1,
- USER_DISMISSED = 2,
- CLOSE_NOTIFICATION = 3,
- UNDEFINED = 4
- }
+ private Set<string>? active_conversation_ids = null;
+ private Set<string>? active_ids = new HashSet<string>();
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<Conversation> 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<string>();
+ active_conversation_ids = new HashSet<string>();
} 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) {