Change Mastodon into Pixelfed.

This commit is contained in:
Marcin Czachursk 2023-02-19 10:43:37 +01:00
parent 7d55eba3ee
commit e507ed3916
54 changed files with 234 additions and 234 deletions

View File

@ -6,7 +6,7 @@
import Foundation
/// Represents a user of Mastodon and their associated profile.
/// Represents a user of Pixelfed and their associated profile.
public struct Account: Codable {
/// The account id.

View File

@ -6,12 +6,12 @@
import Foundation
/// Represents the software instance of Mastodon running on this domain.
/// Represents the software instance of Pixelfed running on this domain.
public struct Instance: Codable {
/// The domain name of the instance.
public let uri: String
/// The version of Mastodon installed on the instance.
/// The version of Pixelfed installed on the instance.
public let version: String
/// The title of the website.

View File

@ -6,11 +6,11 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func verifyCredentials() async throws -> Account {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.verifyCredentials,
target: Pixelfed.Account.verifyCredentials,
withBearerToken: token
)
@ -20,7 +20,7 @@ public extension MastodonClientAuthenticated {
func account(for accountId: String) async throws -> Account {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.account(accountId),
target: Pixelfed.Account.account(accountId),
withBearerToken: token
)
@ -30,7 +30,7 @@ public extension MastodonClientAuthenticated {
func relationships(for accountId: String) async throws -> Relationship? {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.relationships([accountId]),
target: Pixelfed.Account.relationships([accountId]),
withBearerToken: token
)
@ -47,7 +47,7 @@ public extension MastodonClientAuthenticated {
limit: Int = 40) async throws -> [Status] {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.statuses(accountId, onlyMedia, excludeReplies, maxId, sinceId, minId, limit),
target: Pixelfed.Account.statuses(accountId, onlyMedia, excludeReplies, maxId, sinceId, minId, limit),
withBearerToken: token
)
@ -57,7 +57,7 @@ public extension MastodonClientAuthenticated {
func follow(for accountId: String) async throws -> Relationship {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.follow(accountId),
target: Pixelfed.Account.follow(accountId),
withBearerToken: token
)
@ -67,7 +67,7 @@ public extension MastodonClientAuthenticated {
func unfollow(for accountId: String) async throws -> Relationship {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.unfollow(accountId),
target: Pixelfed.Account.unfollow(accountId),
withBearerToken: token
)
@ -77,7 +77,7 @@ public extension MastodonClientAuthenticated {
func mute(for accountId: String) async throws -> Relationship {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.mute(accountId),
target: Pixelfed.Account.mute(accountId),
withBearerToken: token
)
@ -87,7 +87,7 @@ public extension MastodonClientAuthenticated {
func unmute(for accountId: String) async throws -> Relationship {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.unmute(accountId),
target: Pixelfed.Account.unmute(accountId),
withBearerToken: token
)
@ -97,7 +97,7 @@ public extension MastodonClientAuthenticated {
func block(for accountId: String) async throws -> Relationship {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.block(accountId),
target: Pixelfed.Account.block(accountId),
withBearerToken: token
)
@ -107,7 +107,7 @@ public extension MastodonClientAuthenticated {
func unblock(for accountId: String) async throws -> Relationship {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.unblock(accountId),
target: Pixelfed.Account.unblock(accountId),
withBearerToken: token
)
@ -117,7 +117,7 @@ public extension MastodonClientAuthenticated {
func followers(for accountId: String, page: Int = 1) async throws -> [Account] {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.followers(accountId, nil, nil, nil, nil, page),
target: Pixelfed.Account.followers(accountId, nil, nil, nil, nil, page),
withBearerToken: token
)
@ -127,7 +127,7 @@ public extension MastodonClientAuthenticated {
func following(for accountId: String, page: Int = 1) async throws -> [Account] {
let request = try Self.request(
for: baseURL,
target: Mastodon.Account.following(accountId, nil, nil, nil, nil, page),
target: Pixelfed.Account.following(accountId, nil, nil, nil, nil, page),
withBearerToken: token
)
@ -141,7 +141,7 @@ public extension MastodonClientAuthenticated {
page: Page? = nil) async throws -> [Status] {
let request = try Self.request(
for: baseURL,
target: Mastodon.Favourites.favourites(maxId, sinceId, minId, limit, page),
target: Pixelfed.Favourites.favourites(maxId, sinceId, minId, limit, page),
withBearerToken: token
)
@ -155,7 +155,7 @@ public extension MastodonClientAuthenticated {
page: Page? = nil) async throws -> [Status] {
let request = try Self.request(
for: baseURL,
target: Mastodon.Bookmarks.bookmarks(maxId, sinceId, minId, limit, page),
target: Pixelfed.Bookmarks.bookmarks(maxId, sinceId, minId, limit, page),
withBearerToken: token
)

View File

@ -6,11 +6,11 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func getContext(for statusId: String) async throws -> Context {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.context(statusId),
target: Pixelfed.Statuses.context(statusId),
withBearerToken: token
)

View File

@ -8,7 +8,7 @@ import Foundation
import OAuthSwift
import AuthenticationServices
public extension MastodonClient {
public extension PixelfedClient {
/// Creates OAuth application in Pixelfed.
func createApp(named name: String,
@ -18,7 +18,7 @@ public extension MastodonClient {
let request = try Self.request(
for: baseURL,
target: Mastodon.Apps.register(
target: Pixelfed.Apps.register(
clientName: name,
redirectUris: redirectUri,
scopes: scopes.reduce("") { $0 == "" ? $1 : $0 + " " + $1},
@ -80,7 +80,7 @@ public extension MastodonClient {
oAuthHandle = oauthClient?.authorize(
withCallbackURL: app.redirectUri,
scope: scope.joined(separator: " "),
state: "MASToDON_AUTH",
state: "PixELfed_AUTH",
completionHandler: { result in
switch result {
case let .success((credentials, _, _)):

View File

@ -6,9 +6,9 @@
import Foundation
public extension MastodonClient {
public extension PixelfedClient {
func readInstanceInformation() async throws -> Instance {
let request = try Self.request(for: baseURL, target: Mastodon.Instances.instance)
let request = try Self.request(for: baseURL, target: Pixelfed.Instances.instance)
return try await downloadJson(Instance.self, request: request)
}
}

View File

@ -6,11 +6,11 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func upload(data: Data, fileName: String, mimeType: String) async throws -> UploadedAttachment {
let request = try Self.request(
for: baseURL,
target: Mastodon.Media.upload(data, fileName, mimeType),
target: Pixelfed.Media.upload(data, fileName, mimeType),
withBearerToken: token)
return try await downloadJson(UploadedAttachment.self, request: request)
@ -19,7 +19,7 @@ public extension MastodonClientAuthenticated {
func update(id: EntityId, description: String?, focus: CGPoint?) async throws -> UploadedAttachment {
let request = try Self.request(
for: baseURL,
target: Mastodon.Media.update(id, description, focus),
target: Pixelfed.Media.update(id, description, focus),
withBearerToken: token)
let (data, response) = try await urlSession.data(for: request)

View File

@ -6,14 +6,14 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func notifications(maxId: MaxId? = nil,
sinceId: SinceId? = nil,
minId: MinId? = nil,
limit: Int? = nil
) async throws -> Linkable<[Notification]> {
let request = try Self.request(for: baseURL,
target: Mastodon.Notifications.notifications(maxId, sinceId, minId, limit),
target: Pixelfed.Notifications.notifications(maxId, sinceId, minId, limit),
withBearerToken: token)
return try await downloadJsonWithLink([Notification].self, request: request)

View File

@ -6,12 +6,12 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func places(query: String) async throws -> [Place] {
let request = try Self.request(
for: baseURL,
target: Mastodon.Places.search(query),
target: Pixelfed.Places.search(query),
withBearerToken: token
)

View File

@ -6,12 +6,12 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func search(query: String, type: Mastodon.Search.ResultsType) async throws -> SearchResults {
func search(query: String, type: Pixelfed.Search.ResultsType) async throws -> SearchResults {
let request = try Self.request(
for: baseURL,
target: Mastodon.Search.search(query, type, false),
target: Pixelfed.Search.search(query, type, false),
withBearerToken: token
)

View File

@ -6,11 +6,11 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func status(statusId: EntityId) async throws -> Status {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.status(statusId),
target: Pixelfed.Statuses.status(statusId),
withBearerToken: token)
return try await downloadJson(Status.self, request: request)
@ -19,7 +19,7 @@ public extension MastodonClientAuthenticated {
func favouritedBy(for statusId: String, page: Int = 1) async throws -> [Account] {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.favouritedBy(statusId, nil, nil, nil, nil, page),
target: Pixelfed.Statuses.favouritedBy(statusId, nil, nil, nil, nil, page),
withBearerToken: token
)
@ -29,7 +29,7 @@ public extension MastodonClientAuthenticated {
func rebloggedBy(for statusId: String, page: Int = 1) async throws -> [Account] {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.rebloggedBy(statusId, nil, nil, nil, nil, page),
target: Pixelfed.Statuses.rebloggedBy(statusId, nil, nil, nil, nil, page),
withBearerToken: token
)

View File

@ -6,12 +6,12 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func boost(statusId: EntityId) async throws -> Status {
// TODO: Check whether the current user already boosted the status
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.reblog(statusId),
target: Pixelfed.Statuses.reblog(statusId),
withBearerToken: token
)
@ -21,7 +21,7 @@ public extension MastodonClientAuthenticated {
func unboost(statusId: EntityId) async throws -> Status {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.unreblog(statusId),
target: Pixelfed.Statuses.unreblog(statusId),
withBearerToken: token
)
@ -31,7 +31,7 @@ public extension MastodonClientAuthenticated {
func bookmark(statusId: EntityId) async throws -> Status {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.bookmark(statusId),
target: Pixelfed.Statuses.bookmark(statusId),
withBearerToken: token
)
@ -41,7 +41,7 @@ public extension MastodonClientAuthenticated {
func unbookmark(statusId: EntityId) async throws -> Status {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.unbookmark(statusId),
target: Pixelfed.Statuses.unbookmark(statusId),
withBearerToken: token
)
@ -51,7 +51,7 @@ public extension MastodonClientAuthenticated {
func favourite(statusId: EntityId) async throws -> Status {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.favourite(statusId),
target: Pixelfed.Statuses.favourite(statusId),
withBearerToken: token
)
@ -61,7 +61,7 @@ public extension MastodonClientAuthenticated {
func unfavourite(statusId: EntityId) async throws -> Status {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.unfavourite(statusId),
target: Pixelfed.Statuses.unfavourite(statusId),
withBearerToken: token
)
@ -71,7 +71,7 @@ public extension MastodonClientAuthenticated {
func pin(statusId: EntityId) async throws -> Status {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.pin(statusId),
target: Pixelfed.Statuses.pin(statusId),
withBearerToken: token
)
@ -81,17 +81,17 @@ public extension MastodonClientAuthenticated {
func unpin(statusId: EntityId) async throws -> Status {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.unpin(statusId),
target: Pixelfed.Statuses.unpin(statusId),
withBearerToken: token
)
return try await downloadJson(Status.self, request: request)
}
func new(statusComponents: Mastodon.Statuses.Components) async throws -> Status {
func new(statusComponents: Pixelfed.Statuses.Components) async throws -> Status {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.new(statusComponents),
target: Pixelfed.Statuses.new(statusComponents),
withBearerToken: token)
return try await downloadJson(Status.self, request: request)
@ -100,7 +100,7 @@ public extension MastodonClientAuthenticated {
func delete(statusId: EntityId) async throws {
let request = try Self.request(
for: baseURL,
target: Mastodon.Statuses.delete(statusId),
target: Pixelfed.Statuses.delete(statusId),
withBearerToken: token)
try await send(request: request)

View File

@ -6,12 +6,12 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func tag(hashtag: String) async throws -> Tag {
let request = try Self.request(
for: baseURL,
target: Mastodon.Tags.tag(hashtag),
target: Pixelfed.Tags.tag(hashtag),
withBearerToken: token
)
@ -21,7 +21,7 @@ public extension MastodonClientAuthenticated {
func follow(hashtag: String) async throws -> Tag {
let request = try Self.request(
for: baseURL,
target: Mastodon.Tags.follow(hashtag),
target: Pixelfed.Tags.follow(hashtag),
withBearerToken: token
)
@ -31,7 +31,7 @@ public extension MastodonClientAuthenticated {
func unfollow(hashtag: String) async throws -> Tag {
let request = try Self.request(
for: baseURL,
target: Mastodon.Tags.unfollow(hashtag),
target: Pixelfed.Tags.unfollow(hashtag),
withBearerToken: token
)

View File

@ -6,7 +6,7 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func getHomeTimeline(
maxId: EntityId? = nil,
sinceId: EntityId? = nil,
@ -15,7 +15,7 @@ public extension MastodonClientAuthenticated {
let request = try Self.request(
for: baseURL,
target: Mastodon.Timelines.home(maxId, sinceId, minId, limit),
target: Pixelfed.Timelines.home(maxId, sinceId, minId, limit),
withBearerToken: token
)
@ -32,7 +32,7 @@ public extension MastodonClientAuthenticated {
let request = try Self.request(
for: baseURL,
target: Mastodon.Timelines.pub(local, remote, onlyMedia, maxId, sinceId, minId, limit),
target: Pixelfed.Timelines.pub(local, remote, onlyMedia, maxId, sinceId, minId, limit),
withBearerToken: token
)
@ -51,27 +51,27 @@ public extension MastodonClientAuthenticated {
let request = try Self.request(
for: baseURL,
target: Mastodon.Timelines.tag(tag, local, remote, onlyMedia, maxId, sinceId, minId, limit),
target: Pixelfed.Timelines.tag(tag, local, remote, onlyMedia, maxId, sinceId, minId, limit),
withBearerToken: token
)
return try await downloadJson([Status].self, request: request)
}
func setMarkers(_ markers: [Mastodon.Markers.Timeline: EntityId]) async throws -> Markers {
func setMarkers(_ markers: [Pixelfed.Markers.Timeline: EntityId]) async throws -> Markers {
let request = try Self.request(
for: baseURL,
target: Mastodon.Markers.set(markers),
target: Pixelfed.Markers.set(markers),
withBearerToken: token
)
return try await downloadJson(Markers.self, request: request)
}
func readMarkers(_ markers: Set<Mastodon.Markers.Timeline>) async throws -> Markers {
func readMarkers(_ markers: Set<Pixelfed.Markers.Timeline>) async throws -> Markers {
let request = try Self.request(
for: baseURL,
target: Mastodon.Markers.read(markers),
target: Pixelfed.Markers.read(markers),
withBearerToken: token
)

View File

@ -6,12 +6,12 @@
import Foundation
public extension MastodonClientAuthenticated {
public extension PixelfedClientAuthenticated {
func statusesTrends(range: Mastodon.Trends.TrendRange) async throws -> [Status] {
func statusesTrends(range: Pixelfed.Trends.TrendRange) async throws -> [Status] {
let request = try Self.request(
for: baseURL,
target: Mastodon.Trends.statuses(range, nil, nil),
target: Pixelfed.Trends.statuses(range, nil, nil),
withBearerToken: token
)

View File

@ -7,15 +7,15 @@
import Foundation
import OAuthSwift
public enum MastodonClientError: Swift.Error {
public enum PixelfedClientError: Swift.Error {
case oAuthCancelled
}
public protocol MastodonClientProtocol {
public protocol PixelfedClientProtocol {
static func request(for baseURL: URL, target: TargetType, withBearerToken token: String?) throws -> URLRequest
}
public extension MastodonClientProtocol {
public extension PixelfedClientProtocol {
static func request(for baseURL: URL, target: TargetType, withBearerToken token: String? = nil) throws -> URLRequest {
var urlComponents = URLComponents(url: baseURL.appendingPathComponent(target.path), resolvingAgainstBaseURL: false)
@ -40,7 +40,7 @@ public extension MastodonClientProtocol {
}
}
public class MastodonClient: MastodonClientProtocol {
public class PixelfedClient: PixelfedClientProtocol {
let urlSession: URLSession
let baseURL: URL
@ -55,12 +55,12 @@ public class MastodonClient: MastodonClientProtocol {
self.urlSession = urlSession
}
public func getAuthenticated(token: Token) -> MastodonClientAuthenticated {
MastodonClientAuthenticated(baseURL: baseURL, urlSession: urlSession, token: token)
public func getAuthenticated(token: Token) -> PixelfedClientAuthenticated {
PixelfedClientAuthenticated(baseURL: baseURL, urlSession: urlSession, token: token)
}
deinit {
oAuthContinuation?.resume(throwing: MastodonClientError.oAuthCancelled)
oAuthContinuation?.resume(throwing: PixelfedClientError.oAuthCancelled)
oAuthHandle?.cancel()
}
@ -85,7 +85,7 @@ public class MastodonClient: MastodonClientProtocol {
}
}
public class MastodonClientAuthenticated: MastodonClientProtocol {
public class PixelfedClientAuthenticated: PixelfedClientProtocol {
public let token: Token
public let baseURL: URL

View File

@ -6,7 +6,7 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Account {
case account(EntityId)
case verifyCredentials
@ -24,7 +24,7 @@ extension Mastodon {
}
}
extension Mastodon.Account: TargetType {
extension Pixelfed.Account: TargetType {
fileprivate var apiPath: String { return "/api/v1/accounts" }
public var path: String {

View File

@ -6,13 +6,13 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Apps {
case register(clientName: String, redirectUris: String, scopes: String?, website: String?)
}
}
extension Mastodon.Apps: TargetType {
extension Pixelfed.Apps: TargetType {
struct Request: Encodable {
let clientName: String
let redirectUris: String
@ -27,11 +27,11 @@ extension Mastodon.Apps: TargetType {
}
func encode(to encoder: Encoder) throws {
var container: KeyedEncodingContainer<Mastodon.Apps.Request.CodingKeys> = encoder.container(keyedBy: Mastodon.Apps.Request.CodingKeys.self)
try container.encode(self.clientName, forKey: Mastodon.Apps.Request.CodingKeys.clientName)
try container.encode(self.redirectUris, forKey: Mastodon.Apps.Request.CodingKeys.redirectUris)
try container.encode(self.scopes, forKey: Mastodon.Apps.Request.CodingKeys.scopes)
try container.encode(self.website, forKey: Mastodon.Apps.Request.CodingKeys.website)
var container: KeyedEncodingContainer<Pixelfed.Apps.Request.CodingKeys> = encoder.container(keyedBy: Pixelfed.Apps.Request.CodingKeys.self)
try container.encode(self.clientName, forKey: Pixelfed.Apps.Request.CodingKeys.clientName)
try container.encode(self.redirectUris, forKey: Pixelfed.Apps.Request.CodingKeys.redirectUris)
try container.encode(self.scopes, forKey: Pixelfed.Apps.Request.CodingKeys.scopes)
try container.encode(self.website, forKey: Pixelfed.Apps.Request.CodingKeys.website)
}
}

View File

@ -6,13 +6,13 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Blocks {
case blocks
}
}
extension Mastodon.Blocks: TargetType {
extension Pixelfed.Blocks: TargetType {
fileprivate var apiPath: String { return "/api/v1/blocks" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,13 +6,13 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Bookmarks {
case bookmarks(MaxId?, SinceId?, MinId?, Limit?, Page?)
}
}
extension Mastodon.Bookmarks: TargetType {
extension Pixelfed.Bookmarks: TargetType {
fileprivate var apiPath: String { return "/api/v1/bookmarks" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,13 +6,13 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Favourites {
case favourites(MaxId?, SinceId?, MinId?, Limit?, Page?)
}
}
extension Mastodon.Favourites: TargetType {
extension Pixelfed.Favourites: TargetType {
fileprivate var apiPath: String { return "/api/v1/favourites" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,7 +6,7 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum FollowRequests {
case followRequests
case authorize(String)
@ -14,7 +14,7 @@ extension Mastodon {
}
}
extension Mastodon.FollowRequests: TargetType {
extension Pixelfed.FollowRequests: TargetType {
fileprivate var apiPath: String { return "/api/v1/follow_requests" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,13 +6,13 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Follows {
case follow(String)
}
}
extension Mastodon.Follows: TargetType {
extension Pixelfed.Follows: TargetType {
fileprivate var apiPath: String { return "/api/v1/follows" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,13 +6,13 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Instances {
case instance
}
}
extension Mastodon.Instances: TargetType {
extension Pixelfed.Instances: TargetType {
fileprivate var apiPath: String { return "/api/v1/instance" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,7 +6,7 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Markers {
public enum Timeline: String, Encodable {
case home
@ -18,7 +18,7 @@ extension Mastodon {
}
}
extension Mastodon.Markers: TargetType {
extension Pixelfed.Markers: TargetType {
fileprivate var apiPath: String { return "/api/v1/markers" }
public var path: String {

View File

@ -8,14 +8,14 @@ import Foundation
fileprivate let multipartBoundary = UUID().uuidString
extension Mastodon {
extension Pixelfed {
public enum Media {
case upload(Data, String, String)
case update(EntityId, String?, CGPoint?)
}
}
extension Mastodon.Media: TargetType {
extension Pixelfed.Media: TargetType {
struct Request: Encodable {
let description: String?
let focus: String?
@ -26,9 +26,9 @@ extension Mastodon.Media: TargetType {
}
func encode(to encoder: Encoder) throws {
var container: KeyedEncodingContainer<Mastodon.Media.Request.CodingKeys> = encoder.container(keyedBy: Mastodon.Media.Request.CodingKeys.self)
try container.encode(self.description, forKey: Mastodon.Media.Request.CodingKeys.description)
try container.encodeIfPresent(self.focus, forKey: Mastodon.Media.Request.CodingKeys.focus)
var container: KeyedEncodingContainer<Pixelfed.Media.Request.CodingKeys> = encoder.container(keyedBy: Pixelfed.Media.Request.CodingKeys.self)
try container.encode(self.description, forKey: Pixelfed.Media.Request.CodingKeys.description)
try container.encodeIfPresent(self.focus, forKey: Pixelfed.Media.Request.CodingKeys.focus)
}
}

View File

@ -6,13 +6,13 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Mutes {
case mutes
}
}
extension Mastodon.Mutes: TargetType {
extension Pixelfed.Mutes: TargetType {
fileprivate var apiPath: String { return "/api/v1/mutes" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,7 +6,7 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Notifications {
case notifications(MaxId?, SinceId?, MinId?, Limit?)
case notification(String)
@ -14,7 +14,7 @@ extension Mastodon {
}
}
extension Mastodon.Notifications: TargetType {
extension Pixelfed.Notifications: TargetType {
fileprivate var apiPath: String { return "/api/v1/notifications" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,13 +6,13 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum OAuth {
case authenticate(Application, UsernameType, PasswordType, String?)
}
}
extension Mastodon.OAuth: TargetType {
extension Pixelfed.OAuth: TargetType {
struct Request: Encodable {
let clientId: String
let clientSecret: String
@ -31,13 +31,13 @@ extension Mastodon.OAuth: TargetType {
}
func encode(to encoder: Encoder) throws {
var container: KeyedEncodingContainer<Mastodon.OAuth.Request.CodingKeys> = encoder.container(keyedBy: Mastodon.OAuth.Request.CodingKeys.self)
try container.encode(self.clientId, forKey: Mastodon.OAuth.Request.CodingKeys.clientId)
try container.encode(self.clientSecret, forKey: Mastodon.OAuth.Request.CodingKeys.clientSecret)
try container.encode(self.grantType, forKey: Mastodon.OAuth.Request.CodingKeys.grantType)
try container.encode(self.username, forKey: Mastodon.OAuth.Request.CodingKeys.username)
try container.encode(self.password, forKey: Mastodon.OAuth.Request.CodingKeys.password)
try container.encode(self.scope, forKey: Mastodon.OAuth.Request.CodingKeys.scope)
var container: KeyedEncodingContainer<Pixelfed.OAuth.Request.CodingKeys> = encoder.container(keyedBy: Pixelfed.OAuth.Request.CodingKeys.self)
try container.encode(self.clientId, forKey: Pixelfed.OAuth.Request.CodingKeys.clientId)
try container.encode(self.clientSecret, forKey: Pixelfed.OAuth.Request.CodingKeys.clientSecret)
try container.encode(self.grantType, forKey: Pixelfed.OAuth.Request.CodingKeys.grantType)
try container.encode(self.username, forKey: Pixelfed.OAuth.Request.CodingKeys.username)
try container.encode(self.password, forKey: Pixelfed.OAuth.Request.CodingKeys.password)
try container.encode(self.scope, forKey: Pixelfed.OAuth.Request.CodingKeys.scope)
}
}

View File

@ -6,5 +6,5 @@
import Foundation
public class Mastodon {
public class Pixelfed {
}

View File

@ -6,13 +6,13 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Places {
case search(SearchQuery)
}
}
extension Mastodon.Places: TargetType {
extension Pixelfed.Places: TargetType {
fileprivate var apiPath: String { return "/api/v1.1/compose/search/location" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,14 +6,14 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Reports {
case list
case report(String, [String], String)
}
}
extension Mastodon.Reports: TargetType {
extension Pixelfed.Reports: TargetType {
private struct Request: Encodable {
let accountId: String
let statusIds: [String]
@ -26,10 +26,10 @@ extension Mastodon.Reports: TargetType {
}
func encode(to encoder: Encoder) throws {
var container: KeyedEncodingContainer<Mastodon.Reports.Request.CodingKeys> = encoder.container(keyedBy: Mastodon.Reports.Request.CodingKeys.self)
try container.encode(self.accountId, forKey: Mastodon.Reports.Request.CodingKeys.accountId)
try container.encode(self.statusIds, forKey: Mastodon.Reports.Request.CodingKeys.statusIds)
try container.encode(self.comment, forKey: Mastodon.Reports.Request.CodingKeys.comment)
var container: KeyedEncodingContainer<Pixelfed.Reports.Request.CodingKeys> = encoder.container(keyedBy: Pixelfed.Reports.Request.CodingKeys.self)
try container.encode(self.accountId, forKey: Pixelfed.Reports.Request.CodingKeys.accountId)
try container.encode(self.statusIds, forKey: Pixelfed.Reports.Request.CodingKeys.statusIds)
try container.encode(self.comment, forKey: Pixelfed.Reports.Request.CodingKeys.comment)
}
}

View File

@ -6,14 +6,14 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Search {
case search(SearchQuery, ResultsType, Bool)
}
}
extension Mastodon.Search: TargetType {
extension Pixelfed.Search: TargetType {
public enum ResultsType: String {
case accounts = "accounts"
case hashtags = "hashtags"

View File

@ -6,7 +6,7 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Statuses {
public enum Visibility: String, Encodable {
case priv = "private"
@ -32,7 +32,7 @@ extension Mastodon {
}
}
extension Mastodon.Statuses {
extension Pixelfed.Statuses {
public struct Components {
public let inReplyToId: EntityId?
public let text: String
@ -67,7 +67,7 @@ extension Mastodon.Statuses {
}
}
extension Mastodon.Statuses: TargetType {
extension Pixelfed.Statuses: TargetType {
struct Request: Encodable {
let status: String
let inReplyToId: String?
@ -92,16 +92,16 @@ extension Mastodon.Statuses: TargetType {
}
func encode(to encoder: Encoder) throws {
var container: KeyedEncodingContainer<Mastodon.Statuses.Request.CodingKeys> = encoder.container(keyedBy: Mastodon.Statuses.Request.CodingKeys.self)
try container.encode(self.status, forKey: Mastodon.Statuses.Request.CodingKeys.status)
try container.encode(self.inReplyToId, forKey: Mastodon.Statuses.Request.CodingKeys.inReplyToId)
try container.encode(self.mediaIds, forKey: Mastodon.Statuses.Request.CodingKeys.mediaIds)
try container.encode(self.sensitive, forKey: Mastodon.Statuses.Request.CodingKeys.sensitive)
try container.encodeIfPresent(self.spoilerText, forKey: Mastodon.Statuses.Request.CodingKeys.spoilerText)
try container.encode(self.visibility, forKey: Mastodon.Statuses.Request.CodingKeys.visibility)
try container.encodeIfPresent(self.placeId, forKey: Mastodon.Statuses.Request.CodingKeys.placeId)
try container.encode(self.commentsDisabled, forKey: Mastodon.Statuses.Request.CodingKeys.commentsDisabled)
try container.encodeIfPresent(self.collectionIds, forKey: Mastodon.Statuses.Request.CodingKeys.collectionIds)
var container: KeyedEncodingContainer<Pixelfed.Statuses.Request.CodingKeys> = encoder.container(keyedBy: Pixelfed.Statuses.Request.CodingKeys.self)
try container.encode(self.status, forKey: Pixelfed.Statuses.Request.CodingKeys.status)
try container.encode(self.inReplyToId, forKey: Pixelfed.Statuses.Request.CodingKeys.inReplyToId)
try container.encode(self.mediaIds, forKey: Pixelfed.Statuses.Request.CodingKeys.mediaIds)
try container.encode(self.sensitive, forKey: Pixelfed.Statuses.Request.CodingKeys.sensitive)
try container.encodeIfPresent(self.spoilerText, forKey: Pixelfed.Statuses.Request.CodingKeys.spoilerText)
try container.encode(self.visibility, forKey: Pixelfed.Statuses.Request.CodingKeys.visibility)
try container.encodeIfPresent(self.placeId, forKey: Pixelfed.Statuses.Request.CodingKeys.placeId)
try container.encode(self.commentsDisabled, forKey: Pixelfed.Statuses.Request.CodingKeys.commentsDisabled)
try container.encodeIfPresent(self.collectionIds, forKey: Pixelfed.Statuses.Request.CodingKeys.collectionIds)
}
}

View File

@ -6,7 +6,7 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Tags {
case tag(Hashtag)
case follow(Hashtag)
@ -14,7 +14,7 @@ extension Mastodon {
}
}
extension Mastodon.Tags: TargetType {
extension Pixelfed.Tags: TargetType {
fileprivate var apiPath: String { return "/api/v1/tags" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,7 +6,7 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Timelines {
case home(MaxId?, SinceId?, MinId?, Limit?)
case pub(Bool, Bool, Bool, MaxId?, SinceId?, MinId?, Limit?)
@ -14,7 +14,7 @@ extension Mastodon {
}
}
extension Mastodon.Timelines: TargetType {
extension Pixelfed.Timelines: TargetType {
fileprivate var apiPath: String { return "/api/v1/timelines" }
/// The path to be appended to `baseURL` to form the full `URL`.

View File

@ -6,7 +6,7 @@
import Foundation
extension Mastodon {
extension Pixelfed {
public enum Trends {
case tags(TrendRange?, Offset?, Limit?)
case statuses(TrendRange?, Offset?, Limit?)
@ -14,7 +14,7 @@ extension Mastodon {
}
}
extension Mastodon.Trends: TargetType {
extension Pixelfed.Trends: TargetType {
public enum TrendRange: String {
case daily = "daily"
case monthly = "monthly"

View File

@ -1,11 +1,11 @@
import XCTest
@testable import MastodonKit
@testable import PixelfedKit
final class MastodonKitTests: XCTestCase {
final class PixelfedKitTests: XCTestCase {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(MastodonKit().text, "Hello, World!")
// XCTAssertEqual(PixelfedKit().text, "Hello, World!")
}
}

View File

@ -7,16 +7,16 @@
import Foundation
import PixelfedKit
/// Mastodon 'Account'.
/// Pixelfed 'Account'.
extension Client {
public class Accounts: BaseClient {
public func account(withId accountId: String) async throws -> Account? {
return try await mastodonClient.account(for: accountId)
return try await pixelfedClient.account(for: accountId)
}
public func relationships(withId accountId: String) async throws -> Relationship? {
return try await mastodonClient.relationships(for: accountId)
return try await pixelfedClient.relationships(for: accountId)
}
public func statuses(createdBy accountId: String,
@ -26,7 +26,7 @@ extension Client {
sinceId: String? = nil,
minId: String? = nil,
limit: Int = 40) async throws -> [Status] {
return try await mastodonClient.statuses(for: accountId,
return try await pixelfedClient.statuses(for: accountId,
onlyMedia: onlyMedia,
excludeReplies: excludeReplies,
maxId: maxId,
@ -36,35 +36,35 @@ extension Client {
}
public func follow(account accountId: String) async throws -> Relationship? {
return try await mastodonClient.follow(for: accountId)
return try await pixelfedClient.follow(for: accountId)
}
public func unfollow(account accountId: String) async throws -> Relationship? {
return try await mastodonClient.unfollow(for: accountId)
return try await pixelfedClient.unfollow(for: accountId)
}
public func mute(account accountId: String) async throws -> Relationship? {
return try await mastodonClient.mute(for: accountId)
return try await pixelfedClient.mute(for: accountId)
}
public func unmute(account accountId: String) async throws -> Relationship? {
return try await mastodonClient.unmute(for: accountId)
return try await pixelfedClient.unmute(for: accountId)
}
public func block(account accountId: String) async throws -> Relationship? {
return try await mastodonClient.block(for: accountId)
return try await pixelfedClient.block(for: accountId)
}
public func unblock(account accountId: String) async throws -> Relationship? {
return try await mastodonClient.unblock(for: accountId)
return try await pixelfedClient.unblock(for: accountId)
}
public func followers(account accountId: String, page: Int) async throws -> [Account] {
return try await mastodonClient.followers(for: accountId, page: page)
return try await pixelfedClient.followers(for: accountId, page: page)
}
public func following(account accountId: String, page: Int) async throws -> [Account] {
return try await mastodonClient.following(for: accountId, page: page)
return try await pixelfedClient.following(for: accountId, page: page)
}
public func favourites(maxId: String? = nil,
@ -72,7 +72,7 @@ extension Client {
minId: String? = nil,
limit: Int = 10,
page: Int? = nil) async throws -> [Status] {
return try await mastodonClient.favourites(limit: limit, page: page)
return try await pixelfedClient.favourites(limit: limit, page: page)
}
public func bookmarks(maxId: String? = nil,
@ -80,7 +80,7 @@ extension Client {
minId: String? = nil,
limit: Int = 10,
page: Int? = nil) async throws -> [Status] {
return try await mastodonClient.bookmarks(limit: limit, page: page)
return try await pixelfedClient.bookmarks(limit: limit, page: page)
}
}
}

View File

@ -7,7 +7,7 @@
import Foundation
import PixelfedKit
/// Mastodon 'Search'.
/// Pixelfed 'Search'.
extension Client {
public class Instances {
private let urlJson = URL(string: "https://raw.githubusercontent.com/VernissageApp/Home/main/instances.json")!
@ -57,7 +57,7 @@ extension Client {
group.addTask {
do {
if let baseUrl = URL(string: url) {
let client = MastodonClient(baseURL: baseUrl)
let client = PixelfedClient(baseURL: baseUrl)
return try await client.readInstanceInformation()
}
@ -80,7 +80,7 @@ extension Client {
}
func instance(url: URL) async throws -> Instance {
let client = MastodonClient(baseURL: url)
let client = PixelfedClient(baseURL: url)
return try await client.readInstanceInformation()
}

View File

@ -7,15 +7,15 @@
import Foundation
import PixelfedKit
/// Mastodon 'Statuses'.
/// Pixelfed 'Statuses'.
extension Client {
public class Media: BaseClient {
func upload(data: Data, fileName: String, mimeType: String) async throws -> UploadedAttachment? {
return try await mastodonClient.upload(data: data, fileName: fileName, mimeType: mimeType)
return try await pixelfedClient.upload(data: data, fileName: fileName, mimeType: mimeType)
}
func update(id: String, description: String?, focus: CGPoint?) async throws -> UploadedAttachment? {
return try await mastodonClient.update(id: id, description: description, focus: focus)
return try await pixelfedClient.update(id: id, description: description, focus: focus)
}
}
}

View File

@ -7,7 +7,7 @@
import Foundation
import PixelfedKit
/// Mastodon 'Notifications'.
/// Pixelfed 'Notifications'.
extension Client {
public class Notifications: BaseClient {
public func notifications(maxId: MaxId? = nil,
@ -15,7 +15,7 @@ extension Client {
minId: MinId? = nil,
limit: Int? = nil
) async throws -> Linkable<[PixelfedKit.Notification]> {
return try await mastodonClient.notifications(maxId: maxId, sinceId: sinceId, minId: minId, limit: limit)
return try await pixelfedClient.notifications(maxId: maxId, sinceId: sinceId, minId: minId, limit: limit)
}
}
}

View File

@ -7,11 +7,11 @@
import Foundation
import PixelfedKit
/// Mastodon 'Places'.
/// Pixelfed 'Places'.
extension Client {
public class Places: BaseClient {
public func search(query: String) async throws -> [Place] {
return try await mastodonClient.places(query: query)
return try await pixelfedClient.places(query: query)
}
}
}

View File

@ -7,11 +7,11 @@
import Foundation
import PixelfedKit
/// Mastodon 'Search'.
/// Pixelfed 'Search'.
extension Client {
public class Search: BaseClient {
public func search(query: String, resultsType: Mastodon.Search.ResultsType) async throws -> SearchResults? {
return try await mastodonClient.search(query: query, type: resultsType)
public func search(query: String, resultsType: Pixelfed.Search.ResultsType) async throws -> SearchResults? {
return try await pixelfedClient.search(query: query, type: resultsType)
}
}
}

View File

@ -7,52 +7,52 @@
import Foundation
import PixelfedKit
/// Mastodon 'Statuses'.
/// Pixelfed 'Statuses'.
extension Client {
public class Statuses: BaseClient {
public func status(withId statusId: String) async throws -> Status {
return try await mastodonClient.status(statusId: statusId)
return try await pixelfedClient.status(statusId: statusId)
}
func favourite(statusId: String) async throws -> Status? {
return try await mastodonClient.favourite(statusId: statusId)
return try await pixelfedClient.favourite(statusId: statusId)
}
func unfavourite(statusId: String) async throws -> Status? {
return try await mastodonClient.unfavourite(statusId: statusId)
return try await pixelfedClient.unfavourite(statusId: statusId)
}
func pin(statusId: String) async throws -> Status? {
return try await mastodonClient.pin(statusId: statusId)
return try await pixelfedClient.pin(statusId: statusId)
}
func unpin(statusId: String) async throws -> Status? {
return try await mastodonClient.unpin(statusId: statusId)
return try await pixelfedClient.unpin(statusId: statusId)
}
func boost(statusId: String) async throws -> Status? {
return try await mastodonClient.boost(statusId: statusId)
return try await pixelfedClient.boost(statusId: statusId)
}
func unboost(statusId: String) async throws -> Status? {
return try await mastodonClient.unboost(statusId: statusId)
return try await pixelfedClient.unboost(statusId: statusId)
}
func bookmark(statusId: String) async throws -> Status? {
return try await mastodonClient.bookmark(statusId: statusId)
return try await pixelfedClient.bookmark(statusId: statusId)
}
func unbookmark(statusId: String) async throws -> Status? {
return try await mastodonClient.unbookmark(statusId: statusId)
return try await pixelfedClient.unbookmark(statusId: statusId)
}
func new(status: Mastodon.Statuses.Components) async throws -> Status? {
return try await mastodonClient.new(statusComponents: status)
func new(status: Pixelfed.Statuses.Components) async throws -> Status? {
return try await pixelfedClient.new(statusComponents: status)
}
func delete(statusId: String) async throws {
try await mastodonClient.delete(statusId: statusId)
try await pixelfedClient.delete(statusId: statusId)
}
func comments(to statusId: String) async throws -> [CommentModel] {
@ -64,15 +64,15 @@ extension Client {
}
public func favouritedBy(statusId: String, page: Int) async throws -> [Account] {
return try await mastodonClient.favouritedBy(for: statusId, page: page)
return try await pixelfedClient.favouritedBy(for: statusId, page: page)
}
public func rebloggedBy(statusId: String, page: Int) async throws -> [Account] {
return try await mastodonClient.rebloggedBy(for: statusId, page: page)
return try await pixelfedClient.rebloggedBy(for: statusId, page: page)
}
private func getCommentDescendants(to statusId: String, showDivider: Bool, to commentViewModels: inout [CommentModel]) async throws {
let context = try await mastodonClient.getContext(for: statusId)
let context = try await pixelfedClient.getContext(for: statusId)
let descendants = context.descendants.toStatusViewModel()
for status in descendants {

View File

@ -7,19 +7,19 @@
import Foundation
import PixelfedKit
/// Mastodon 'Tags'.
/// Pixelfed 'Tags'.
extension Client {
public class Tags: BaseClient {
public func get(tag: String) async throws -> Tag? {
return try await mastodonClient.tag(hashtag: tag)
return try await pixelfedClient.tag(hashtag: tag)
}
public func follow(tag: String) async throws -> Tag? {
return try await mastodonClient.follow(hashtag: tag)
return try await pixelfedClient.follow(hashtag: tag)
}
public func unfollow(tag: String) async throws -> Tag? {
return try await mastodonClient.unfollow(hashtag: tag)
return try await pixelfedClient.unfollow(hashtag: tag)
}
}
}

View File

@ -7,7 +7,7 @@
import Foundation
import PixelfedKit
/// Mastodon 'Timeline'.
/// Pixelfed 'Timeline'.
extension Client {
public class PublicTimeline: BaseClient {
public func getStatuses(local: Bool,
@ -16,7 +16,7 @@ extension Client {
sinceId: String? = nil,
minId: String? = nil,
limit: Int = 40) async throws -> [Status] {
return try await mastodonClient.getPublicTimeline(local: local,
return try await pixelfedClient.getPublicTimeline(local: local,
remote: remote,
onlyMedia: true,
maxId: maxId,
@ -32,7 +32,7 @@ extension Client {
sinceId: String? = nil,
minId: String? = nil,
limit: Int = 40) async throws -> [Status] {
return try await mastodonClient.getTagTimeline(tag: tag,
return try await pixelfedClient.getTagTimeline(tag: tag,
local: local,
remote: remote,
onlyMedia: true,

View File

@ -7,11 +7,11 @@
import Foundation
import PixelfedKit
/// Mastodon 'Trends'.
/// Pixelfed 'Trends'.
extension Client {
public class Trends: BaseClient {
public func statuses(range: Mastodon.Trends.TrendRange) async throws -> [Status] {
return try await mastodonClient.statusesTrends(range: range)
public func statuses(range: Pixelfed.Trends.TrendRange) async throws -> [Status] {
return try await pixelfedClient.statusesTrends(range: range)
}
}
}

View File

@ -11,38 +11,38 @@ public class Client: ObservableObject {
public static let shared = Client()
private init() { }
private var mastodonClient: MastodonClientAuthenticated?
private var pixelfedClient: PixelfedClientAuthenticated?
func setAccount(account: AccountModel) {
guard let accessToken = account.accessToken else {
return
}
self.mastodonClient = MastodonClient(baseURL: account.serverUrl).getAuthenticated(token: accessToken)
self.pixelfedClient = PixelfedClient(baseURL: account.serverUrl).getAuthenticated(token: accessToken)
}
}
extension Client {
public var trends: Trends? { return Trends(mastodonClient: self.mastodonClient) }
public var publicTimeline: PublicTimeline? { return PublicTimeline(mastodonClient: self.mastodonClient) }
public var tags: Tags? { return Tags(mastodonClient: self.mastodonClient) }
public var notifications: Notifications? { return Notifications(mastodonClient: self.mastodonClient) }
public var statuses: Statuses? { return Statuses(mastodonClient: self.mastodonClient) }
public var media: Media? { return Media(mastodonClient: self.mastodonClient) }
public var accounts: Accounts? { return Accounts(mastodonClient: self.mastodonClient) }
public var search: Search? { return Search(mastodonClient: self.mastodonClient) }
public var places: Places? { return Places(mastodonClient: self.mastodonClient) }
public var trends: Trends? { return Trends(pixelfedClient: self.pixelfedClient) }
public var publicTimeline: PublicTimeline? { return PublicTimeline(pixelfedClient: self.pixelfedClient) }
public var tags: Tags? { return Tags(pixelfedClient: self.pixelfedClient) }
public var notifications: Notifications? { return Notifications(pixelfedClient: self.pixelfedClient) }
public var statuses: Statuses? { return Statuses(pixelfedClient: self.pixelfedClient) }
public var media: Media? { return Media(pixelfedClient: self.pixelfedClient) }
public var accounts: Accounts? { return Accounts(pixelfedClient: self.pixelfedClient) }
public var search: Search? { return Search(pixelfedClient: self.pixelfedClient) }
public var places: Places? { return Places(pixelfedClient: self.pixelfedClient) }
public var instances: Instances { return Instances() }
}
public class BaseClient {
public var mastodonClient: MastodonClientAuthenticated
public var pixelfedClient: PixelfedClientAuthenticated
init?(mastodonClient: MastodonClientAuthenticated?) {
guard let mastodonClient else {
init?(pixelfedClient: PixelfedClientAuthenticated?) {
guard let pixelfedClient else {
return nil
}
self.mastodonClient = mastodonClient
self.pixelfedClient = pixelfedClient
}
}

View File

@ -22,7 +22,7 @@ public class AuthorizationService {
}
// When we have at least one account then we have to verify access token.
let client = MastodonClient(baseURL: currentAccount.serverUrl).getAuthenticated(token: accessToken)
let client = PixelfedClient(baseURL: currentAccount.serverUrl).getAuthenticated(token: accessToken)
do {
let account = try await client.verifyCredentials()
@ -49,7 +49,7 @@ public class AuthorizationService {
throw AuthorisationError.badServerUrl
}
let client = MastodonClient(baseURL: baseUrl)
let client = PixelfedClient(baseURL: baseUrl)
// Verify address.
_ = try await client.readInstanceInformation()
@ -148,7 +148,7 @@ public class AuthorizationService {
}
private func refreshAccessToken(accountData: AccountData) async throws {
let client = MastodonClient(baseURL: accountData.serverUrl)
let client = PixelfedClient(baseURL: accountData.serverUrl)
guard let refreshToken = accountData.refreshToken else {
return
@ -173,7 +173,7 @@ public class AuthorizationService {
presentationContextProvider: ASWebAuthenticationPresentationContextProviding
) async throws {
let client = MastodonClient(baseURL: accountData.serverUrl)
let client = PixelfedClient(baseURL: accountData.serverUrl)
// Create application (we will get clientId and clientSecret).
let oAuthApp = Application(clientId: accountData.clientId,

View File

@ -96,7 +96,7 @@ public class HomeTimelineService {
return 0
}
let client = MastodonClient(baseURL: account.serverUrl).getAuthenticated(token: accessToken)
let client = PixelfedClient(baseURL: account.serverUrl).getAuthenticated(token: accessToken)
var amountOfStatuses = 0
var newestStatusId = newestStatus.id
@ -124,7 +124,7 @@ public class HomeTimelineService {
}
// Retrieve statuses from API.
let client = MastodonClient(baseURL: account.serverUrl).getAuthenticated(token: accessToken)
let client = PixelfedClient(baseURL: account.serverUrl).getAuthenticated(token: accessToken)
let statuses = try await client.getHomeTimeline(limit: 40)
// Retrieve all statuses from database.
@ -169,7 +169,7 @@ public class HomeTimelineService {
}
// Retrieve statuses from API.
let client = MastodonClient(baseURL: account.serverUrl).getAuthenticated(token: accessToken)
let client = PixelfedClient(baseURL: account.serverUrl).getAuthenticated(token: accessToken)
let statuses = try await client.getHomeTimeline(maxId: maxId, minId: minId, limit: 20)
// Save statuses in database.

View File

@ -72,7 +72,7 @@ class RouterPath: ObservableObject {
public func navigateToAccountFrom(acct: String, url: URL) async {
Task {
let results = try? await Client.shared.search?.search(query: acct, resultsType: Mastodon.Search.ResultsType.accounts)
let results = try? await Client.shared.search?.search(query: acct, resultsType: Pixelfed.Search.ResultsType.accounts)
if let accountFromApi = results?.accounts.first {
navigate(to: .userProfile(accountId: accountFromApi.id,

View File

@ -17,7 +17,7 @@ struct ComposeView: View {
@State var statusViewModel: StatusModel?
@State private var text = String.empty()
@State private var visibility = Mastodon.Statuses.Visibility.pub
@State private var visibility = Pixelfed.Statuses.Visibility.pub
@State private var isSensitive = false
@State private var spoilerText = String.empty()
@State private var commentsDisabled = false
@ -260,17 +260,17 @@ struct ComposeView: View {
HStack {
Image(systemName: "globe.europe.africa")
Text(" Everyone")
}.tag(Mastodon.Statuses.Visibility.pub)
}.tag(Pixelfed.Statuses.Visibility.pub)
HStack {
Image(systemName: "lock.open")
Text(" Unlisted")
}.tag(Mastodon.Statuses.Visibility.unlisted)
}.tag(Pixelfed.Statuses.Visibility.unlisted)
HStack {
Image(systemName: "lock")
Text(" Followers")
}.tag(Mastodon.Statuses.Visibility.priv)
}.tag(Pixelfed.Statuses.Visibility.priv)
}.buttonStyle(.bordered)
}
}
@ -368,8 +368,8 @@ struct ComposeView: View {
}
}
private func createStatus() -> Mastodon.Statuses.Components {
return Mastodon.Statuses.Components(inReplyToId: self.statusViewModel?.id,
private func createStatus() -> Pixelfed.Statuses.Components {
return Pixelfed.Statuses.Components(inReplyToId: self.statusViewModel?.id,
text: self.text,
spoilerText: self.isSensitive ? self.spoilerText : String.empty(),
mediaIds: self.photosAttachment.getUploadedPhotoIds(),

View File

@ -13,16 +13,16 @@ struct TrendStatusesView: View {
@State public var accountId: String
@State private var tabSelectedValue: Mastodon.Trends.TrendRange = .daily
@State private var tabSelectedValue: Pixelfed.Trends.TrendRange = .daily
@State private var statusViewModels: [StatusModel] = []
@State private var state: ViewState = .loading
var body: some View {
ScrollView {
Picker(selection: $tabSelectedValue, label: Text("")) {
Text("Daily").tag(Mastodon.Trends.TrendRange.daily)
Text("Monthly").tag(Mastodon.Trends.TrendRange.monthly)
Text("Yearly").tag(Mastodon.Trends.TrendRange.yearly)
Text("Daily").tag(Pixelfed.Trends.TrendRange.daily)
Text("Monthly").tag(Pixelfed.Trends.TrendRange.monthly)
Text("Yearly").tag(Pixelfed.Trends.TrendRange.yearly)
}
.padding()