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

@ -30,6 +30,14 @@ extension APIService {
let targetStatusID = targetStatus.id let targetStatusID = targetStatus.id
_targetStatusID = targetStatusID _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) targetStatus.update(liked: favoriteKind == .create, by: mastodonUser)
} }

View File

@ -29,13 +29,18 @@ extension APIService {
let targetStatusID = targetStatus.id let targetStatusID = targetStatus.id
_targetStatusID = targetStatusID _targetStatusID = targetStatusID
let reblogsCount: NSNumber
switch reblogKind { switch reblogKind {
case .reblog: case .reblog:
targetStatus.update(reblogged: true, by: mastodonUser) targetStatus.update(reblogged: true, by: mastodonUser)
reblogsCount = NSNumber(value: targetStatus.reblogsCount.intValue + 1)
case .undoReblog: case .undoReblog:
targetStatus.update(reblogged: false, by: mastodonUser) targetStatus.update(reblogged: false, by: mastodonUser)
reblogsCount = NSNumber(value: max(0, targetStatus.reblogsCount.intValue - 1))
} }
targetStatus.update(reblogsCount: reblogsCount)
} }
.tryMap { result in .tryMap { result in
switch result { switch result {