Skip to content

Commit d6bba42

Browse files
WIP ensure sync updates state
1 parent 9ebdbc7 commit d6bba42

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

securedrop_client/api_jobs/sync.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ class MetadataSyncJob(ApiJob):
1717

1818
NUMBER_OF_TIMES_TO_RETRY_AN_API_CALL = 2
1919

20-
def __init__(self, data_dir: str) -> None:
20+
def __init__(self, data_dir: str, state: Any) -> None:
2121
super().__init__(remaining_attempts=self.NUMBER_OF_TIMES_TO_RETRY_AN_API_CALL)
2222
self.data_dir = data_dir
23+
self._state = state
2324

2425
def call_api(self, api_client: API, session: Session) -> Any:
2526
"""
@@ -40,6 +41,16 @@ def call_api(self, api_client: API, session: Session) -> Any:
4041
sources, submissions, replies = get_remote_data(api_client)
4142

4243
update_local_storage(session, sources, submissions, replies, self.data_dir)
44+
45+
for source in sources:
46+
source_id = source.uuid
47+
files = []
48+
for submission in submissions:
49+
if submission.source_id == source_id and submission.is_file():
50+
files.append(submission.uuid)
51+
conversation_id = source_id
52+
self._state.upsert_conversation(conversation_id, files)
53+
4354
user = api_client.get_current_user()
4455
if "uuid" in user and "username" in user and "first_name" in user and "last_name" in user:
4556
create_or_update_user(

securedrop_client/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def start_app(args, qt_args) -> NoReturn: # type: ignore [no-untyped-def]
220220
gui_state_writer = state.Writer(gui_state)
221221
gui = Window(gui_state)
222222
gui.source_selection_changed.connect(gui_state_writer.set_selected_conversation)
223+
gui.conversation_updated.connect(gui_state_writer.upsert_conversation)
223224

224225
controller = Controller(
225226
"http://localhost:8081/",

securedrop_client/gui/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Window(QMainWindow):
4646
icon = "icon.png"
4747

4848
source_selection_changed = pyqtSignal(str)
49+
# conversation_updated = pyqtSignal(str, str) # consersation_id, pickled list of files
4950

5051
def __init__(self, state: Any) -> None:
5152
"""

securedrop_client/logic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def __init__( # type: ignore [no-untyped-def]
374374
self.data_dir = os.path.join(self.home, "data")
375375

376376
# Background sync to keep client up-to-date with server changes
377-
self.api_sync = ApiSync(self.api, self.session_maker, self.gpg, self.data_dir)
377+
self.api_sync = ApiSync(self.api, self.session_maker, self.gpg, self.data_dir, state)
378378
self.api_sync.sync_started.connect(self.on_sync_started, type=Qt.QueuedConnection)
379379
self.api_sync.sync_success.connect(self.on_sync_success, type=Qt.QueuedConnection)
380380
self.api_sync.sync_failure.connect(self.on_sync_failure, type=Qt.QueuedConnection)

securedrop_client/sync.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from securedrop_client.api_jobs.base import ApiInaccessibleError
88
from securedrop_client.api_jobs.sync import MetadataSyncJob
99
from securedrop_client.crypto import GpgHelper
10+
from securedrop_client.gui import state
1011

1112
logger = logging.getLogger(__name__)
1213

@@ -23,7 +24,12 @@ class ApiSync(QObject):
2324
TIME_BETWEEN_SYNCS_MS = 1000 * 15 # fifteen seconds between syncs
2425

2526
def __init__(
26-
self, api_client: API, session_maker: scoped_session, gpg: GpgHelper, data_dir: str
27+
self,
28+
api_client: API,
29+
session_maker: scoped_session,
30+
gpg: GpgHelper,
31+
data_dir: str,
32+
state: state.State,
2733
):
2834
super().__init__()
2935
self.api_client = api_client
@@ -37,6 +43,7 @@ def __init__(
3743
self.sync_started,
3844
self.on_sync_success,
3945
self.on_sync_failure,
46+
state,
4047
)
4148
self.api_sync_bg_task.moveToThread(self.sync_thread)
4249

@@ -102,6 +109,7 @@ def __init__( # type: ignore [no-untyped-def]
102109
sync_started: pyqtSignal,
103110
on_sync_success,
104111
on_sync_failure,
112+
state: state.State,
105113
):
106114
super().__init__()
107115

@@ -113,7 +121,7 @@ def __init__( # type: ignore [no-untyped-def]
113121
self.on_sync_success = on_sync_success
114122
self.on_sync_failure = on_sync_failure
115123

116-
self.job = MetadataSyncJob(self.data_dir)
124+
self.job = MetadataSyncJob(self.data_dir, state)
117125
self.job.success_signal.connect(self.on_sync_success, type=Qt.QueuedConnection)
118126
self.job.failure_signal.connect(self.on_sync_failure, type=Qt.QueuedConnection)
119127

0 commit comments

Comments
 (0)