commit abb818bbd4c82878559bef43958b61e730327a84 parent f1dc023e18a0358ff27a0b09fe93307e3edd2e38 Author: William Casarin <jb55@jb55.com> Date: Sun, 14 Jul 2024 20:14:56 -0700 Fix crash in profile related to profile updates Changelog-Fixed: Fix crash on profile page when there are profile updates Signed-off-by: William Casarin <jb55@jb55.com> Diffstat:
M | damus/Views/Profile/ProfileName.swift | | | 39 | +++++++++++++++++++++------------------ |
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/damus/Views/Profile/ProfileName.swift b/damus/Views/Profile/ProfileName.swift @@ -125,31 +125,34 @@ struct ProfileName: View { return } - var profile: Profile! - var profile_txn: NdbTxn<Profile?>! - switch update { case .remote(let pubkey): - profile_txn = damus_state.profiles.lookup(id: pubkey) - guard let prof = profile_txn.unsafeUnownedValue else { return } - profile = prof + guard let profile_txn = damus_state.profiles.lookup(id: pubkey), + let prof = profile_txn.unsafeUnownedValue else { + return + } + handle_profile_update(profile: prof) case .manual(_, let prof): - profile = prof + handle_profile_update(profile: prof) } - let display_name = Profile.displayName(profile: profile, pubkey: pubkey) - if self.display_name != display_name { - self.display_name = display_name - } + } + } - let nip05 = damus_state.profiles.is_validated(pubkey) - if nip05 != self.nip05 { - self.nip05 = nip05 - } + @MainActor + func handle_profile_update(profile: Profile) { + let display_name = Profile.displayName(profile: profile, pubkey: pubkey) + if self.display_name != display_name { + self.display_name = display_name + } - if donation != profile.damus_donation { - donation = profile.damus_donation - } + let nip05 = damus_state.profiles.is_validated(pubkey) + if nip05 != self.nip05 { + self.nip05 = nip05 + } + + if donation != profile.damus_donation { + donation = profile.damus_donation } } }