Browse Source

Only show local posts on public instance timelines

simple-swift-promises
Shadowfacts 5 months ago
parent
commit
81256b7a96
Signed by: Shadowfacts <me@shadowfacts.net> GPG Key ID: 94A5AB95422746E5

+ 1
- 1
Pachyderm/Client.swift View File

@@ -81,7 +81,7 @@ public class Client {
81 81
     }
82 82
     
83 83
     func createURLRequest<Result>(request: Request<Result>) -> URLRequest? {
84
-        guard var components = URLComponents(url: request.baseURL ?? baseURL, resolvingAgainstBaseURL: true) else { return nil }
84
+        guard var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else { return nil }
85 85
         components.path = request.path
86 86
         components.queryItems = request.queryParameters.queryItems
87 87
         guard let url = components.url else { return nil }

+ 2
- 14
Pachyderm/Model/Timeline.swift View File

@@ -11,7 +11,6 @@ import Foundation
11 11
 public enum Timeline {
12 12
     case home
13 13
     case `public`(local: Bool)
14
-    case instance(instanceURL: URL)
15 14
     case tag(hashtag: String)
16 15
     case list(id: String)
17 16
     case direct
@@ -22,7 +21,7 @@ extension Timeline {
22 21
         switch self {
23 22
         case .home:
24 23
             return "/api/v1/timelines/home"
25
-        case .public, .instance(_):
24
+        case .public:
26 25
             return "/api/v1/timelines/public"
27 26
         case let .tag(hashtag):
28 27
             return "/api/v1/timelines/tag/\(hashtag)"
@@ -34,12 +33,7 @@ extension Timeline {
34 33
     }
35 34
     
36 35
     func request(range: RequestRange) -> Request<[Status]> {
37
-        var request: Request<[Status]>
38
-        if case let .instance(instanceURL) = self {
39
-            request = Request<[Status]>(method: .get, baseURL: instanceURL, path: endpoint)
40
-        } else {
41
-            request = Request<[Status]>(method: .get, path: endpoint)
42
-        }
36
+        var request: Request<[Status]> = Request<[Status]>(method: .get, path: endpoint)
43 37
         if case .public(true) = self {
44 38
             request.queryParameters.append("local" => true)
45 39
         }
@@ -57,8 +51,6 @@ extension Timeline: Codable {
57 51
             self = .home
58 52
         case "public":
59 53
             self = .public(local: try container.decode(Bool.self, forKey: .local))
60
-        case "instanceURL":
61
-            self = .instance(instanceURL: try container.decode(URL.self, forKey: .instanceURL))
62 54
         case "tag":
63 55
             self = .tag(hashtag: try container.decode(String.self, forKey: .hashtag))
64 56
         case "list":
@@ -78,9 +70,6 @@ extension Timeline: Codable {
78 70
         case let .public(local):
79 71
             try container.encode("public", forKey: .type)
80 72
             try container.encode(local, forKey: .local)
81
-        case let .instance(instanceURL):
82
-            try container.encode("instanceURL", forKey: .type)
83
-            try container.encode(instanceURL, forKey: .instanceURL)
84 73
         case let .tag(hashtag):
85 74
             try container.encode("tag", forKey: .type)
86 75
             try container.encode(hashtag, forKey: .hashtag)
@@ -95,7 +84,6 @@ extension Timeline: Codable {
95 84
     enum CodingKeys: String, CodingKey {
96 85
         case type
97 86
         case local
98
-        case instanceURL
99 87
         case hashtag
100 88
         case listID
101 89
     }

+ 1
- 3
Pachyderm/Request/Request.swift View File

@@ -10,14 +10,12 @@ import Foundation
10 10
 
11 11
 public struct Request<ResultType: Decodable> {
12 12
     let method: Method
13
-    let baseURL: URL?
14 13
     let path: String
15 14
     let body: Body
16 15
     var queryParameters: [Parameter]
17 16
     
18
-    init(method: Method, baseURL: URL? = nil, path: String, body: Body = .empty, queryParameters: [Parameter] = []) {
17
+    init(method: Method, path: String, body: Body = .empty, queryParameters: [Parameter] = []) {
19 18
         self.method = method
20
-        self.baseURL = baseURL
21 19
         self.path = path
22 20
         self.body = body
23 21
         self.queryParameters = queryParameters

+ 0
- 4
Tusker/Extensions/Timline+UI.swift View File

@@ -16,8 +16,6 @@ extension Timeline {
16 16
             return "Home"
17 17
         case let .public(local):
18 18
             return local ? "Local" : "Federated"
19
-        case let .instance(instance):
20
-            return instance.host!
21 19
         case let .tag(hashtag):
22 20
             return "#\(hashtag)"
23 21
         case .list:
@@ -37,8 +35,6 @@ extension Timeline {
37 35
             } else {
38 36
                 return UIImage(systemName: "globe")
39 37
             }
40
-        case .instance(_):
41
-            return UIImage(systemName: "globe")
42 38
         default:
43 39
             return nil
44 40
         }

+ 4
- 1
Tusker/Screens/Timeline/InstanceTimelineViewController.swift View File

@@ -39,7 +39,10 @@ class InstanceTimelineViewController: TimelineTableViewController {
39 39
         // 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
40 40
         instanceMastodonController = MastodonController(instanceURL: url)
41 41
 
42
-        super.init(for: .instance(instanceURL: url), mastodonController: instanceMastodonController)
42
+        super.init(for: .public(local: true), mastodonController: instanceMastodonController)
43
+        
44
+        title = url.host!
45
+        userActivity = nil // todo: activity for instance-specific timelines
43 46
     }
44 47
     
45 48
     required init?(coder aDecoder: NSCoder) {

+ 0
- 3
Tusker/Shortcuts/UserActivityManager.swift View File

@@ -111,9 +111,6 @@ class UserActivityManager {
111 111
         case .public(local: false):
112 112
             activity.title = NSLocalizedString("Show Federated Timeline", comment: "federated timeline shortcut title")
113 113
             activity.suggestedInvocationPhrase = NSLocalizedString("Show my federated timeline", comment: "federated timeline invocation phrase")
114
-        case let .instance(instance):
115
-            activity.title = String(format: NSLocalizedString("Show %@", comment: "show instance timeline shortcut title"), instance.host!)
116
-            activity.suggestedInvocationPhrase = String(format: NSLocalizedString("Show the instance %@", comment: "instance timeline shortcut invocation phrase"), instance.host!)
117 114
         case let .tag(hashtag):
118 115
             activity.title = String(format: NSLocalizedString("Show #%@", comment: "show hashtag shortcut title"), hashtag)
119 116
             activity.suggestedInvocationPhrase = String(format: NSLocalizedString("Show the %@ hashtag", comment: "hashtag shortcut invocation phrase"), hashtag)

Loading…
Cancel
Save