Potentially fix race condition

This commit is contained in:
nielsandriesse 2021-02-24 09:53:17 +11:00
parent c5c6bf2624
commit afeabf0fe9
2 changed files with 3 additions and 3 deletions

View File

@ -218,4 +218,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 2fca3f32c171e1324c9e3809b96a32d4a929d05c PODFILE CHECKSUM: 2fca3f32c171e1324c9e3809b96a32d4a929d05c
COCOAPODS: 1.10.0.rc.1 COCOAPODS: 1.10.1

View File

@ -153,7 +153,7 @@ extension MessageReceiver {
let shouldUpdate = given(userDefaults[.lastDisplayNameUpdate]) { message.sentTimestamp! > UInt64($0.timeIntervalSince1970 * 1000) } ?? true let shouldUpdate = given(userDefaults[.lastDisplayNameUpdate]) { message.sentTimestamp! > UInt64($0.timeIntervalSince1970 * 1000) } ?? true
if shouldUpdate { if shouldUpdate {
userProfile.profileName = displayName userProfile.profileName = displayName
userDefaults[.lastDisplayNameUpdate] = Date() userDefaults[.lastDisplayNameUpdate] = Date(timeIntervalSince1970: TimeInterval(message.sentTimestamp! / 1000))
} }
} }
if let profilePictureURL = message.profilePictureURL, let profileKeyAsData = message.profileKey { if let profilePictureURL = message.profilePictureURL, let profileKeyAsData = message.profileKey {
@ -161,7 +161,7 @@ extension MessageReceiver {
if shouldUpdate { if shouldUpdate {
userProfile.avatarUrlPath = profilePictureURL userProfile.avatarUrlPath = profilePictureURL
userProfile.profileKey = OWSAES256Key(data: profileKeyAsData) userProfile.profileKey = OWSAES256Key(data: profileKeyAsData)
userDefaults[.lastProfilePictureUpdate] = Date() userDefaults[.lastProfilePictureUpdate] = Date(timeIntervalSince1970: TimeInterval(message.sentTimestamp! / 1000))
} }
} }
userProfile.save(with: transaction) userProfile.save(with: transaction)