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

110 lines
3.6 KiB
Swift

//
// APIService+Recommend.swift
// Mastodon
//
// Created by sxiaojian on 2021/3/31.
//
import Combine
import Foundation
import MastodonSDK
import CoreData
import CoreDataStack
import OSLog
extension APIService {
func suggestionAccount(
query: Mastodon.API.Suggestions.Query?,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<[Mastodon.Entity.Account]> {
let response = try await Mastodon.API.Suggestions.accounts(
session: session,
domain: authenticationBox.domain,
query: query,
authorization: authenticationBox.userAuthorization
).singleOutput()
let managedObjectContext = backgroundManagedObjectContext
try await managedObjectContext.performChanges {
for entity in response.value {
_ = Persistence.MastodonUser.createOrMerge(
in: managedObjectContext,
context: Persistence.MastodonUser.PersistContext(
domain: authenticationBox.domain,
entity: entity,
cache: nil,
networkDate: response.networkDate
)
)
} // end for in
}
return response
}
func suggestionAccountV2(
query: Mastodon.API.Suggestions.Query?,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<[Mastodon.Entity.V2.SuggestionAccount]> {
let response = try await Mastodon.API.V2.Suggestions.accounts(
session: session,
domain: authenticationBox.domain,
query: query,
authorization: authenticationBox.userAuthorization
).singleOutput()
let managedObjectContext = backgroundManagedObjectContext
try await managedObjectContext.performChanges {
for entity in response.value {
_ = Persistence.MastodonUser.createOrMerge(
in: managedObjectContext,
context: Persistence.MastodonUser.PersistContext(
domain: authenticationBox.domain,
entity: entity.account,
cache: nil,
networkDate: response.networkDate
)
)
} // end for in
}
return response
}
}
extension APIService {
func familiarFollowers(
query: Mastodon.API.Account.FamiliarFollowersQuery,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<[Mastodon.Entity.Account]> {
let response = try await Mastodon.API.Account.familiarFollowers(
session: session,
domain: authenticationBox.domain,
query: query,
authorization: authenticationBox.userAuthorization
).singleOutput()
// let managedObjectContext = backgroundManagedObjectContext
// try await managedObjectContext.performChanges {
// for entity in response.value {
// _ = Persistence.MastodonUser.createOrMerge(
// in: managedObjectContext,
// context: Persistence.MastodonUser.PersistContext(
// domain: authenticationBox.domain,
// entity: entity.account,
// cache: nil,
// networkDate: response.networkDate
// )
// )
// } // end for in
// }
return response
}
}