fix: reblog and favorite count update delay issue

This commit is contained in:
CMK 2021-06-17 16:44:57 +08:00
parent 931197e51c
commit 04dbe9ebc9
3 changed files with 14 additions and 1 deletions

View File

@ -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
)

View File

@ -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)
}

View File

@ -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