From 81256b7a96e70042bbc3aa49662b3620e90a294a Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 25 Jan 2020 10:37:22 -0500 Subject: [PATCH] Only show local posts on public instance timelines --- Pachyderm/Client.swift | 2 +- Pachyderm/Model/Timeline.swift | 16 ++-------------- Pachyderm/Request/Request.swift | 4 +--- Tusker/Extensions/Timline+UI.swift | 4 ---- .../InstanceTimelineViewController.swift | 5 ++++- Tusker/Shortcuts/UserActivityManager.swift | 3 --- 6 files changed, 8 insertions(+), 26 deletions(-) diff --git a/Pachyderm/Client.swift b/Pachyderm/Client.swift index e0de6b61..c593b7b3 100644 --- a/Pachyderm/Client.swift +++ b/Pachyderm/Client.swift @@ -81,7 +81,7 @@ public class Client { } func createURLRequest(request: Request) -> URLRequest? { - guard var components = URLComponents(url: request.baseURL ?? baseURL, resolvingAgainstBaseURL: true) else { return nil } + guard var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else { return nil } components.path = request.path components.queryItems = request.queryParameters.queryItems guard let url = components.url else { return nil } diff --git a/Pachyderm/Model/Timeline.swift b/Pachyderm/Model/Timeline.swift index 65f8ac78..a515701a 100644 --- a/Pachyderm/Model/Timeline.swift +++ b/Pachyderm/Model/Timeline.swift @@ -11,7 +11,6 @@ import Foundation public enum Timeline { case home case `public`(local: Bool) - case instance(instanceURL: URL) case tag(hashtag: String) case list(id: String) case direct @@ -22,7 +21,7 @@ extension Timeline { switch self { case .home: return "/api/v1/timelines/home" - case .public, .instance(_): + case .public: return "/api/v1/timelines/public" case let .tag(hashtag): return "/api/v1/timelines/tag/\(hashtag)" @@ -34,12 +33,7 @@ extension Timeline { } func request(range: RequestRange) -> Request<[Status]> { - var request: Request<[Status]> - if case let .instance(instanceURL) = self { - request = Request<[Status]>(method: .get, baseURL: instanceURL, path: endpoint) - } else { - request = Request<[Status]>(method: .get, path: endpoint) - } + var request: Request<[Status]> = Request<[Status]>(method: .get, path: endpoint) if case .public(true) = self { request.queryParameters.append("local" => true) } @@ -57,8 +51,6 @@ extension Timeline: Codable { self = .home case "public": self = .public(local: try container.decode(Bool.self, forKey: .local)) - case "instanceURL": - self = .instance(instanceURL: try container.decode(URL.self, forKey: .instanceURL)) case "tag": self = .tag(hashtag: try container.decode(String.self, forKey: .hashtag)) case "list": @@ -78,9 +70,6 @@ extension Timeline: Codable { case let .public(local): try container.encode("public", forKey: .type) try container.encode(local, forKey: .local) - case let .instance(instanceURL): - try container.encode("instanceURL", forKey: .type) - try container.encode(instanceURL, forKey: .instanceURL) case let .tag(hashtag): try container.encode("tag", forKey: .type) try container.encode(hashtag, forKey: .hashtag) @@ -95,7 +84,6 @@ extension Timeline: Codable { enum CodingKeys: String, CodingKey { case type case local - case instanceURL case hashtag case listID } diff --git a/Pachyderm/Request/Request.swift b/Pachyderm/Request/Request.swift index e877e873..c21aaf67 100644 --- a/Pachyderm/Request/Request.swift +++ b/Pachyderm/Request/Request.swift @@ -10,14 +10,12 @@ import Foundation public struct Request { let method: Method - let baseURL: URL? let path: String let body: Body var queryParameters: [Parameter] - init(method: Method, baseURL: URL? = nil, path: String, body: Body = .empty, queryParameters: [Parameter] = []) { + init(method: Method, path: String, body: Body = .empty, queryParameters: [Parameter] = []) { self.method = method - self.baseURL = baseURL self.path = path self.body = body self.queryParameters = queryParameters diff --git a/Tusker/Extensions/Timline+UI.swift b/Tusker/Extensions/Timline+UI.swift index b34c2f84..a0364187 100644 --- a/Tusker/Extensions/Timline+UI.swift +++ b/Tusker/Extensions/Timline+UI.swift @@ -16,8 +16,6 @@ extension Timeline { return "Home" case let .public(local): return local ? "Local" : "Federated" - case let .instance(instance): - return instance.host! case let .tag(hashtag): return "#\(hashtag)" case .list: @@ -37,8 +35,6 @@ extension Timeline { } else { return UIImage(systemName: "globe") } - case .instance(_): - return UIImage(systemName: "globe") default: return nil } diff --git a/Tusker/Screens/Timeline/InstanceTimelineViewController.swift b/Tusker/Screens/Timeline/InstanceTimelineViewController.swift index 2694bf6f..9284df25 100644 --- a/Tusker/Screens/Timeline/InstanceTimelineViewController.swift +++ b/Tusker/Screens/Timeline/InstanceTimelineViewController.swift @@ -39,7 +39,10 @@ class InstanceTimelineViewController: TimelineTableViewController { // the timeline VC only stores a weak reference to it, so we need to store a strong reference to make sure it's not released immediately instanceMastodonController = MastodonController(instanceURL: url) - super.init(for: .instance(instanceURL: url), mastodonController: instanceMastodonController) + super.init(for: .public(local: true), mastodonController: instanceMastodonController) + + title = url.host! + userActivity = nil // todo: activity for instance-specific timelines } required init?(coder aDecoder: NSCoder) { diff --git a/Tusker/Shortcuts/UserActivityManager.swift b/Tusker/Shortcuts/UserActivityManager.swift index 4c181663..28045bd6 100644 --- a/Tusker/Shortcuts/UserActivityManager.swift +++ b/Tusker/Shortcuts/UserActivityManager.swift @@ -111,9 +111,6 @@ class UserActivityManager { case .public(local: false): activity.title = NSLocalizedString("Show Federated Timeline", comment: "federated timeline shortcut title") activity.suggestedInvocationPhrase = NSLocalizedString("Show my federated timeline", comment: "federated timeline invocation phrase") - case let .instance(instance): - activity.title = String(format: NSLocalizedString("Show %@", comment: "show instance timeline shortcut title"), instance.host!) - activity.suggestedInvocationPhrase = String(format: NSLocalizedString("Show the instance %@", comment: "instance timeline shortcut invocation phrase"), instance.host!) case let .tag(hashtag): activity.title = String(format: NSLocalizedString("Show #%@", comment: "show hashtag shortcut title"), hashtag) activity.suggestedInvocationPhrase = String(format: NSLocalizedString("Show the %@ hashtag", comment: "hashtag shortcut invocation phrase"), hashtag)