Skip to content

Commit

Permalink
emit timestamp whenever a sync has started
Browse files Browse the repository at this point in the history
Signed-off-by: Allie Crevier <allie@freedom.press>
  • Loading branch information
Allie Crevier committed Nov 23, 2021
1 parent 394bacd commit 46f8e91
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
9 changes: 5 additions & 4 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""
import html
import logging
from datetime import datetime
from gettext import gettext as _
from gettext import ngettext
from typing import Dict, List, Optional, Union # noqa: F401
Expand Down Expand Up @@ -248,8 +249,8 @@ def setup(self, controller: Controller) -> None:
self.controller.sync_started.connect(self._on_sync_started)
self.controller.sync_succeeded.connect(self._on_sync_succeeded)

@pyqtSlot()
def _on_sync_started(self) -> None:
@pyqtSlot(datetime)
def _on_sync_started(self, timestamp: datetime) -> None:
self.sync_animation = load_movie("sync_active.gif")
self.sync_animation.setScaledSize(QSize(24, 20))
self.setMovie(self.sync_animation)
Expand Down Expand Up @@ -3726,8 +3727,8 @@ def update_authentication_state(self, authenticated: bool) -> None:
else:
self.set_logged_out()

@pyqtSlot()
def _on_sync_started(self) -> None:
@pyqtSlot(datetime)
def _on_sync_started(self, timestamp: datetime) -> None:
try:
self.update_authentication_state(self.controller.is_authenticated)
if self.text_edit.hasFocus():
Expand Down
11 changes: 7 additions & 4 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import datetime
import functools
import inspect
import logging
import os
import uuid
from datetime import datetime
from gettext import gettext as _
from typing import Dict, List, Type, Union # noqa: F401

Expand Down Expand Up @@ -138,8 +138,11 @@ class Controller(QObject):

"""
This signal indicates when a sync has started.
Emits:
datetime: the time that the sync started
"""
sync_started = pyqtSignal()
sync_started = pyqtSignal(datetime)

"""
This signal indicates when a sync has successfully completed.
Expand Down Expand Up @@ -592,7 +595,7 @@ def get_last_sync(self): # type: ignore [no-untyped-def]
return None

def on_sync_started(self) -> None:
self.sync_started.emit()
self.sync_started.emit(datetime.utcnow())

def on_sync_success(self) -> None:
"""
Expand Down Expand Up @@ -1079,7 +1082,7 @@ def send_reply(self, source_uuid: str, reply_uuid: str, message: str) -> None:
)
draft_reply = db.DraftReply(
uuid=reply_uuid,
timestamp=datetime.datetime.utcnow(),
timestamp=datetime.utcnow(),
source_id=source.id,
journalist_id=self.authenticated_user.id,
file_counter=source.interaction_count,
Expand Down
8 changes: 4 additions & 4 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def test_SyncIcon__on_sync_started(mocker):
"""
sync_icon = SyncIcon()

sync_icon._on_sync_started()
sync_icon._on_sync_started(mocker.MagicMock())

file_path = sync_icon.sync_animation.fileName()
filename = file_path[file_path.rfind("/") + 1 :]
Expand Down Expand Up @@ -5056,14 +5056,14 @@ def test_ReplyBoxWidget_test_refocus_after_sync(mocker):
rb.text_edit.hasFocus = mocker.MagicMock(return_value=True)
rb.text_edit.setFocus = mocker.MagicMock()

rb._on_sync_started()
rb._on_sync_started(mocker.MagicMock())
assert rb.refocus_after_sync is True

rb._on_sync_succeeded()
rb.text_edit.setFocus.assert_called_once_with()

rb.text_edit.hasFocus.return_value = False
rb._on_sync_started()
rb._on_sync_started(mocker.MagicMock())
assert rb.refocus_after_sync is False


Expand All @@ -5079,7 +5079,7 @@ def pretend_source_was_deleted(self):

uas = mocker.patch.object(ReplyBoxWidget, "update_authentication_state")
uas.side_effect = pretend_source_was_deleted
rb._on_sync_started()
rb._on_sync_started(mocker.MagicMock())
rb._on_sync_succeeded()

exception_str = str(sqlalchemy.orm.exc.ObjectDeletedError(attributes.instance_state(s), None))
Expand Down

0 comments on commit 46f8e91

Please sign in to comment.