Remove more users (IOS-192)

This commit is contained in:
Nathan Mattes 2024-02-14 16:51:24 +01:00
parent 7024823cbf
commit cb3a90b5be
3 changed files with 2 additions and 391 deletions

View File

@ -366,20 +366,8 @@ extension MainTabBarController {
guard let authContext = authContext else { return }
Task { @MainActor in
let profileResponse = try await context.apiService.authenticatedUserInfo(
authenticationBox: authContext.mastodonAuthenticationBox
)
if let user = authContext.mastodonAuthenticationBox.authentication.user(
in: context.managedObjectContext
) {
user.update(
property: .init(
entity: profileResponse.value,
domain: authContext.mastodonAuthenticationBox.domain
)
)
}
let profileResponse = try await context.apiService.authenticatedUserInfo(authenticationBox: authContext.mastodonAuthenticationBox)
FileManager.default.store(account: profileResponse.value, forUserID: authContext.mastodonAuthenticationBox.authentication.userIdentifier())
}
}
}

View File

@ -143,20 +143,6 @@ extension MastodonUser {
}
}
extension MastodonUser {
@discardableResult
public static func insert(
into context: NSManagedObjectContext,
property: Property
) -> MastodonUser {
let object: MastodonUser = context.insertObject()
object.configure(property: property)
return object
}
}
extension MastodonUser: Managed {
public static var defaultSortDescriptors: [NSSortDescriptor] {
return [NSSortDescriptor(keyPath: \MastodonUser.createdAt, ascending: false)]
@ -209,324 +195,4 @@ extension MastodonUser {
public static func predicate(followRequestedBy userID: String) -> NSPredicate {
NSPredicate(format: "ANY %K.%K == %@", #keyPath(MastodonUser.followRequestedBy), #keyPath(MastodonUser.id), userID)
}
}
// MARK: - AutoGenerateProperty
extension MastodonUser: AutoGenerateProperty {
// sourcery:inline:MastodonUser.AutoGenerateProperty
// Generated using Sourcery
// DO NOT EDIT
public struct Property {
public let identifier: String
public let domain: String
public let id: String
public let acct: String
public let username: String
public let displayName: String
public let avatar: String
public let avatarStatic: String?
public let header: String
public let headerStatic: String?
public let note: String?
public let url: String?
public let statusesCount: Int64
public let followingCount: Int64
public let followersCount: Int64
public let locked: Bool
public let bot: Bool
public let suspended: Bool
public let createdAt: Date
public let updatedAt: Date
public let emojis: [MastodonEmoji]
public let fields: [MastodonField]
public init(
identifier: String,
domain: String,
id: String,
acct: String,
username: String,
displayName: String,
avatar: String,
avatarStatic: String?,
header: String,
headerStatic: String?,
note: String?,
url: String?,
statusesCount: Int64,
followingCount: Int64,
followersCount: Int64,
locked: Bool,
bot: Bool,
suspended: Bool,
createdAt: Date,
updatedAt: Date,
emojis: [MastodonEmoji],
fields: [MastodonField]
) {
self.identifier = identifier
self.domain = domain
self.id = id
self.acct = acct
self.username = username
self.displayName = displayName
self.avatar = avatar
self.avatarStatic = avatarStatic
self.header = header
self.headerStatic = headerStatic
self.note = note
self.url = url
self.statusesCount = statusesCount
self.followingCount = followingCount
self.followersCount = followersCount
self.locked = locked
self.bot = bot
self.suspended = suspended
self.createdAt = createdAt
self.updatedAt = updatedAt
self.emojis = emojis
self.fields = fields
}
}
public func configure(property: Property) {
self.identifier = property.identifier
self.domain = property.domain
self.id = property.id
self.acct = property.acct
self.username = property.username
self.displayName = property.displayName
self.avatar = property.avatar
self.avatarStatic = property.avatarStatic
self.header = property.header
self.headerStatic = property.headerStatic
self.note = property.note
self.url = property.url
self.statusesCount = property.statusesCount
self.followingCount = property.followingCount
self.followersCount = property.followersCount
self.locked = property.locked
self.bot = property.bot
self.suspended = property.suspended
self.createdAt = property.createdAt
self.updatedAt = property.updatedAt
self.emojis = property.emojis
self.fields = property.fields
}
public func update(property: Property) {
update(acct: property.acct)
update(username: property.username)
update(displayName: property.displayName)
update(avatar: property.avatar)
update(avatarStatic: property.avatarStatic)
update(header: property.header)
update(headerStatic: property.headerStatic)
update(note: property.note)
update(url: property.url)
update(statusesCount: property.statusesCount)
update(followingCount: property.followingCount)
update(followersCount: property.followersCount)
update(locked: property.locked)
update(bot: property.bot)
update(suspended: property.suspended)
update(createdAt: property.createdAt)
update(updatedAt: property.updatedAt)
update(emojis: property.emojis)
update(fields: property.fields)
}
// sourcery:end
}
// MARK: - AutoUpdatableObject
extension MastodonUser: AutoUpdatableObject {
// sourcery:inline:MastodonUser.AutoUpdatableObject
// Generated using Sourcery
// DO NOT EDIT
public func update(acct: String) {
if self.acct != acct {
self.acct = acct
}
}
public func update(username: String) {
if self.username != username {
self.username = username
}
}
public func update(displayName: String) {
if self.displayName != displayName {
self.displayName = displayName
}
}
public func update(avatar: String) {
if self.avatar != avatar {
self.avatar = avatar
}
}
public func update(avatarStatic: String?) {
if self.avatarStatic != avatarStatic {
self.avatarStatic = avatarStatic
}
}
public func update(header: String) {
if self.header != header {
self.header = header
}
}
public func update(headerStatic: String?) {
if self.headerStatic != headerStatic {
self.headerStatic = headerStatic
}
}
public func update(note: String?) {
if self.note != note {
self.note = note
}
}
public func update(url: String?) {
if self.url != url {
self.url = url
}
}
public func update(statusesCount: Int64) {
if self.statusesCount != statusesCount {
self.statusesCount = statusesCount
}
}
public func update(followingCount: Int64) {
if self.followingCount != followingCount {
self.followingCount = followingCount
}
}
public func update(followersCount: Int64) {
if self.followersCount != followersCount {
self.followersCount = followersCount
}
}
public func update(locked: Bool) {
if self.locked != locked {
self.locked = locked
}
}
public func update(bot: Bool) {
if self.bot != bot {
self.bot = bot
}
}
public func update(suspended: Bool) {
if self.suspended != suspended {
self.suspended = suspended
}
}
public func update(createdAt: Date) {
if self.createdAt != createdAt {
self.createdAt = createdAt
}
}
public func update(updatedAt: Date) {
if self.updatedAt != updatedAt {
self.updatedAt = updatedAt
}
}
public func update(emojis: [MastodonEmoji]) {
if self.emojis != emojis {
self.emojis = emojis
}
}
public func update(fields: [MastodonField]) {
if self.fields != fields {
self.fields = fields
}
}
// sourcery:end
public func update(isFollowing: Bool, by mastodonUser: MastodonUser) {
if isFollowing {
if !self.followingBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.followingBy)).add(mastodonUser)
}
} else {
if self.followingBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.followingBy)).remove(mastodonUser)
}
}
}
public func update(isFollowRequested: Bool, by mastodonUser: MastodonUser) {
if isFollowRequested {
if !self.followRequestedBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.followRequestedBy)).add(mastodonUser)
}
} else {
if self.followRequestedBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.followRequestedBy)).remove(mastodonUser)
}
}
}
public func update(isMuting: Bool, by mastodonUser: MastodonUser) {
if isMuting {
if !self.mutingBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.mutingBy)).add(mastodonUser)
}
} else {
if self.mutingBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.mutingBy)).remove(mastodonUser)
}
}
}
public func update(isBlocking: Bool, by mastodonUser: MastodonUser) {
if isBlocking {
if !self.blockingBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.blockingBy)).add(mastodonUser)
}
} else {
if self.blockingBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.blockingBy)).remove(mastodonUser)
}
}
}
public func update(isEndorsed: Bool, by mastodonUser: MastodonUser) {
if isEndorsed {
if !self.endorsedBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.endorsedBy)).add(mastodonUser)
}
} else {
if self.endorsedBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.endorsedBy)).remove(mastodonUser)
}
}
}
public func update(isDomainBlocking: Bool, by mastodonUser: MastodonUser) {
if isDomainBlocking {
if !self.domainBlockingBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.domainBlockingBy)).add(mastodonUser)
}
} else {
if self.domainBlockingBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.domainBlockingBy)).remove(mastodonUser)
}
}
}
public func update(isShowingReblogs: Bool, by mastodonUser: MastodonUser) {
if isShowingReblogs {
if !self.showingReblogsBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.showingReblogsBy)).add(mastodonUser)
}
} else {
if self.showingReblogsBy.contains(mastodonUser) {
self.mutableSetValue(forKey: #keyPath(MastodonUser.showingReblogsBy)).remove(mastodonUser)
}
}
}
}
extension MastodonUser {
public var verifiedLink: MastodonField? {
let firstVerified = fields.first(where: { $0.verifiedAt != nil })
return firstVerified
}
}

View File

@ -1,43 +0,0 @@
//
// MastodonUser+Property.swift
// Mastodon
//
// Created by MainasuK on 2022-1-11.
//
import Foundation
import CoreDataStack
import MastodonSDK
extension MastodonUser.Property {
public init(entity: Mastodon.Entity.Account, domain: String) {
self.init(entity: entity, domain: domain, networkDate: Date())
}
init(entity: Mastodon.Entity.Account, domain: String, networkDate: Date) {
self.init(
identifier: entity.id + "@" + domain,
domain: domain,
id: entity.id,
acct: entity.acct,
username: entity.username,
displayName: entity.displayName,
avatar: entity.avatar,
avatarStatic: entity.avatarStatic,
header: entity.header,
headerStatic: entity.headerStatic,
note: entity.note,
url: entity.url,
statusesCount: Int64(entity.statusesCount),
followingCount: Int64(entity.followingCount),
followersCount: Int64(entity.followersCount),
locked: entity.locked,
bot: entity.bot ?? false,
suspended: entity.suspended ?? false,
createdAt: entity.createdAt,
updatedAt: networkDate,
emojis: entity.mastodonEmojis,
fields: entity.mastodonFields
)
}
}