From e3876382bbd9087006e576d4db77223a50aba176 Mon Sep 17 00:00:00 2001 From: Daira-Emma Hopwood Date: Tue, 19 Nov 2024 15:01:20 +0000 Subject: [PATCH] Fix a bug in the logic for when we should update the remote address book file. This would have caused new address book entries not to be written (after the first remote store of the file). Signed-off-by: Daira-Emma Hopwood --- CHANGELOG.md | 3 +++ .../AddressBookClient/AddressBookLiveKey.swift | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eda05a719..82b4d93e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ directly impact users rather than highlighting other crucial architectural updat ## [Unreleased] +### Fixed +- Fixed a bug that could cause newly added address book entries not to be saved remotely. + ## 1.2.3 build 3 (2024-11-19) ### Added diff --git a/modules/Sources/Dependencies/AddressBookClient/AddressBookLiveKey.swift b/modules/Sources/Dependencies/AddressBookClient/AddressBookLiveKey.swift index 31a2fb3e4..205ed29a6 100644 --- a/modules/Sources/Dependencies/AddressBookClient/AddressBookLiveKey.swift +++ b/modules/Sources/Dependencies/AddressBookClient/AddressBookLiveKey.swift @@ -165,7 +165,7 @@ extension AddressBookClient: DependencyKey { remoteStorage: RemoteStorageClient, storeAfterSync: Bool = true ) throws -> (contacts: AddressBookContacts, remoteStoreResult: RemoteStoreResult) { - // Ensure remote contacts are prepared + // Ensure remote contacts are prepared. var remoteContacts: AddressBookContacts = .empty var shouldUpdateRemote = false var cannotUpdateRemote = false @@ -185,14 +185,16 @@ extension AddressBookClient: DependencyKey { throw error } - // Merge strategy + // We merge from the local contacts into the remote contacts, which + // makes it easy to see when the merged contacts have changed relative + // to the previous remote contacts. var syncedContacts = AddressBookContacts( lastUpdated: Date(), version: AddressBookContacts.Constants.version, - contacts: contacts.contacts + contacts: remoteContacts.contacts ) - remoteContacts.contacts.forEach { + contacts.contacts.forEach { var notFound = true for i in 0..