aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src
diff options
context:
space:
mode:
authorSamuel Hand <samuel.hand@openmailbox.org>2018-07-11 13:20:02 +0100
committerSamuel Hand <samuel.hand@openmailbox.org>2018-07-11 13:20:02 +0100
commit62ad56af216410d51ebfd6fa542e936703465549 (patch)
tree5d3bb3538f65b1500a1bef69fda396e43484e5fc /plugins/omemo/src
parentacbc5710d083e69f887b0b5a15e48b7d10b48190 (diff)
downloaddino-62ad56af216410d51ebfd6fa542e936703465549.tar.gz
dino-62ad56af216410d51ebfd6fa542e936703465549.zip
Notify on a new own device
Diffstat (limited to 'plugins/omemo/src')
-rw-r--r--plugins/omemo/src/own_notifications.vala38
-rw-r--r--plugins/omemo/src/plugin.vala1
2 files changed, 39 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..df0c4740
--- /dev/null
+++ b/plugins/omemo/src/own_notifications.vala
@@ -0,0 +1,38 @@
+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) {
+ return plugin.db.identity_meta.with_address(account.id, jid.bare_jid.to_string()).with(plugin.db.identity_meta.trust_level, "=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).without_null(plugin.db.identity_meta.identity_key_public_base64).count() > 0;
+ }
+
+ private void display_notification() {
+ Notification notification = new Notification("Trust decision required");
+ notification.set_body(@"A new OMEMO device has been added for the account $(account.bare_jid)");
+ plugin.app.send_notification(account.id.to_string()+"-new-device", notification);
+ }
+}
+}
diff --git a/plugins/omemo/src/plugin.vala b/plugins/omemo/src/plugin.vala
index 79e6a5eb..b63ed3f2 100644
--- a/plugins/omemo/src/plugin.vala
+++ b/plugins/omemo/src/plugin.vala
@@ -44,6 +44,7 @@ public class Plugin : RootInterface, Object {
this.app.plugin_registry.register_notification_populator(device_notification_populator);
this.app.stream_interactor.module_manager.initialize_account_modules.connect((account, list) => {
list.add(new StreamModule());
+ new OwnNotifications(this, this.app.stream_interactor, account);
});
Manager.start(this.app.stream_interactor, db);