Commit f40a8902 authored by Marcin Mielniczuk's avatar Marcin Mielniczuk

Address the review

parent 37587c40
Pipeline #4044 passed with stages
in 2 minutes and 54 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()
......
......@@ -353,6 +353,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)
......
......@@ -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:
......@@ -1147,9 +1141,10 @@ class ConversationTextview(GObject.GObject):
def print_encryption_status(self, iter_, additional_data):
details = self._get_encryption_details(additional_data)
enc_plugin = app.plugin_manager.encryption_plugins[self.encryption]
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 +1153,17 @@ 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.
current_trust = enc_plugin.get_fingerprint_trust(self.account, fingerprint)
fpr_trust = current_trust or 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