No content changes: git diff --ignore-all-space over these files is empty. The churn came from editing on Windows against a repo checked out with LF.
34 lines
1.4 KiB
Dart
34 lines
1.4 KiB
Dart
import '../../models/document_model.dart';
|
|
|
|
/// Result of merging the server's document list with local corrections that
|
|
/// haven't made it back to the server yet.
|
|
class MergedDocuments {
|
|
final List<DocumentModel> docs;
|
|
final Set<String> unsyncedIds;
|
|
|
|
const MergedDocuments(this.docs, this.unsyncedIds);
|
|
}
|
|
|
|
/// Merges the server's authoritative document list with local corrections for
|
|
/// documents whose `PUT` sync failed (`syncFailed` in the pending queue).
|
|
///
|
|
/// Without this, refreshing the documents list would silently overwrite a
|
|
/// driver's corrected-but-unsynced edit with the server's stale pre-edit copy
|
|
/// on every successful fetch - the correction is still recoverable via the
|
|
/// pending queue's retry action, but the history list would show the wrong
|
|
/// data (or the document would vanish from it entirely) until the retry
|
|
/// succeeds. `unsyncedOverrides` wins over `serverDocs` for matching ids, and
|
|
/// is kept even if the server list doesn't (yet) include that id at all.
|
|
MergedDocuments mergeDocumentsWithUnsyncedOverrides({
|
|
required List<DocumentModel> serverDocs,
|
|
required Map<String, DocumentModel> unsyncedOverrides,
|
|
}) {
|
|
final merged = <String, DocumentModel>{
|
|
for (final doc in serverDocs) doc.id: doc,
|
|
};
|
|
for (final entry in unsyncedOverrides.entries) {
|
|
merged[entry.key] = entry.value;
|
|
}
|
|
return MergedDocuments(merged.values.toList(), unsyncedOverrides.keys.toSet());
|
|
}
|