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

61 lines
1.8 KiB
Swift
Raw Normal View History

2021-11-01 12:54:07 +01:00
//
// APIService+Follower.swift
// Mastodon
//
// Created by Cirno MainasuK on 2021-11-1.
//
import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {
func followers(
userID: Mastodon.Entity.Account.ID,
maxID: String?,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<[Mastodon.Entity.Account]> {
let domain = authenticationBox.domain
let authorization = authenticationBox.userAuthorization
2021-11-01 12:54:07 +01:00
let query = Mastodon.API.Account.FollowerQuery(
maxID: maxID,
limit: nil
)
let response = try await Mastodon.API.Account.followers(
2021-11-01 12:54:07 +01:00
session: session,
domain: domain,
userID: userID,
query: query,
2021-11-01 12:54:07 +01:00
authorization: authorization
).singleOutput()
let managedObjectContext = self.backgroundManagedObjectContext
try await managedObjectContext.performChanges {
let me = authenticationBox.authenticationRecord.object(in: managedObjectContext)?.user
for entity in response.value {
let result = Persistence.MastodonUser.createOrMerge(
in: managedObjectContext,
context: Persistence.MastodonUser.PersistContext(
domain: domain,
2021-11-01 12:54:07 +01:00
entity: entity,
cache: nil,
networkDate: response.networkDate
2021-11-01 12:54:07 +01:00
)
)
let user = result.user
me?.update(isFollowing: true, by: user)
2021-11-01 12:54:07 +01:00
}
}
return response
2021-11-01 12:54:07 +01:00
}
}