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(
|
|
|
|
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,
|
2022-01-27 14:23:39 +01:00
|
|
|
authenticationBox: MastodonAuthenticationBox
|
|
|
|
) async throws -> Mastodon.Response.Content<[Mastodon.Entity.Status]> {
|
|
|
|
let domain = authenticationBox.domain
|
|
|
|
let authorization = authenticationBox.userAuthorization
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
let response = try await Mastodon.API.Account.statuses(
|
2021-04-01 08:39:15 +02:00
|
|
|
session: session,
|
|
|
|
domain: domain,
|
|
|
|
accountID: accountID,
|
|
|
|
query: query,
|
|
|
|
authorization: authorization
|
2022-01-27 14:23:39 +01:00
|
|
|
).singleOutput()
|
|
|
|
|
|
|
|
let managedObjectContext = self.backgroundManagedObjectContext
|
|
|
|
try await managedObjectContext.performChanges {
|
|
|
|
let me = authenticationBox.authenticationRecord.object(in: managedObjectContext)?.user
|
|
|
|
for entity in response.value {
|
2022-04-29 07:35:03 +02:00
|
|
|
_ = Persistence.Status.createOrMerge(
|
2022-01-27 14:23:39 +01:00
|
|
|
in: managedObjectContext,
|
|
|
|
context: Persistence.Status.PersistContext(
|
|
|
|
domain: domain,
|
|
|
|
entity: entity,
|
|
|
|
me: me,
|
|
|
|
statusCache: nil,
|
|
|
|
userCache: nil,
|
|
|
|
networkDate: response.networkDate
|
|
|
|
)
|
|
|
|
)
|
2021-04-01 08:39:15 +02:00
|
|
|
}
|
|
|
|
}
|
2022-01-27 14:23:39 +01:00
|
|
|
|
|
|
|
return response
|
|
|
|
} // end func
|
2021-04-01 08:39:15 +02:00
|
|
|
|
|
|
|
}
|