Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Service/APIService/APIService+UserTimeline.swift

71 lines
2.2 KiB
Swift
Raw Normal View History

2021-04-01 08:39:15 +02:00
//
// APIService+UserTimeline.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-3-30.
//
import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {
func userTimeline(
domain: String,
accountID: String,
maxID: Mastodon.Entity.Status.ID? = nil,
sinceID: Mastodon.Entity.Status.ID? = nil,
limit: Int = onceRequestStatusMaxCount,
excludeReplies: Bool? = nil,
excludeReblogs: Bool? = nil,
onlyMedia: Bool? = nil,
authorizationBox: MastodonAuthenticationBox
2021-04-01 08:39:15 +02:00
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Status]>, Error> {
let authorization = authorizationBox.userAuthorization
let requestMastodonUserID = authorizationBox.userID
2021-06-14 23:09:50 +02:00
let query = Mastodon.API.Account.AccountStatusesQuery(
2021-04-01 08:39:15 +02:00
maxID: maxID,
sinceID: sinceID,
excludeReplies: excludeReplies,
excludeReblogs: excludeReblogs,
onlyMedia: onlyMedia,
limit: limit
)
return Mastodon.API.Account.statuses(
session: session,
domain: domain,
accountID: accountID,
query: query,
authorization: authorization
)
.flatMap { response -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Status]>, Error> in
return APIService.Persist.persistStatus(
managedObjectContext: self.backgroundManagedObjectContext,
domain: domain,
query: nil,
response: response,
persistType: .user,
requestMastodonUserID: requestMastodonUserID,
log: OSLog.api
)
.setFailureType(to: Error.self)
.tryMap { result -> Mastodon.Response.Content<[Mastodon.Entity.Status]> in
switch result {
case .success:
return response
case .failure(let error):
throw error
}
}
.eraseToAnyPublisher()
}
.eraseToAnyPublisher()
}
}