Address the review.

parent 37587c40
Pipeline #4056 failed with stages
in 53 seconds
......@@ -207,15 +207,6 @@ class ChatControl(ChatControlBase):
self.session = session
# Enable encryption if needed
fprs = {}
if self.encryption is not None:
enc_plugin = app.plugin_manager.encryption_plugins[self.encryption]
fprs = enc_plugin.get_fingerprints(acct,
self.contact.jid,
groupchat=False)
self.conv_textview.set_encryption(self.encryption, fprs)
self.no_autonegotiation = False
self.add_actions()
self.update_ui()
......
......@@ -26,6 +26,7 @@
import os
import time
from tempfile import TemporaryDirectory
from typing import Optional, Tuple
from gi.repository import Gtk
from gi.repository import Gdk
......@@ -353,6 +354,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.handlers[id_] = parent_win.window
self.encryption = self.get_encryption_state()
self.conv_textview.set_encryption(self.encryption)
# PluginSystem: adding GUI extension point for ChatControlBase
# instance object (also subclasses, eg. ChatControl or GroupchatControl)
......@@ -985,12 +987,23 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
if additional_data is None:
additional_data = AdditionalDataDict()
current_trust = None
if self.encryption:
enc_plugin = app.plugin_manager.encryption_plugins[self.encryption]
print("{}".format(additional_data))
details = _get_encryption_details(additional_data)
if details:
_name, fingerprint, _trust = details
print("CALLING {} {} {}".format(self.account, jid, fingerprint))
current_trust = enc_plugin.get_fingerprint_trust(self.account, jid, fingerprint)
print("GOT THE TRUST: {}".format(current_trust))
textview.print_conversation_line(text, kind, name, tim,
other_tags_for_name, other_tags_for_time, other_tags_for_text,
subject, old_kind, xhtml,
displaymarking=displaymarking, message_id=message_id,
correct_id=correct_id, additional_data=additional_data,
encrypted=encrypted)
encrypted=encrypted, current_trust=current_trust)
if restored:
return
......@@ -1428,3 +1441,12 @@ class ScrolledWindow(Gtk.ScrolledWindow):
Gtk.PolicyType.AUTOMATIC)
return min_height, natural_height
def _get_encryption_details(additional_data: AdditionalDataDict) -> Optional[Tuple[str, str, str]]:
name = additional_data.get_value('encrypted', 'name')
if name is None:
return None
fingerprint = additional_data.get_value('encrypted', 'fingerprint')
trust = additional_data.get_value('encrypted', 'trust')
return name, fingerprint, trust
......@@ -29,7 +29,7 @@ import queue
import urllib
import logging
from calendar import timegm
from typing import Optional, Tuple, Dict
from typing import Optional, Tuple
from gi.repository import Gtk
from gi.repository import Pango
......@@ -221,8 +221,7 @@ class ConversationTextview(GObject.GObject):
self.account = account
self._cursor_changed = False
self.last_time_printout = 0
self.encryption_enabled = False
self.fingerprint_trust = {} # type: Dict[str, Trust]
self.encryption = None
style = self.tv.get_style_context()
style.add_class('gajim-conversation-font')
......@@ -368,13 +367,8 @@ class ConversationTextview(GObject.GObject):
app.css_config.get_value('.gajim-highlight-message', StyleAttr.COLOR))
self.tv.update_tags()
def set_encryption(self,
encryption: Optional[str],
fingerprints: Optional[Dict[str, Trust]] = None
) -> None:
self.encryption_enabled = encryption is not None
if self.encryption_enabled and fingerprints is not None:
self.fingerprint_trust = fingerprints
def set_encryption(self, encryption: Optional[str]) -> None:
self.encryption = encryption
def scroll_to_end(self, force=False):
if self.autoscroll or force:
......@@ -943,10 +937,11 @@ class ConversationTextview(GObject.GObject):
other_tags_for_name=None, other_tags_for_time=None, other_tags_for_text=None,
subject=None, old_kind=None, xhtml=None, graphics=True,
displaymarking=None, message_id=None, correct_id=None, additional_data=None,
encrypted=None):
encrypted=None, current_trust: Optional[Trust] = None):
"""
Print 'chat' type messages
"""
log.error("ARGZ: %s" % name)
if additional_data is None:
additional_data = AdditionalDataDict()
buffer_ = self.tv.get_buffer()
......@@ -1017,7 +1012,7 @@ class ConversationTextview(GObject.GObject):
# print the encryption icon
if kind in ('incoming', 'outgoing'):
self.print_encryption_status(iter_, additional_data)
self.print_encryption_status(iter_, current_trust, additional_data)
# print the time stamp
self.print_time(text, kind, tim, direction_mark,
......@@ -1145,32 +1140,31 @@ class ConversationTextview(GObject.GObject):
if text.startswith('/me ') or text.startswith('/me\n'):
return kind
def print_encryption_status(self, iter_, additional_data):
def print_encryption_status(self, iter_, current_trust: Optional[Trust], additional_data: AdditionalDataDict) -> None:
details = self._get_encryption_details(additional_data)
if details is None:
# Message was not encrypted
if not self.encryption_enabled:
if self.encryption is None:
return
icon = 'channel-insecure-symbolic'
color = 'unencrypted-color'
tooltip = _('Not encrypted')
else:
name, fingerprint, trust = details
log.error("current: %s, old: %s" % (current_trust, trust))
tooltip = _('Encrypted (%s)') % (name)
# If a new fingerprint was added, but we may not have it in our dict
# until the textview is reloaded
if fingerprint in self.fingerprint_trust:
current_trust = self.fingerprint_trust[fingerprint]
icon, trust_tooltip, color = TRUST_SYMBOL_DATA[current_trust]
elif trust is None:
# First try to query the current trust.
# If unknown, fall back to the message original trust.
fpr_trust = current_trust if current_trust is not None else trust
log.error("chosen: %s" % fpr_trust)
if fpr_trust is not None:
icon, trust_tooltip, color = TRUST_SYMBOL_DATA[fpr_trust]
tooltip = '%s\n%s' % (tooltip, trust_tooltip)
else:
# The encryption plugin did not pass trust information
icon = 'channel-secure-symbolic'
color = 'encrypted-color'
else:
# Fallback to the original trust
icon, trust_tooltip, color = TRUST_SYMBOL_DATA[trust]
tooltip = '%s\n%s' % (tooltip, trust_tooltip)
if fingerprint is not None:
fingerprint = format_fingerprint(fingerprint)
......
......@@ -263,15 +263,6 @@ class GroupchatControl(ChatControlBase):
self.control_id)
# Encryption
fprs = {}
if self.encryption is not None:
enc_plugin = app.plugin_manager.encryption_plugins[self.encryption]
fprs = enc_plugin.get_fingerprints(acct,
self.contact.jid,
groupchat=True)
self.conv_textview.set_encryption(self.encryption, fprs)
self.lock_image = self.xml.get_object('lock_image')
self.authentication_button = self.xml.get_object(
'authentication_button')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment