Skip to content

Commit

Permalink
gui: persist SourceConversationWrapper for each source
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Jun 19, 2019
1 parent b015df3 commit 72076e2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import sys

from gettext import gettext as _
from typing import List
from typing import Dict, List # noqa: F401
from uuid import uuid4
from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QTimer, QSize, pyqtBoundSignal, QObject
from PyQt5.QtGui import QIcon, QPalette, QBrush, QColor, QFont, QLinearGradient
Expand Down Expand Up @@ -609,6 +609,8 @@ def __init__(self, parent: QObject):
self.layout.addWidget(self.source_list)
self.layout.addWidget(self.view_holder)

self.source_conversations = {} # type: Dict[Source, SourceConversationWrapper]

def setup(self, controller):
"""
Pass through the controller object to this widget.
Expand All @@ -631,7 +633,14 @@ def on_source_changed(self):
source = self.source_list.get_current_source()

if source:
conversation_wrapper = SourceConversationWrapper(source, self.controller)
# Try to get the SourceConversationWrapper from the persistent dict,
# else we create it.
try:
conversation_wrapper = self.source_conversations[source]
except KeyError:
conversation_wrapper = SourceConversationWrapper(source, self.controller)
self.source_conversations[source] = conversation_wrapper

self.set_conversation(conversation_wrapper)
else:
self.clear_conversation()
Expand Down

0 comments on commit 72076e2

Please sign in to comment.