Skip to content

Commit

Permalink
Merge pull request #142 from freedomofpress/refresh-conversation-view
Browse files Browse the repository at this point in the history
Refresh conversation view
  • Loading branch information
heartsucker authored Nov 14, 2018
2 parents 84afd00 + b51777a commit ab45363
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ def setup(self):
self.sync_update = QTimer()
self.sync_update.timeout.connect(self.sync_api)
self.sync_update.start(1000 * 60 * 5) # every 5 minutes.
# Use a QTimer to update the current conversation view such
# that as downloads/decryption occur, the messages and replies
# populate the view.
self.conv_view_update = QTimer()
self.conv_view_update.timeout.connect(
self.update_conversation_view)
self.conv_view_update.start(1000 * 60 * 0.10) # every 6 seconds

event.listen(models.Submission, 'load', self.on_object_loaded)
event.listen(models.Submission, 'init', self.on_object_instantiated)
Expand Down Expand Up @@ -407,6 +414,16 @@ def update_sources(self):
self.gui.show_sources(sources)
self.update_sync()

def update_conversation_view(self):
"""
Updates the conversation view to reflect progress
of the download and decryption of messages and replies.
"""
# Redraw the conversation view if we have clicked on a source.
if self.gui.current_source:
self.session.refresh(self.gui.current_source)
self.gui.show_conversation_for(self.gui.current_source)

def on_update_star_complete(self, result):
"""
After we star or unstar a source, we should sync the API
Expand Down
28 changes: 28 additions & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,34 @@ def test_Client_update_sources(safe_tmpdir):
mock_gui.show_sources.assert_called_once_with(source_list)


def test_Client_update_conversation_view_current_source(safe_tmpdir):
"""
Ensure the UI displays the latest version of the messages/replies that
have been downloaded/decrypted in the current conversation view.
"""
mock_gui = mock.MagicMock()
mock_gui.current_source = 'teehee'
mock_gui.show_conversation_for = mock.MagicMock()
mock_session = mock.MagicMock()
cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
cl.update_conversation_view()
mock_gui.show_conversation_for.assert_called_once_with(
mock_gui.current_source)


def test_Client_update_conversation_view_no_current_source(safe_tmpdir):
"""
Ensure that if there is no current source (i.e. the user has not clicked
a source in the sidebar), the UI will not redraw the conversation view.
"""
mock_gui = mock.MagicMock()
mock_gui.current_source = None
mock_session = mock.MagicMock()
cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
cl.update_conversation_view()
mock_gui.show_conversation_for.assert_not_called()


def test_Client_unstars_a_source_if_starred(safe_tmpdir):
"""
Ensure that the client unstars a source if it is starred.
Expand Down

0 comments on commit ab45363

Please sign in to comment.