@@ -73,7 +73,8 @@ base class AttachmentQueue {
7373
7474 final Mutex _mutex = Mutex ();
7575 bool _closed = false ;
76- StreamSubscription <List <WatchedAttachmentItem >>? _syncStatusSubscription;
76+ StreamSubscription <void >? _syncStatusSubscription;
77+ StreamSubscription <void >? _watchedAttachmentsSubscription;
7778 final AttachmentService _attachmentsService;
7879 final SyncingService _syncingService;
7980
@@ -168,10 +169,23 @@ base class AttachmentQueue {
168169 await _verifyAttachments (context);
169170 });
170171
172+ // Listen for connectivity changes and watched attachments
171173 await _syncingService.startSync ();
172174
173- // Listen for connectivity changes and watched attachments
174- _syncStatusSubscription = _watchAttachments ().listen ((items) async {
175+ _watchedAttachmentsSubscription =
176+ _watchAttachments ().listen ((items) async {
177+ await _processWatchedAttachments (items);
178+ });
179+
180+ var previouslyConnected = _db.currentStatus.connected;
181+ _syncStatusSubscription = _db.statusStream.listen ((status) {
182+ if (! previouslyConnected && status.connected) {
183+ _syncingService.triggerSync ();
184+ }
185+
186+ previouslyConnected = status.connected;
187+ });
188+ _watchAttachments ().listen ((items) async {
175189 await _processWatchedAttachments (items);
176190 });
177191
@@ -187,10 +201,19 @@ base class AttachmentQueue {
187201 }
188202
189203 Future <void > _stopSyncingInternal () async {
190- if (_closed || _syncStatusSubscription == null ) return ;
204+ if (_closed ||
205+ _syncStatusSubscription == null ||
206+ _watchedAttachmentsSubscription == null ) {
207+ return ;
208+ }
209+
210+ await (
211+ _syncStatusSubscription! .cancel (),
212+ _watchedAttachmentsSubscription! .cancel (),
213+ ).wait;
191214
192- await _syncStatusSubscription? .cancel ();
193215 _syncStatusSubscription = null ;
216+ _watchedAttachmentsSubscription = null ;
194217 await _syncingService.stopSync ();
195218
196219 _logger.info ('AttachmentQueue stopped syncing.' );
0 commit comments