| ... |
... |
@@ -29,7 +29,7 @@ |
|
29
|
29
|
from gi.repository import Gtk
|
|
30
|
30
|
from nbxmpp.protocol import JID
|
|
31
|
31
|
from omemo_dr.const import OMEMOTrust
|
|
32
|
|
-from omemo_dr.identitykey import IdentityKey
|
|
|
32
|
+from omemo_dr.structs import IdentityInfo
|
|
33
|
33
|
|
|
34
|
34
|
from gajim.common import app
|
|
35
|
35
|
from gajim.common import ged
|
| ... |
... |
@@ -169,7 +169,7 @@ def _on_account_state(self, |
|
169
|
169
|
|
|
170
|
170
|
def _filter_func(self, row: KeyRow, _user_data: Any) -> bool:
|
|
171
|
171
|
search_text = self._ui.search.get_text()
|
|
172
|
|
- if search_text and search_text.lower() not in str(row.jid):
|
|
|
172
|
+ if search_text and search_text.lower() not in row.address:
|
|
173
|
173
|
return False
|
|
174
|
174
|
if self._ui.show_inactive_switch.get_active():
|
|
175
|
175
|
return True
|
| ... |
... |
@@ -177,7 +177,7 @@ def _filter_func(self, row: KeyRow, _user_data: Any) -> bool: |
|
177
|
177
|
|
|
178
|
178
|
@staticmethod
|
|
179
|
179
|
def _sort_func(row1: KeyRow, row2: KeyRow, _user_data: Any) -> int:
|
|
180
|
|
- result = locale.strcoll(str(row1.jid), str(row2.jid))
|
|
|
180
|
+ result = locale.strcoll(row1.address, row2.address)
|
|
181
|
181
|
if result != 0:
|
|
182
|
182
|
return result
|
|
183
|
183
|
|
| ... |
... |
@@ -192,46 +192,9 @@ def _on_search_changed(self, _entry: Gtk.SearchEntry) -> None: |
|
192
|
192
|
self._ui.list.invalidate_filter()
|
|
193
|
193
|
|
|
194
|
194
|
def _load_fingerprints(self, contact: types.ChatContactT) -> None:
|
|
195
|
|
- if contact.is_groupchat:
|
|
196
|
|
- members = list(self._omemo.backend.get_group_members(
|
|
197
|
|
- str(contact.jid)))
|
|
198
|
|
- sessions = self._omemo.backend.storage.get_sessions_from_jids(
|
|
199
|
|
- members)
|
|
200
|
|
- results = self._omemo.backend.storage.get_muc_fingerprints(members)
|
|
201
|
|
- else:
|
|
202
|
|
- sessions = self._omemo.backend.storage.get_sessions_from_jid(
|
|
203
|
|
- str(contact.jid))
|
|
204
|
|
- results = self._omemo.backend.storage.get_fingerprints(
|
|
205
|
|
- str(contact.jid))
|
|
206
|
|
-
|
|
207
|
|
- rows: dict[IdentityKey, KeyRow] = {}
|
|
208
|
|
- for result in results:
|
|
209
|
|
- rows[result.public_key] = KeyRow(contact,
|
|
210
|
|
- result.recipient_id,
|
|
211
|
|
- result.public_key,
|
|
212
|
|
- result.trust,
|
|
213
|
|
- result.timestamp)
|
|
214
|
|
-
|
|
215
|
|
- for item in sessions:
|
|
216
|
|
- if item.record.is_fresh():
|
|
217
|
|
- return
|
|
218
|
|
- identity_key = item.record.get_session_state().\
|
|
219
|
|
- get_remote_identity_key()
|
|
220
|
|
- identity_key = IdentityKey(identity_key.get_public_key())
|
|
221
|
|
- try:
|
|
222
|
|
- key_row = rows[identity_key]
|
|
223
|
|
- except KeyError:
|
|
224
|
|
- log.warning('Could not find session identitykey %s',
|
|
225
|
|
- item.device_id)
|
|
226
|
|
- self._omemo.backend.storage.delete_session(item.recipient_id,
|
|
227
|
|
- item.device_id)
|
|
228
|
|
- continue
|
|
229
|
|
-
|
|
230
|
|
- key_row.active = item.active
|
|
231
|
|
- key_row.device_id = item.device_id
|
|
232
|
|
-
|
|
233
|
|
- for row in rows.values():
|
|
234
|
|
- self._ui.list.add(row)
|
|
|
195
|
+ for identity_info in self._omemo.backend.get_identity_infos(
|
|
|
196
|
+ str(contact.jid)):
|
|
|
197
|
+ self._ui.list.add(KeyRow(contact, identity_info))
|
|
235
|
198
|
|
|
236
|
199
|
@staticmethod
|
|
237
|
200
|
def _get_qrcode(jid: JID,
|
| ... |
... |
@@ -277,20 +240,16 @@ def _on_manage_trust_clicked(self, _button: Gtk.Button) -> None: |
|
277
|
240
|
class KeyRow(Gtk.ListBoxRow):
|
|
278
|
241
|
def __init__(self,
|
|
279
|
242
|
contact: types.ChatContactT,
|
|
280
|
|
- jid: JID,
|
|
281
|
|
- identity_key: IdentityKey,
|
|
282
|
|
- trust: OMEMOTrust,
|
|
283
|
|
- last_seen: Optional[float]
|
|
|
243
|
+ identity_info: IdentityInfo
|
|
284
|
244
|
) -> None:
|
|
285
|
245
|
|
|
286
|
246
|
Gtk.ListBoxRow.__init__(self)
|
|
287
|
247
|
self.set_activatable(False)
|
|
288
|
248
|
|
|
289
|
|
- self._active = False
|
|
290
|
|
- self._device_id: Optional[int] = None
|
|
291
|
|
- self._identity_key = identity_key
|
|
292
|
|
- self.trust = trust
|
|
293
|
|
- self.jid = jid
|
|
|
249
|
+ self._contact = contact
|
|
|
250
|
+ self._address = str(self._contact.jid)
|
|
|
251
|
+ self._identity_info = identity_info
|
|
|
252
|
+ self._trust = identity_info.trust
|
|
294
|
253
|
|
|
295
|
254
|
client = app.get_client(contact.account)
|
|
296
|
255
|
self._omemo = client.get_module('OMEMO')
|
| ... |
... |
@@ -302,7 +261,7 @@ def __init__(self, |
|
302
|
261
|
grid.attach(self._trust_button, 1, 1, 1, 3)
|
|
303
|
262
|
|
|
304
|
263
|
if contact.is_groupchat:
|
|
305
|
|
- jid_label = Gtk.Label(label=str(jid))
|
|
|
264
|
+ jid_label = Gtk.Label(label=self._address)
|
|
306
|
265
|
jid_label.set_selectable(False)
|
|
307
|
266
|
jid_label.set_halign(Gtk.Align.START)
|
|
308
|
267
|
jid_label.set_valign(Gtk.Align.START)
|
| ... |
... |
@@ -311,7 +270,7 @@ def __init__(self, |
|
311
|
270
|
grid.attach(jid_label, 2, 1, 1, 1)
|
|
312
|
271
|
|
|
313
|
272
|
self.fingerprint = Gtk.Label(
|
|
314
|
|
- label=self._identity_key.get_fingerprint(formatted=True))
|
|
|
273
|
+ label=self._identity_info.public_key.get_fingerprint(formatted=True))
|
|
315
|
274
|
self.fingerprint.get_style_context().add_class('monospace')
|
|
316
|
275
|
self.fingerprint.get_style_context().add_class('small-label')
|
|
317
|
276
|
self.fingerprint.set_selectable(True)
|
| ... |
... |
@@ -320,9 +279,10 @@ def __init__(self, |
|
320
|
279
|
self.fingerprint.set_hexpand(True)
|
|
321
|
280
|
grid.attach(self.fingerprint, 2, 2, 1, 1)
|
|
322
|
281
|
|
|
323
|
|
- if last_seen is not None:
|
|
324
|
|
- last_seen_str = time.strftime(app.settings.get('date_time_format'),
|
|
325
|
|
- time.localtime(last_seen))
|
|
|
282
|
+ if self._identity_info.last_seen is not None:
|
|
|
283
|
+ last_seen_str = time.strftime(
|
|
|
284
|
+ app.settings.get('date_time_format'),
|
|
|
285
|
+ time.localtime(self._identity_info.last_seen))
|
|
326
|
286
|
else:
|
|
327
|
287
|
last_seen_str = _('Never')
|
|
328
|
288
|
last_seen_label = Gtk.Label(label=_('Last seen: %s') % last_seen_str)
|
| ... |
... |
@@ -344,11 +304,13 @@ def _on_destroy(self, *args: Any) -> None: |
|
344
|
304
|
def delete_fingerprint(self, *args: Any) -> None:
|
|
345
|
305
|
|
|
346
|
306
|
def _remove():
|
|
347
|
|
- self._omemo.backend.remove_device(str(self.jid), self.device_id)
|
|
348
|
|
- self._omemo.backend.storage.delete_session(
|
|
349
|
|
- str(self.jid), self.device_id)
|
|
|
307
|
+ device_id = self._identity_info.device_id
|
|
|
308
|
+
|
|
|
309
|
+ self._omemo.backend.remove_device(self._address, device_id)
|
|
|
310
|
+ self._omemo.backend.storage.delete_session(self._address,
|
|
|
311
|
+ device_id)
|
|
350
|
312
|
self._omemo.backend.storage.delete_identity(
|
|
351
|
|
- str(self.jid), self._identity_key)
|
|
|
313
|
+ self._address, self._identity_info.public_key)
|
|
352
|
314
|
|
|
353
|
315
|
listbox = cast(Gtk.ListBox, self.get_parent())
|
|
354
|
316
|
listbox.remove(self)
|
| ... |
... |
@@ -364,37 +326,28 @@ def _remove(): |
|
364
|
326
|
callback=_remove)],
|
|
365
|
327
|
transient_for=cast(Gtk.Window, self.get_toplevel())).show()
|
|
366
|
328
|
|
|
367
|
|
- def set_trust(self) -> None:
|
|
368
|
|
- icon_name, tooltip, css_class = TRUST_DATA[self.trust]
|
|
|
329
|
+ def set_trust(self, trust: OMEMOTrust) -> None:
|
|
|
330
|
+ self._trust = trust
|
|
|
331
|
+ icon_name, tooltip, css_class = TRUST_DATA[trust]
|
|
369
|
332
|
image = cast(Gtk.Image, self._trust_button.get_child())
|
|
370
|
333
|
image.set_from_icon_name(icon_name, Gtk.IconSize.MENU)
|
|
371
|
334
|
image.get_style_context().add_class(css_class)
|
|
372
|
335
|
image.set_tooltip_text(tooltip)
|
|
373
|
336
|
|
|
374
|
337
|
self._omemo.backend.storage.set_trust(
|
|
375
|
|
- str(self.jid), self._identity_key, self.trust)
|
|
|
338
|
+ self._address, self._identity_info.public_key, trust)
|
|
376
|
339
|
|
|
377
|
340
|
@property
|
|
378
|
|
- def active(self) -> bool:
|
|
379
|
|
- return self._active
|
|
380
|
|
-
|
|
381
|
|
- @active.setter
|
|
382
|
|
- def active(self, active: bool) -> None:
|
|
383
|
|
- context = self.fingerprint.get_style_context()
|
|
384
|
|
- self._active = bool(active)
|
|
385
|
|
- if self._active:
|
|
386
|
|
- context.remove_class('omemo-inactive-color')
|
|
387
|
|
- else:
|
|
388
|
|
- context.add_class('omemo-inactive-color')
|
|
389
|
|
- self._trust_button.update()
|
|
|
341
|
+ def trust(self) -> OMEMOTrust:
|
|
|
342
|
+ return self._trust
|
|
390
|
343
|
|
|
391
|
344
|
@property
|
|
392
|
|
- def device_id(self) -> Optional[int]:
|
|
393
|
|
- return self._device_id
|
|
|
345
|
+ def active(self) -> bool:
|
|
|
346
|
+ return self._identity_info.active
|
|
394
|
347
|
|
|
395
|
|
- @device_id.setter
|
|
396
|
|
- def device_id(self, device_id: int) -> None:
|
|
397
|
|
- self._device_id = device_id
|
|
|
348
|
+ @property
|
|
|
349
|
+ def address(self) -> str:
|
|
|
350
|
+ return self._address
|
|
398
|
351
|
|
|
399
|
352
|
|
|
400
|
353
|
class TrustButton(Gtk.MenuButton):
|
| ... |
... |
@@ -444,8 +397,7 @@ def _activated(self, _listbox: Gtk.ListBox, row: MenuOption) -> None: |
|
444
|
397
|
if row.type_ is None:
|
|
445
|
398
|
self._row.delete_fingerprint()
|
|
446
|
399
|
else:
|
|
447
|
|
- self._row.trust = row.type_
|
|
448
|
|
- self._row.set_trust()
|
|
|
400
|
+ self._row.set_trust(row.type_)
|
|
449
|
401
|
trust_button = cast(TrustButton, self.get_relative_to())
|
|
450
|
402
|
trust_button.update()
|
|
451
|
403
|
self.update()
|