From 308e5ab9101322dff1c0367609b5db0680f18b4f Mon Sep 17 00:00:00 2001 From: Sjmarf <78750526+Sjmarf@users.noreply.github.com> Date: Tue, 16 Jan 2024 11:24:31 +0000 Subject: [PATCH] Community Favorite Fix (#857) --- .../Content/Community/CommunityModel.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Mlem/Models/Content/Community/CommunityModel.swift b/Mlem/Models/Content/Community/CommunityModel.swift index 256e2fd73..8066a62d9 100644 --- a/Mlem/Models/Content/Community/CommunityModel.swift +++ b/Mlem/Models/Content/Community/CommunityModel.swift @@ -185,24 +185,24 @@ struct CommunityModel { func toggleFavorite(_ callback: @escaping (_ item: Self) -> Void = { _ in }) async throws { var new = self new.favorited.toggle() - if favorited { - favoriteCommunitiesTracker.unfavorite(community) - } else { - favoriteCommunitiesTracker.favorite(community) + if new.favorited { + favoriteCommunitiesTracker.favorite(self.community) if let subscribed, !subscribed { - try await self.toggleSubscribe { [self] community in + try await new.toggleSubscribe { community in var community = community if !(community.subscribed ?? true) { print("Subscribe failed, unfavoriting...") community.favorited = false - favoriteCommunitiesTracker.unfavorite(self.community) + favoriteCommunitiesTracker.unfavorite(community.community) } - callback(new) + callback(community) } } - } - RunLoop.main.perform { [new] in - callback(new) + } else { + favoriteCommunitiesTracker.unfavorite(community) + RunLoop.main.perform { [new] in + callback(new) + } } }