From 04dbe9ebc9f947cd874036c57e924c6233ceb88f Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 17 Jun 2021 16:44:57 +0800 Subject: [PATCH] fix: reblog and favorite count update delay issue --- .../Protocol/StatusProvider/StatusProviderFacade.swift | 2 +- Mastodon/Service/APIService/APIService+Favorite.swift | 8 ++++++++ Mastodon/Service/APIService/APIService+Reblog.swift | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift index 98fecc975..a21422159 100644 --- a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift +++ b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift @@ -247,7 +247,7 @@ extension StatusProviderFacade { } .map { statusObjectID, favoriteKind -> AnyPublisher<(Status.ID, Mastodon.API.Favorites.FavoriteKind), Error> in return context.apiService.favorite( - statusObjectID: statusObjectID, + statusObjectID: statusObjectID, mastodonUserObjectID: mastodonUserObjectID, favoriteKind: favoriteKind ) diff --git a/Mastodon/Service/APIService/APIService+Favorite.swift b/Mastodon/Service/APIService/APIService+Favorite.swift index 23206494e..d3f1d81ec 100644 --- a/Mastodon/Service/APIService/APIService+Favorite.swift +++ b/Mastodon/Service/APIService/APIService+Favorite.swift @@ -30,6 +30,14 @@ extension APIService { let targetStatusID = targetStatus.id _targetStatusID = targetStatusID + let favouritesCount: NSNumber + switch favoriteKind { + case .create: + favouritesCount = NSNumber(value: targetStatus.favouritesCount.intValue + 1) + case .destroy: + favouritesCount = NSNumber(value: max(0, targetStatus.favouritesCount.intValue - 1)) + } + targetStatus.update(favouritesCount: favouritesCount) targetStatus.update(liked: favoriteKind == .create, by: mastodonUser) } diff --git a/Mastodon/Service/APIService/APIService+Reblog.swift b/Mastodon/Service/APIService/APIService+Reblog.swift index 6dc9f189b..adfac3066 100644 --- a/Mastodon/Service/APIService/APIService+Reblog.swift +++ b/Mastodon/Service/APIService/APIService+Reblog.swift @@ -29,12 +29,17 @@ extension APIService { let targetStatusID = targetStatus.id _targetStatusID = targetStatusID + let reblogsCount: NSNumber switch reblogKind { case .reblog: targetStatus.update(reblogged: true, by: mastodonUser) + reblogsCount = NSNumber(value: targetStatus.reblogsCount.intValue + 1) case .undoReblog: targetStatus.update(reblogged: false, by: mastodonUser) + reblogsCount = NSNumber(value: max(0, targetStatus.reblogsCount.intValue - 1)) } + + targetStatus.update(reblogsCount: reblogsCount) } .tryMap { result in