diff options
author | Marvin W <git@larma.de> | 2017-03-11 23:52:12 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2017-03-11 23:58:35 +0100 |
commit | e27d63269d0b41fa8d5b5f0f2e4a9dc7de4b9ab9 (patch) | |
tree | 80e547d0e02e770e8bcd912e42f8afa753aeb0f6 /main/src/ui/notifications.vala | |
parent | cd6b904e970291a63551d0f1d80bbd550e778ec8 (diff) | |
download | dino-e27d63269d0b41fa8d5b5f0f2e4a9dc7de4b9ab9.tar.gz dino-e27d63269d0b41fa8d5b5f0f2e4a9dc7de4b9ab9.zip |
Move UI code into main dir
Diffstat (limited to 'main/src/ui/notifications.vala')
-rw-r--r-- | main/src/ui/notifications.vala | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala new file mode 100644 index 00000000..17636995 --- /dev/null +++ b/main/src/ui/notifications.vala @@ -0,0 +1,57 @@ +using Dino.Entities; +using Xmpp; + +namespace Dino.Ui { + +public class Notifications : GLib.Object { + + private StreamInteractor stream_interactor; + private Notify.Notification notification = new Notify.Notification("", null, null); + + public Notifications(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + } + + public void start() { + MessageManager.get_instance(stream_interactor).message_received.connect(on_message_received); + PresenceManager.get_instance(stream_interactor).received_subscription_request.connect(on_received_subscription_request); + } + + private void on_message_received(Entities.Message message, Conversation conversation) { + if (!ChatInteraction.get_instance(stream_interactor).is_active_focus()) { + string display_name = Util.get_conversation_display_name(stream_interactor, conversation); + if (MucManager.get_instance(stream_interactor).is_groupchat(conversation.counterpart, conversation.account)) { + string muc_occupant = Util.get_display_name(stream_interactor, message.from, conversation.account); + display_name = muc_occupant + " in " + display_name; + } + notification.update(display_name, message.body, null); + notification.set_image_from_pixbuf((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation)); + notification.set_timeout(3); + try { + notification.show(); + } catch (Error error) { } + } + } + + private void on_received_subscription_request(Jid jid, Account account) { + Notify.Notification notification = new Notify.Notification("Subscription request", jid.bare_jid.to_string(), null); + notification.set_image_from_pixbuf((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account)); + notification.add_action("accept", "Accept", () => { + PresenceManager.get_instance(stream_interactor).approve_subscription(account, jid); + try { + notification.close(); + } catch (Error error) { } + }); + notification.add_action("deny", "Deny", () => { + PresenceManager.get_instance(stream_interactor).deny_subscription(account, jid); + try { + notification.close(); + } catch (Error error) { } + }); + try { + notification.show(); + } catch (Error error) { } + } +} + +}
\ No newline at end of file |