fix: reblog and favorite count update delay issue
This commit is contained in:
parent
931197e51c
commit
04dbe9ebc9
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue