@@ -73,7 +73,8 @@ base class AttachmentQueue {
73
73
74
74
final Mutex _mutex = Mutex ();
75
75
bool _closed = false ;
76
- StreamSubscription <List <WatchedAttachmentItem >>? _syncStatusSubscription;
76
+ StreamSubscription <void >? _syncStatusSubscription;
77
+ StreamSubscription <void >? _watchedAttachmentsSubscription;
77
78
final AttachmentService _attachmentsService;
78
79
final SyncingService _syncingService;
79
80
@@ -168,10 +169,23 @@ base class AttachmentQueue {
168
169
await _verifyAttachments (context);
169
170
});
170
171
172
+ // Listen for connectivity changes and watched attachments
171
173
await _syncingService.startSync ();
172
174
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 {
175
189
await _processWatchedAttachments (items);
176
190
});
177
191
@@ -187,10 +201,19 @@ base class AttachmentQueue {
187
201
}
188
202
189
203
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;
191
214
192
- await _syncStatusSubscription? .cancel ();
193
215
_syncStatusSubscription = null ;
216
+ _watchedAttachmentsSubscription = null ;
194
217
await _syncingService.stopSync ();
195
218
196
219
_logger.info ('AttachmentQueue stopped syncing.' );
0 commit comments