aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/own_notifications.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2018-11-10 08:05:14 -0600
committerMarvin W <git@larma.de>2018-11-10 08:05:14 -0600
commitdfb75e2cda1eb9edbbdd9ea88c131d9cb31742ed (patch)
treed3c1ae4251844239eb46e57c8eacf03466aed608 /plugins/omemo/src/own_notifications.vala
parent559bbc5ca3ad5d44ea949788005a29fe9d86a232 (diff)
parent65a12021bc7abbf5ddea068ffe9b4715cfc34f0b (diff)
downloaddino-dfb75e2cda1eb9edbbdd9ea88c131d9cb31742ed.tar.gz
dino-dfb75e2cda1eb9edbbdd9ea88c131d9cb31742ed.zip
Merge PR #413 "Improvements to the OMEMO plugin"
Diffstat (limited to 'plugins/omemo/src/own_notifications.vala')
-rw-r--r--plugins/omemo/src/own_notifications.vala42
1 files changed, 42 insertions, 0 deletions
diff --git a/plugins/omemo/src/own_notifications.vala b/plugins/omemo/src/own_notifications.vala
new file mode 100644
index 00000000..5c96f8d5
--- /dev/null
+++ b/plugins/omemo/src/own_notifications.vala
@@ -0,0 +1,42 @@
+using Dino.Entities;
+using Xmpp;
+using Gtk;
+
+namespace Dino.Plugins.Omemo {
+
+public class OwnNotifications {
+
+ private StreamInteractor stream_interactor;
+ private Plugin plugin;
+ private Account account;
+
+ public OwnNotifications (Plugin plugin, StreamInteractor stream_interactor, Account account) {
+ this.stream_interactor = (!)stream_interactor;
+ this.plugin = plugin;
+ this.account = account;
+ stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).bundle_fetched.connect_after((jid, device_id, bundle) => {
+ if (jid.equals(account.bare_jid) && has_new_devices(account.bare_jid)) {
+ display_notification();
+ }
+ });
+
+ if (has_new_devices(account.bare_jid)) {
+ display_notification();
+ }
+ }
+
+ public bool has_new_devices(Jid jid) {
+ int identity_id = plugin.db.identity.get_id(account.id);
+ if (identity_id < 0) return false;
+
+ return plugin.db.identity_meta.get_new_devices(identity_id, jid.bare_jid.to_string()).count() > 0;
+ }
+
+ private void display_notification() {
+ Notification notification = new Notification(_("OMEMO trust decision required"));
+ notification.set_default_action_and_target_value("app.own-keys", new Variant.int32(account.id));
+ notification.set_body(_("Did you add a new device for account %s").printf(@"$(account.bare_jid.to_string())"));
+ plugin.app.send_notification(account.id.to_string()+"-new-device", notification);
+ }
+}
+}