Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/services/sync_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,29 @@ class SyncManager {
.map((i) => i.get<String>('issn'))
.toSet();

bool isMatch = false;
// If an issn match I merge them to avoid duplicates
if (localIssnSet.intersection(cloudIssnSet).isNotEmpty) {
isMatch = true;
} else if (localIssnSet.isEmpty || cloudIssnSet.isEmpty) {
String localPub = (potentialMatch['publisher'] ?? '')
.toString()
.toLowerCase()
.trim();
String cloudPub =
r.get<String>('publisher', '').toLowerCase().trim();

if (localPub.isEmpty ||
cloudPub.isEmpty ||
localPub.contains(cloudPub) ||
cloudPub.contains(localPub)) {
isMatch = true;
}
}

if (isMatch) {
logger.info(
"Merging local journal ${potentialMatch['sync_id']} into cloud ID $cloudSyncId via ISSN match.");
"Merging local journal ${potentialMatch['sync_id']} into cloud ID $cloudSyncId.");
await db.update('journals', {'sync_id': cloudSyncId},
where: 'journal_id = ?', whereArgs: [localId]);

Expand Down