From 49d00bb1b0d74e3151ae4dbe796ae4f1029980da Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 27 Apr 2020 19:32:16 -0400 Subject: [PATCH] Fix swipe actions not showing up --- Pachyderm/Model/Status.swift | 16 ++++++++-------- .../Views/Status/BaseStatusTableViewCell.swift | 4 ++-- .../Status/TimelineStatusTableViewCell.swift | 16 ++++++++-------- Tusker/XCallbackURL/XCBActions.swift | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Pachyderm/Model/Status.swift b/Pachyderm/Model/Status.swift index 3662fe04..9c422733 100644 --- a/Pachyderm/Model/Status.swift +++ b/Pachyderm/Model/Status.swift @@ -62,20 +62,20 @@ public class Status: Decodable { return Request(method: .delete, path: "/api/v1/statuses/\(status.id)") } - public static func reblog(_ status: Status) -> Request { - return Request(method: .post, path: "/api/v1/statuses/\(status.id)/reblog") + public static func reblog(_ statusID: String) -> Request { + return Request(method: .post, path: "/api/v1/statuses/\(statusID)/reblog") } - public static func unreblog(_ status: Status) -> Request { - return Request(method: .post, path: "/api/v1/statuses/\(status.id)/unreblog") + public static func unreblog(_ statusID: String) -> Request { + return Request(method: .post, path: "/api/v1/statuses/\(statusID)/unreblog") } - public static func favourite(_ status: Status) -> Request { - return Request(method: .post, path: "/api/v1/statuses/\(status.id)/favourite") + public static func favourite(_ statusID: String) -> Request { + return Request(method: .post, path: "/api/v1/statuses/\(statusID)/favourite") } - public static func unfavourite(_ status: Status) -> Request { - return Request(method: .post, path: "/api/v1/statuses/\(status.id)/unfavourite") + public static func unfavourite(_ statusID: String) -> Request { + return Request(method: .post, path: "/api/v1/statuses/\(statusID)/unfavourite") } public static func pin(_ status: Status) -> Request { diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 12652b10..e5fc77b3 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -255,7 +255,7 @@ class BaseStatusTableViewCell: UITableViewCell { favorited = !favorited let realStatus: Status = status.reblog ?? status - let request = (favorited ? Status.favourite : Status.unfavourite)(realStatus) + let request = (favorited ? Status.favourite : Status.unfavourite)(realStatus.id) mastodonController.run(request) { response in DispatchQueue.main.async { if case let .success(newStatus, _) = response { @@ -280,7 +280,7 @@ class BaseStatusTableViewCell: UITableViewCell { reblogged = !reblogged let realStatus: Status = status.reblog ?? status - let request = (reblogged ? Status.reblog : Status.unreblog)(realStatus) + let request = (reblogged ? Status.reblog : Status.unreblog)(realStatus.id) mastodonController.run(request) { response in DispatchQueue.main.async { if case let .success(newStatus, _) = response { diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 1338c59a..019fdaec 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -176,19 +176,19 @@ extension TimelineStatusTableViewCell: TableViewSwipeActionProvider { func leadingSwipeActionsConfiguration() -> UISwipeActionsConfiguration? { guard let mastodonController = mastodonController else { return nil } - guard let status = mastodonController.cache.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") } + guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") } let favoriteTitle: String let favoriteRequest: Request let favoriteColor: UIColor - if status.favourited ?? false { + if status.favourited { favoriteTitle = "Unfavorite" - favoriteRequest = Status.unfavourite(status) + favoriteRequest = Status.unfavourite(status.id) favoriteColor = UIColor(displayP3Red: 235/255, green: 77/255, blue: 62/255, alpha: 1) } else { favoriteTitle = "Favorite" - favoriteRequest = Status.favourite(status) + favoriteRequest = Status.favourite(status.id) favoriteColor = UIColor(displayP3Red: 1, green: 204/255, blue: 0, alpha: 1) } let favorite = UIContextualAction(style: .normal, title: favoriteTitle) { (action, view, completion) in @@ -199,7 +199,7 @@ extension TimelineStatusTableViewCell: TableViewSwipeActionProvider { return } completion(true) - mastodonController.cache.add(status: status) + mastodonController.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false) } }) } @@ -209,13 +209,13 @@ extension TimelineStatusTableViewCell: TableViewSwipeActionProvider { let reblogTitle: String let reblogRequest: Request let reblogColor: UIColor - if status.reblogged ?? false { + if status.reblogged { reblogTitle = "Unreblog" - reblogRequest = Status.unreblog(status) + reblogRequest = Status.unreblog(status.id) reblogColor = UIColor(displayP3Red: 235/255, green: 77/255, blue: 62/255, alpha: 1) } else { reblogTitle = "Reblog" - reblogRequest = Status.reblog(status) + reblogRequest = Status.reblog(status.id) reblogColor = tintColor } let reblog = UIContextualAction(style: .normal, title: reblogTitle) { (action, view, completion) in diff --git a/Tusker/XCallbackURL/XCBActions.swift b/Tusker/XCallbackURL/XCBActions.swift index 26dbb462..9ec6d1d9 100644 --- a/Tusker/XCallbackURL/XCBActions.swift +++ b/Tusker/XCallbackURL/XCBActions.swift @@ -204,9 +204,9 @@ struct XCBActions { statusAction(request: Status.reblog, alertTitle: "Reblog status?", request, session, silent) } - static func statusAction(request: @escaping (Status) -> Request, alertTitle: String, _ url: XCBRequest, _ session: XCBSession, _ silent: Bool?) { + static func statusAction(request: @escaping (String) -> Request, alertTitle: String, _ url: XCBRequest, _ session: XCBSession, _ silent: Bool?) { func performAction(status: Status, completion: ((Status) -> Void)?) { - mastodonController.run(request(status)) { (response) in + mastodonController.run(request(status.id)) { (response) in if case let .success(status, _) = response { mastodonController.cache.add(status: status) completion?(status)