Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh conversation view #142

Merged
merged 3 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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 @@ -402,6 +409,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([1, 2, 3])


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