Commit 062388d7 authored by Marcin Mielniczuk's avatar Marcin Mielniczuk

Address the review.

parent 37587c40
Pipeline #4064 failed with stages
in 36 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,8 @@
import os
import time
from tempfile import TemporaryDirectory
from typing import Optional, Tuple
import logging
from gi.repository import Gtk
from gi.repository import Gdk
......@@ -76,6 +78,7 @@ from gajim.command_system.implementation import execute
if app.is_installed('GSPELL'):
from gi.repository import Gspell # pylint: disable=ungrouped-imports
log = logging.getLogger('gajim.chat_control_base')
################################################################################
class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
......@@ -353,6 +356,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 +989,22 @@ 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]
details = _get_encryption_details(additional_data)
if details:
_name, fingerprint, _trust = details
current_trust = enc_plugin.get_fingerprint_trust(self.account, jid, fingerprint)
log.debug("Trust query for JID: %s, fpr: %s, account: %s. Trust: %s" \
% (jid, fingerprint, self.account, 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 +1442,13 @@ class ScrolledWindow(Gtk.ScrolledWindow):
Gtk.PolicyType.AUTOMATIC)
return min_height, natural_height
# FIXME duplication from conversation_textview
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,7 +937,7 @@ 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
"""
......@@ -1017,7 +1011,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,11 +1139,11 @@ 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'
......@@ -1158,19 +1152,16 @@ class ConversationTextview(GObject.GObject):
name, fingerprint, trust = details
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
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