Browse Source

Only show local posts on public instance timelines

simple-swift-promises
Shadowfacts 2 years ago
parent
commit
81256b7a96
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
6 changed files with 8 additions and 26 deletions
  1. +1
    -1
      Pachyderm/Client.swift
  2. +2
    -14
      Pachyderm/Model/Timeline.swift
  3. +1
    -3
      Pachyderm/Request/Request.swift
  4. +0
    -4
      Tusker/Extensions/Timline+UI.swift
  5. +4
    -1
      Tusker/Screens/Timeline/InstanceTimelineViewController.swift
  6. +0
    -3
      Tusker/Shortcuts/UserActivityManager.swift

+ 1
- 1
Pachyderm/Client.swift View File

@ -81,7 +81,7 @@ public class Client {
}
func createURLRequest<Result>(request: Request<Result>) -> 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 }


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

@ -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
}


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

@ -10,14 +10,12 @@ import Foundation
public struct Request<ResultType: Decodable> {
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


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

@ -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
}


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

@ -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) {


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

@ -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)


Loading…
Cancel
Save