From 44cfd44651e0295e4e19e5f0f624b29a75aa86ec Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 1 Aug 2019 18:03:49 -0600 Subject: [PATCH] Fix faving/reblogging statuses by tapping buttons --- .../Status/ConversationMainStatusTableViewCell.swift | 10 ++++++---- Tusker/Views/Status/StatusTableViewCell.swift | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift index 5c57a1fc..1d19c54d 100644 --- a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift +++ b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift @@ -149,9 +149,10 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive let request = (favorited ? Status.favourite : Status.unfavourite)(realStatus) MastodonController.client.run(request) { response in - self.favorited = realStatus.favourited ?? false DispatchQueue.main.async { - if case .success = response { + if case let .success(newStatus, _) = response { + self.favorited = newStatus.favourited ?? false + MastodonCache.add(status: newStatus) UIImpactFeedbackGenerator(style: .light).impactOccurred() } else { print("Couldn't favorite status \(realStatus.id)") @@ -172,9 +173,10 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive let request = (reblogged ? Status.reblog : Status.unreblog)(realStatus) MastodonController.client.run(request) { response in - self.reblogged = realStatus.reblogged ?? false DispatchQueue.main.async { - if case .success = response { + if case let .success(newStatus, _) = response { + self.reblogged = newStatus.reblogged ?? false + MastodonCache.add(status: newStatus) UIImpactFeedbackGenerator(style: .light).impactOccurred() } else { print("Couldn't reblog status \(realStatus.id)") diff --git a/Tusker/Views/Status/StatusTableViewCell.swift b/Tusker/Views/Status/StatusTableViewCell.swift index cc949314..60975409 100644 --- a/Tusker/Views/Status/StatusTableViewCell.swift +++ b/Tusker/Views/Status/StatusTableViewCell.swift @@ -175,9 +175,9 @@ class StatusTableViewCell: UITableViewCell, PreferencesAdaptive { let request = (favorited ? Status.favourite : Status.unfavourite)(realStatus) MastodonController.client.run(request) { response in DispatchQueue.main.async { - self.favorited = realStatus.favourited ?? false - if case .success = response { - self.favorited = realStatus.favourited ?? false + if case let .success(newStatus, _) = response { + self.favorited = newStatus.favourited ?? false + MastodonCache.add(status: newStatus) UIImpactFeedbackGenerator(style: .light).impactOccurred() } else { self.favorited = oldValue @@ -199,10 +199,10 @@ class StatusTableViewCell: UITableViewCell, PreferencesAdaptive { let realStatus: Status = status.reblog ?? status let request = (reblogged ? Status.reblog : Status.unreblog)(realStatus) MastodonController.client.run(request) { response in - self.reblogged = realStatus.reblogged ?? false DispatchQueue.main.async { - if case .success = response { - self.reblogged = realStatus.reblogged ?? false + if case let .success(newStatus, _) = response { + self.reblogged = newStatus.reblogged ?? false + MastodonCache.add(status: newStatus) UIImpactFeedbackGenerator(style: .light).impactOccurred() } else { self.reblogged = oldValue