diff options
author | Marvin W <git@larma.de> | 2018-06-19 12:52:00 +0200 |
---|---|---|
committer | Samuel Hand <samuel.hand@openmailbox.org> | 2018-06-26 15:42:02 +0100 |
commit | 638d81d67ecd6c7c8be7fd67aeaf15d16486f8e9 (patch) | |
tree | ea1cf3c5f28477bc928777ea0379d2616170fd0b /plugins/omemo | |
parent | 2a8352c5439129798b5141ec021b3b9405840a8a (diff) | |
download | dino-638d81d67ecd6c7c8be7fd67aeaf15d16486f8e9.tar.gz dino-638d81d67ecd6c7c8be7fd67aeaf15d16486f8e9.zip |
More cleanup and database modifications
Diffstat (limited to 'plugins/omemo')
-rw-r--r-- | plugins/omemo/data/contact_details_dialog.ui | 40 | ||||
-rw-r--r-- | plugins/omemo/src/account_settings_dialog.vala | 2 | ||||
-rw-r--r-- | plugins/omemo/src/contact_details_dialog.vala | 56 | ||||
-rw-r--r-- | plugins/omemo/src/contact_details_provider.vala | 5 | ||||
-rw-r--r-- | plugins/omemo/src/database.vala | 4 | ||||
-rw-r--r-- | plugins/omemo/src/device_notification_populator.vala | 34 | ||||
-rw-r--r-- | plugins/omemo/src/manager.vala | 31 | ||||
-rw-r--r-- | plugins/omemo/src/plugin.vala | 2 | ||||
-rw-r--r-- | plugins/omemo/src/stream_module.vala | 14 |
9 files changed, 137 insertions, 51 deletions
diff --git a/plugins/omemo/data/contact_details_dialog.ui b/plugins/omemo/data/contact_details_dialog.ui index e26f79af..ceac2179 100644 --- a/plugins/omemo/data/contact_details_dialog.ui +++ b/plugins/omemo/data/contact_details_dialog.ui @@ -50,6 +50,46 @@ </object> </child> <child> + <object class="GtkBox" id="fingerprints_verified_label"> + <property name="margin-top">12</property> + <property name="orientation">horizontal</property> + <property name="visible">False</property> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="halign">start</property> + <property name="valign">center</property> + <property name="hexpand">True</property> + <property name="label" translatable="yes">Verified Devices</property> + <property name="margin-bottom">2</property> + <attributes> + <attribute name="weight" value="PANGO_WEIGHT_BOLD"/> + </attributes> + </object> + </child> + </object> + </child> + <child> + <object class="GtkFrame" id="fingerprints_verified_container"> + <property name="visible">False</property> + <property name="margin-bottom">18</property> + <child> + <object class="GtkScrolledWindow"> + <property name="hscrollbar_policy">never</property> + <property name="vscrollbar_policy">automatic</property> + <property name="visible">True</property> + <property name="propagate_natural_height">True</property> + <child> + <object class="GtkGrid" id="fingerprints_verified"> + <property name="visible">True</property> + <property name="vexpand">True</property> + </object> + </child> + </object> + </child> + </object> + </child> + <child> <object class="GtkBox"> <property name="margin-top">12</property> <property name="orientation">horizontal</property> diff --git a/plugins/omemo/src/account_settings_dialog.vala b/plugins/omemo/src/account_settings_dialog.vala index f0262c31..76357dbb 100644 --- a/plugins/omemo/src/account_settings_dialog.vala +++ b/plugins/omemo/src/account_settings_dialog.vala @@ -26,7 +26,7 @@ public class AccountSettingsDialog : Gtk.Dialog { int own_id = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.device_id]; int i = 0; - foreach (Row row in plugin.db.identity_meta.with_address(account.bare_jid.to_string())) { + foreach (Row row in plugin.db.identity_meta.with_address(account.id, account.bare_jid.to_string())) { if (row[plugin.db.identity_meta.device_id] == own_id) continue; if (i == 0) { other_list.foreach((widget) => { widget.destroy(); }); diff --git a/plugins/omemo/src/contact_details_dialog.vala b/plugins/omemo/src/contact_details_dialog.vala index 3ee6380a..6bf2c83e 100644 --- a/plugins/omemo/src/contact_details_dialog.vala +++ b/plugins/omemo/src/contact_details_dialog.vala @@ -17,6 +17,9 @@ public class ContactDetailsDialog : Gtk.Dialog { [GtkChild] private Box fingerprints_prompt_label; [GtkChild] private Frame fingerprints_prompt_container; [GtkChild] private Grid fingerprints_prompt; + [GtkChild] private Box fingerprints_verified_label; + [GtkChild] private Frame fingerprints_verified_container; + [GtkChild] private Grid fingerprints_verified; private void set_device_trust(Row device, bool trust) { @@ -57,9 +60,10 @@ public class ContactDetailsDialog : Gtk.Dialog { this.jid = jid; int i = 0; - foreach (Row device in plugin.db.identity_meta.with_address(jid.to_string()).with(plugin.db.identity_meta.trusted_identity, "!=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).with(plugin.db.identity_meta.identity_id, "=", account.id)) { - if(device[plugin.db.identity_meta.identity_key_public_base64] == null) + foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).with(plugin.db.identity_meta.trusted_identity, "!=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).with(plugin.db.identity_meta.trusted_identity, "!=", Database.IdentityMetaTable.TrustLevel.VERIFIED)) { + if (device[plugin.db.identity_meta.identity_key_public_base64] == null) { continue; + } add_fingerprint(device, i, (Database.IdentityMetaTable.TrustLevel) device[plugin.db.identity_meta.trusted_identity]); i++; @@ -67,9 +71,10 @@ public class ContactDetailsDialog : Gtk.Dialog { } int j = 0; - foreach (Row device in plugin.db.identity_meta.with_address(jid.to_string()).with(plugin.db.identity_meta.trusted_identity, "=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).with(plugin.db.identity_meta.identity_id, "=", account.id)) { - if(device[plugin.db.identity_meta.identity_key_public_base64] == null) + foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).with(plugin.db.identity_meta.trusted_identity, "=", Database.IdentityMetaTable.TrustLevel.UNKNOWN)) { + if (device[plugin.db.identity_meta.identity_key_public_base64] == null) { continue; + } string res = fingerprint_markup(fingerprint_from_base64(device[plugin.db.identity_meta.identity_key_public_base64])); Label lbl = new Label(res) @@ -90,8 +95,9 @@ public class ContactDetailsDialog : Gtk.Dialog { add_fingerprint(device, i, Database.IdentityMetaTable.TrustLevel.TRUSTED); i++; - if(j == 0) + if (j == 0) { fingerprints_prompt.attach(new Label("No more new devices") { visible = true, valign = Align.CENTER, halign = Align.CENTER, margin = 8, hexpand = true }, 0, 0); + } }); Button no = new Button() { visible = true, valign = Align.CENTER, hexpand = true}; @@ -107,8 +113,9 @@ public class ContactDetailsDialog : Gtk.Dialog { add_fingerprint(device, i, Database.IdentityMetaTable.TrustLevel.UNTRUSTED); i++; - if(j == 0) + if (j == 0) { fingerprints_prompt.attach(new Label("No more new devices") { visible = true, valign = Align.CENTER, halign = Align.CENTER, margin = 8, hexpand = true }, 0, 0); + } }); box.pack_start(yes); @@ -125,6 +132,43 @@ public class ContactDetailsDialog : Gtk.Dialog { fingerprints_prompt_container.visible = true; } + int k = 0; + foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).without_null(plugin.db.identity_meta.identity_key_public_base64).with(plugin.db.identity_meta.trusted_identity, "=", Database.IdentityMetaTable.TrustLevel.VERIFIED)) { + string res = fingerprint_markup(fingerprint_from_base64(device[plugin.db.identity_meta.identity_key_public_base64])); + Label lbl = new Label(res) + { use_markup=true, justify=Justification.RIGHT, visible=true, margin = 8, halign = Align.START }; + + Box box = new Box(Gtk.Orientation.HORIZONTAL, 0) { visible = true, valign = Align.CENTER, hexpand = true, margin = 8 }; + + Button no = new Button() { visible = true, valign = Align.CENTER, halign = Align.END, hexpand = false }; + no.image = new Image.from_icon_name("list-remove-symbolic", IconSize.BUTTON); + + no.clicked.connect(() => { + set_device_trust(device, false); + + fingerprints_verified.remove(no); + fingerprints_verified.remove(lbl); + k--; + + add_fingerprint(device, i, Database.IdentityMetaTable.TrustLevel.UNTRUSTED); + i++; + + if (k == 0) { + fingerprints_verified.attach(new Label("No more new devices") { visible = true, valign = Align.CENTER, halign = Align.CENTER, margin = 8, hexpand = true }, 0, 0); + } + }); + + box.pack_end(no); + + fingerprints_verified.attach(lbl, 0, k); + fingerprints_verified.attach(box, 1, k); + k++; + } + + if( k > 0 ){ + fingerprints_verified_label.visible = true; + fingerprints_verified_container.visible = true; + } } } diff --git a/plugins/omemo/src/contact_details_provider.vala b/plugins/omemo/src/contact_details_provider.vala index 2c6c4944..1cf635c2 100644 --- a/plugins/omemo/src/contact_details_provider.vala +++ b/plugins/omemo/src/contact_details_provider.vala @@ -18,7 +18,7 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object { if (conversation.type_ == Conversation.Type.CHAT && type == WidgetType.GTK) { int i = 0; - foreach (Row row in plugin.db.identity_meta.with_address(conversation.counterpart.to_string())) { + foreach (Row row in plugin.db.identity_meta.with_address(conversation.account.id, conversation.counterpart.to_string())) { if (row[plugin.db.identity_meta.identity_key_public_base64] != null) { i++; } @@ -34,6 +34,9 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object { btn.activate(); ContactDetailsDialog dialog = new ContactDetailsDialog(plugin, conversation.account, conversation.counterpart); dialog.set_transient_for((Window) btn.get_toplevel()); + dialog.response.connect((response_type) => { + plugin.device_notification_populator.should_hide(); + }); dialog.present(); }); diff --git a/plugins/omemo/src/database.vala b/plugins/omemo/src/database.vala index 48fddde2..3f24e9f6 100644 --- a/plugins/omemo/src/database.vala +++ b/plugins/omemo/src/database.vala @@ -37,8 +37,8 @@ public class Database : Qlite.Database { index("identity_meta_list_idx", {identity_id, address_name}); } - public QueryBuilder with_address(string address_name) { - return select().with(this.address_name, "=", address_name); + public QueryBuilder with_address(int identity_id, string address_name) { + return select().with(this.identity_id, "=", identity_id).with(this.address_name, "=", address_name); } public void insert_device_list(int32 identity_id, string address_name, ArrayList<int32> devices) { diff --git a/plugins/omemo/src/device_notification_populator.vala b/plugins/omemo/src/device_notification_populator.vala index 6b3e668b..8549e052 100644 --- a/plugins/omemo/src/device_notification_populator.vala +++ b/plugins/omemo/src/device_notification_populator.vala @@ -4,14 +4,14 @@ using Gtk; namespace Dino.Plugins.Omemo { -public class DeviceNotificationPopulator : ConversationItemPopulator, Object { +public class DeviceNotificationPopulator : NotificationPopulator, Object { public string id { get { return "device_notification"; } } private StreamInteractor? stream_interactor; private Plugin plugin; private Conversation? current_conversation; - private ConversationItemCollection? item_collection; + private NotificationCollection? notification_collection; private ConversationNotification notification; public DeviceNotificationPopulator(Plugin plugin, StreamInteractor stream_interactor) { @@ -20,37 +20,37 @@ public class DeviceNotificationPopulator : ConversationItemPopulator, Object { } public bool has_new_devices(Jid jid) { - return plugin.db.identity_meta.with_address(jid.bare_jid.to_string()).with(plugin.db.identity_meta.identity_id, "=", current_conversation.account.id).with_null(plugin.db.identity_meta.trusted_identity).without_null(plugin.db.identity_meta.identity_key_public_base64).count() > 0; + return plugin.db.identity_meta.with_address(current_conversation.account.id, jid.bare_jid.to_string()).with(plugin.db.identity_meta.trusted_identity, "=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).without_null(plugin.db.identity_meta.identity_key_public_base64).count() > 0; } - public void init(Conversation conversation, ConversationItemCollection item_collection, Plugins.WidgetType type) { + public void init(Conversation conversation, NotificationCollection notification_collection, Plugins.WidgetType type) { current_conversation = conversation; - this.item_collection = item_collection; + this.notification_collection = notification_collection; stream_interactor.module_manager.get_module(conversation.account, StreamModule.IDENTITY).device_list_loaded.connect((jid) => { - if(jid == conversation.counterpart && has_new_devices(conversation.counterpart) && conversation.type_ == Conversation.Type.CHAT) + if (jid == conversation.counterpart && has_new_devices(conversation.counterpart) && conversation.type_ == Conversation.Type.CHAT) { display_notification(); + } }); - if (has_new_devices(conversation.counterpart) && conversation.type_ == Conversation.Type.CHAT) - display_notification(); + if (has_new_devices(conversation.counterpart) && conversation.type_ == Conversation.Type.CHAT) { + display_notification(); + } } - public void close(Conversation conversation) { } - - public void populate_timestamp(Conversation conversation, DateTime from, DateTime to) { } - - public void populate_between_widgets(Conversation conversation, DateTime from, DateTime to) { } + public void close(Conversation conversation) { + notification = null; + } private void display_notification() { if(notification == null) { notification = new ConversationNotification(plugin, current_conversation.account, current_conversation.counterpart); notification.should_hide.connect(should_hide); - item_collection.add_meta_notification(notification); + notification_collection.add_meta_notification(notification); } } - private void should_hide() { - if (!has_new_devices(current_conversation.counterpart)){ - item_collection.remove_meta_notification(notification); + public void should_hide() { + if (!has_new_devices(current_conversation.counterpart) && notification != null){ + notification_collection.remove_meta_notification(notification); notification = null; } } diff --git a/plugins/omemo/src/manager.vala b/plugins/omemo/src/manager.vala index dbb016a4..938c8631 100644 --- a/plugins/omemo/src/manager.vala +++ b/plugins/omemo/src/manager.vala @@ -181,7 +181,7 @@ public class Manager : StreamInteractionModule, Object { ArrayList<int32> device_list = module.get_device_list(jid); db.identity_meta.insert_device_list(account.id, jid.bare_jid.to_string(), device_list); int inc = 0; - foreach (Row row in db.identity_meta.with_address(jid.bare_jid.to_string()).with_null(db.identity_meta.identity_key_public_base64)) { + foreach (Row row in db.identity_meta.with_address(account.id, jid.bare_jid.to_string()).with_null(db.identity_meta.identity_key_public_base64)) { module.fetch_bundle(stream, Jid.parse(row[db.identity_meta.address_name]), row[db.identity_meta.device_id]); inc++; } @@ -189,32 +189,26 @@ public class Manager : StreamInteractionModule, Object { if (Plugin.DEBUG) print(@"OMEMO: new bundles $inc/$(device_list.size) for $jid\n"); } - if(db.trust.select().with(db.trust.identity_id, "=", account.id).with(db.trust.address_name, " =", jid.bare_jid.to_string()).count() == 0) - db.trust.insert().value(db.trust.identity_id, account.id).value(db.trust.address_name, jid .bare_jid.to_string()).value(db.trust.blind_trust, true).perform(); - + if (db.trust.select().with(db.trust.identity_id, "=", account.id).with(db.trust.address_name, "=", jid.bare_jid.to_string()).count() == 0) { + db.trust.insert().value(db.trust.identity_id, account.id).value(db.trust.address_name, jid.bare_jid.to_string()).value(db.trust.blind_trust, true).perform(); + } } public void on_bundle_fetched(Account account, Jid jid, int32 device_id, Bundle bundle) { bool blind_trust = db.trust.get_blind_trust(account.id, jid.bare_jid.to_string()); - bool untrust = !(blind_trust || db.identity_meta.with_address(jid.bare_jid.to_string()) - .with(db.identity_meta.identity_id, "=", account.id) + bool untrust = !(blind_trust || db.identity_meta.with_address(account.id, jid.bare_jid.to_string()) .with(db.identity_meta.device_id, "=", device_id) .with(db.identity_meta.identity_key_public_base64, "=", Base64.encode(bundle.identity_key.serialize())) - .count() > 0); - - Database.IdentityMetaTable.TrustLevel trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN; - foreach(Row row in db.identity_meta.with_address(jid.bare_jid.to_string()) - .with(db.identity_meta.identity_id, "=", account.id) - .with(db.identity_meta.device_id, "=", device_id)) { - trusted = (Database.IdentityMetaTable.TrustLevel) row[db.identity_meta.trusted_identity]; - break; - } + .single().row().is_present()); - if(untrust) + Database.IdentityMetaTable.TrustLevel trusted = (Database.IdentityMetaTable.TrustLevel) db.identity_meta.with_address(account.id, jid.bare_jid.to_string()).with(db.identity_meta.device_id, "=", device_id).single()[db.identity_meta.trusted_identity, Database.IdentityMetaTable.TrustLevel.UNKNOWN]; + + if(untrust) { trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN; - else if (blind_trust && trusted == Database.IdentityMetaTable.TrustLevel.UNKNOWN) + } else if (blind_trust && trusted == Database.IdentityMetaTable.TrustLevel.UNKNOWN) { trusted = Database.IdentityMetaTable.TrustLevel.TRUSTED; + } db.identity_meta.insert_device_bundle(account.id, jid.bare_jid.to_string(), device_id, bundle, trusted); @@ -234,8 +228,9 @@ public class Manager : StreamInteractionModule, Object { if (trusted != Database.IdentityMetaTable.TrustLevel.TRUSTED && trusted != Database.IdentityMetaTable.TrustLevel.VERIFIED) { module.untrust_device(jid, device_id); } else { - if(account.bare_jid.equals(jid) || (msg.counterpart != null && msg.counterpart.equals_bare(jid))) + if(account.bare_jid.equals(jid) || (msg.counterpart != null && msg.counterpart.equals_bare(jid))) { session_created = module.start_session(stream, jid, device_id, bundle); + } } if (account.bare_jid.equals(jid) && session_created) { state.waiting_own_sessions--; diff --git a/plugins/omemo/src/plugin.vala b/plugins/omemo/src/plugin.vala index 2da35934..79e6a5eb 100644 --- a/plugins/omemo/src/plugin.vala +++ b/plugins/omemo/src/plugin.vala @@ -41,7 +41,7 @@ public class Plugin : RootInterface, Object { this.app.plugin_registry.register_encryption_list_entry(list_entry); this.app.plugin_registry.register_account_settings_entry(settings_entry); this.app.plugin_registry.register_contact_details_entry(contact_details_provider); - this.app.plugin_registry.register_conversation_item_populator(device_notification_populator); + 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()); }); diff --git a/plugins/omemo/src/stream_module.vala b/plugins/omemo/src/stream_module.vala index 83a3dd54..2c792a2f 100644 --- a/plugins/omemo/src/stream_module.vala +++ b/plugins/omemo/src/stream_module.vala @@ -102,20 +102,24 @@ public class StreamModule : XmppStreamModule { } public void untrust_device(Jid jid, int device_id) { - if(device_lists.has_key(jid) && device_lists[jid].contains(device_id)) + if (device_lists.has_key(jid) && device_lists[jid].contains(device_id)) { device_lists[jid].remove(device_id); - if(store.contains_session(new Address(jid.bare_jid.to_string(), device_id))) + } + if (store.contains_session(new Address(jid.bare_jid.to_string(), device_id))) { store.delete_session(new Address(jid.bare_jid.to_string(), device_id)); + } } public void trust_device(Jid jid, int device_id) { - if(is_ignored_device(jid, device_id)){ + if (is_ignored_device(jid, device_id)){ ignored_devices[jid].remove(device_id); } - if(!device_lists.has_key(jid)) + if (!device_lists.has_key(jid)) { device_lists[jid] = new ArrayList<int32>(); - if(!device_lists[jid].contains(device_id)) + } + if (!device_lists[jid].contains(device_id)) { device_lists[jid].add(device_id); + } } private StanzaNode create_encrypted_key(uint8[] key, Address address) throws GLib.Error { |