Commit e42c26b8 authored by Tijmen de Mes's avatar Tijmen de Mes

Store pending decryted messages per session

parent aac47bb6
...@@ -671,6 +671,7 @@ class ChatWidget(base_class, ui_class): ...@@ -671,6 +671,7 @@ class ChatWidget(base_class, ui_class):
self.session = session self.session = session
self.history_loaded = False self.history_loaded = False
self.timestamp_rendered_messages = [] self.timestamp_rendered_messages = []
self.pending_decryption = []
if session is not None: if session is not None:
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.add_observer(ObserverWeakrefProxy(self), sender=session.blink_session) notification_center.add_observer(ObserverWeakrefProxy(self), sender=session.blink_session)
...@@ -1619,7 +1620,6 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -1619,7 +1620,6 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
self.pending_displayed_notifications = {} self.pending_displayed_notifications = {}
self.render_after_load = [] self.render_after_load = []
self.pending_decryption = []
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.add_observer(self, name='SIPApplicationDidStart') notification_center.add_observer(self, name='SIPApplicationDidStart')
notification_center.add_observer(self, name='BlinkSessionNewIncoming') notification_center.add_observer(self, name='BlinkSessionNewIncoming')
...@@ -2408,7 +2408,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2408,7 +2408,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
content = f'<img src={session.chat_widget.encrypted_icon.filename} class="inline-message-icon">Encrypted Message' content = f'<img src={session.chat_widget.encrypted_icon.filename} class="inline-message-icon">Encrypted Message'
content = HtmlProcessor.autolink(content) content = HtmlProcessor.autolink(content)
encrypted = True encrypted = True
self.pending_decryption.append((message)) session.chat_widget.pending_decryption.append((message))
else: else:
content = message.content content = message.content
content = HtmlProcessor.autolink(content if message.content_type == 'text/html' else QTextDocument(content).toHtml()) content = HtmlProcessor.autolink(content if message.content_type == 'text/html' else QTextDocument(content).toHtml())
...@@ -2428,8 +2428,8 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2428,8 +2428,8 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
account = None account = None
sender = ChatSender(message.sender.display_name or session.name, uri, session.icon.filename) sender = ChatSender(message.sender.display_name or session.name, uri, session.icon.filename)
if session.chat_widget.history_loaded: if session.chat_widget.history_loaded:
if message in self.pending_decryption and not encrypted: if message in session.chat_widget.pending_decryption and not encrypted:
self.pending_decryption.remove(message) session.chat_widget.pending_decryption.remove(message)
session.chat_widget.update_message_text(message.id, content) session.chat_widget.update_message_text(message.id, content)
else: else:
session.chat_widget.add_message(ChatMessage(content, sender, direction, id=message.id, timestamp=message.timestamp, history=history)) session.chat_widget.add_message(ChatMessage(content, sender, direction, id=message.id, timestamp=message.timestamp, history=history))
...@@ -2505,8 +2505,8 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2505,8 +2505,8 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
if isinstance(message, BlinkMessage): if isinstance(message, BlinkMessage):
return return
if message in self.pending_decryption: if message in session.chat_widget.pending_decryption:
self.pending_decryption.remove(message) session.chat_widget.pending_decryption.remove(message)
content = message.content content = message.content
content = HtmlProcessor.autolink(content if message.content_type == 'text/html' else QTextDocument(content).toHtml()) content = HtmlProcessor.autolink(content if message.content_type == 'text/html' else QTextDocument(content).toHtml())
session.chat_widget.update_message_text(message.message_id, content) session.chat_widget.update_message_text(message.message_id, content)
...@@ -2534,9 +2534,13 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2534,9 +2534,13 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
def _NH_MessageStreamPGPKeysDidLoad(self, notification): def _NH_MessageStreamPGPKeysDidLoad(self, notification):
stream = notification.sender stream = notification.sender
blink_session = stream.blink_session blink_session = stream.blink_session
session = blink_session.items.chat
if session is None:
return
stream = blink_session.fake_streams.get('messages') stream = blink_session.fake_streams.get('messages')
for message in self.pending_decryption: for message in session.chat_widget.pending_decryption:
if isinstance(message, BlinkMessage): if isinstance(message, BlinkMessage):
continue continue
if stream and stream.can_decrypt: if stream and stream.can_decrypt:
...@@ -2560,7 +2564,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2560,7 +2564,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
content = f'<img src={session.chat_widget.encrypted_icon.filename} class="inline-message-icon">Encrypted Message' content = f'<img src={session.chat_widget.encrypted_icon.filename} class="inline-message-icon">Encrypted Message'
content = HtmlProcessor.autolink(content) content = HtmlProcessor.autolink(content)
encrypted = True encrypted = True
self.pending_decryption.append((message)) session.chat_widget.pending_decryption.append((message))
stream = blink_session.fake_streams.get('messages') stream = blink_session.fake_streams.get('messages')
if stream and stream.can_decrypt: if stream and stream.can_decrypt:
stream.decrypt(message) stream.decrypt(message)
......
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