Only show local posts on public instance timelines

This commit is contained in:
Shadowfacts 2020-01-25 10:37:22 -05:00
parent 5a6c12c5a7
commit 81256b7a96
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
6 changed files with 8 additions and 26 deletions

View File

@ -81,7 +81,7 @@ public class Client {
} }
func createURLRequest<Result>(request: Request<Result>) -> URLRequest? { 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.path = request.path
components.queryItems = request.queryParameters.queryItems components.queryItems = request.queryParameters.queryItems
guard let url = components.url else { return nil } guard let url = components.url else { return nil }

View File

@ -11,7 +11,6 @@ import Foundation
public enum Timeline { public enum Timeline {
case home case home
case `public`(local: Bool) case `public`(local: Bool)
case instance(instanceURL: URL)
case tag(hashtag: String) case tag(hashtag: String)
case list(id: String) case list(id: String)
case direct case direct
@ -22,7 +21,7 @@ extension Timeline {
switch self { switch self {
case .home: case .home:
return "/api/v1/timelines/home" return "/api/v1/timelines/home"
case .public, .instance(_): case .public:
return "/api/v1/timelines/public" return "/api/v1/timelines/public"
case let .tag(hashtag): case let .tag(hashtag):
return "/api/v1/timelines/tag/\(hashtag)" return "/api/v1/timelines/tag/\(hashtag)"
@ -34,12 +33,7 @@ extension Timeline {
} }
func request(range: RequestRange) -> Request<[Status]> { func request(range: RequestRange) -> Request<[Status]> {
var request: Request<[Status]> var request: Request<[Status]> = Request<[Status]>(method: .get, path: endpoint)
if case let .instance(instanceURL) = self {
request = Request<[Status]>(method: .get, baseURL: instanceURL, path: endpoint)
} else {
request = Request<[Status]>(method: .get, path: endpoint)
}
if case .public(true) = self { if case .public(true) = self {
request.queryParameters.append("local" => true) request.queryParameters.append("local" => true)
} }
@ -57,8 +51,6 @@ extension Timeline: Codable {
self = .home self = .home
case "public": case "public":
self = .public(local: try container.decode(Bool.self, forKey: .local)) self = .public(local: try container.decode(Bool.self, forKey: .local))
case "instanceURL":
self = .instance(instanceURL: try container.decode(URL.self, forKey: .instanceURL))
case "tag": case "tag":
self = .tag(hashtag: try container.decode(String.self, forKey: .hashtag)) self = .tag(hashtag: try container.decode(String.self, forKey: .hashtag))
case "list": case "list":
@ -78,9 +70,6 @@ extension Timeline: Codable {
case let .public(local): case let .public(local):
try container.encode("public", forKey: .type) try container.encode("public", forKey: .type)
try container.encode(local, forKey: .local) 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): case let .tag(hashtag):
try container.encode("tag", forKey: .type) try container.encode("tag", forKey: .type)
try container.encode(hashtag, forKey: .hashtag) try container.encode(hashtag, forKey: .hashtag)
@ -95,7 +84,6 @@ extension Timeline: Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case type case type
case local case local
case instanceURL
case hashtag case hashtag
case listID case listID
} }

View File

@ -10,14 +10,12 @@ import Foundation
public struct Request<ResultType: Decodable> { public struct Request<ResultType: Decodable> {
let method: Method let method: Method
let baseURL: URL?
let path: String let path: String
let body: Body let body: Body
var queryParameters: [Parameter] 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.method = method
self.baseURL = baseURL
self.path = path self.path = path
self.body = body self.body = body
self.queryParameters = queryParameters self.queryParameters = queryParameters

View File

@ -16,8 +16,6 @@ extension Timeline {
return "Home" return "Home"
case let .public(local): case let .public(local):
return local ? "Local" : "Federated" return local ? "Local" : "Federated"
case let .instance(instance):
return instance.host!
case let .tag(hashtag): case let .tag(hashtag):
return "#\(hashtag)" return "#\(hashtag)"
case .list: case .list:
@ -37,8 +35,6 @@ extension Timeline {
} else { } else {
return UIImage(systemName: "globe") return UIImage(systemName: "globe")
} }
case .instance(_):
return UIImage(systemName: "globe")
default: default:
return nil return nil
} }

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 // 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) 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) { required init?(coder aDecoder: NSCoder) {

View File

@ -111,9 +111,6 @@ class UserActivityManager {
case .public(local: false): case .public(local: false):
activity.title = NSLocalizedString("Show Federated Timeline", comment: "federated timeline shortcut title") activity.title = NSLocalizedString("Show Federated Timeline", comment: "federated timeline shortcut title")
activity.suggestedInvocationPhrase = NSLocalizedString("Show my federated timeline", comment: "federated timeline invocation phrase") 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): case let .tag(hashtag):
activity.title = String(format: NSLocalizedString("Show #%@", comment: "show hashtag shortcut title"), 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) activity.suggestedInvocationPhrase = String(format: NSLocalizedString("Show the %@ hashtag", comment: "hashtag shortcut invocation phrase"), hashtag)