Remove PollLegacy from Core Data (IOS-182)

This commit is contained in:
Nathan Mattes 2024-06-07 09:51:55 +02:00
parent d12624a0f5
commit e668b21da5
6 changed files with 0 additions and 371 deletions

View File

@ -123,21 +123,6 @@
<relationship name="showingReblogs" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="showingReblogsBy" inverseEntity="MastodonUser"/>
<relationship name="showingReblogsBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="showingReblogs" inverseEntity="MastodonUser"/>
<relationship name="statuses" toMany="YES" deletionRule="Nullify" destinationEntity="Status" inverseName="author" inverseEntity="Status"/>
<relationship name="votePolls" toMany="YES" deletionRule="Nullify" destinationEntity="Poll" inverseName="votedBy" inverseEntity="Poll"/>
</entity>
<entity name="Poll" representedClassName="CoreDataStack.Poll" syncable="YES">
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="domain" attributeType="String" defaultValueString=""/>
<attribute name="expired" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="expiresAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="id" attributeType="String"/>
<attribute name="isVoting" transient="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="multiple" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="updatedAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="votersCount" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="votesCount" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<relationship name="status" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="poll" inverseEntity="Status"/>
<relationship name="votedBy" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="votePolls" inverseEntity="MastodonUser"/>
</entity>
<entity name="Setting" representedClassName="CoreDataStack.Setting" syncable="YES">
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
@ -182,7 +167,6 @@
<relationship name="feeds" toMany="YES" deletionRule="Cascade" destinationEntity="Feed" inverseName="status" inverseEntity="Feed"/>
<relationship name="mutedBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="muted" inverseEntity="MastodonUser"/>
<relationship name="pinnedBy" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="pinnedStatus" inverseEntity="MastodonUser"/>
<relationship name="poll" optional="YES" maxCount="1" deletionRule="Cascade" destinationEntity="Poll" inverseName="status" inverseEntity="Poll"/>
<relationship name="reblog" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="reblogFrom" inverseEntity="Status"/>
<relationship name="reblogFrom" toMany="YES" deletionRule="Cascade" destinationEntity="Status" inverseName="reblog" inverseEntity="Status"/>
<relationship name="rebloggedBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="reblogged" inverseEntity="MastodonUser"/>

View File

@ -72,7 +72,6 @@ final public class MastodonUser: NSManagedObject {
@NSManaged public private(set) var reblogged: Set<Status>
@NSManaged public private(set) var muted: Set<Status>
@NSManaged public private(set) var bookmarked: Set<Status>
@NSManaged public private(set) var votePolls: Set<PollLegacy>
// relationships
@NSManaged public private(set) var following: Set<MastodonUser>
@NSManaged public private(set) var followingBy: Set<MastodonUser>

View File

@ -1,316 +0,0 @@
//
// Poll.swift
// CoreDataStack
//
// Created by MainasuK Cirno on 2021-3-2.
//
import Foundation
import CoreData
public final class PollLegacy: NSManagedObject {
public typealias ID = String
// sourcery: autoGenerateProperty
@NSManaged public private(set) var domain: String
// sourcery: autoGenerateProperty
@NSManaged public private(set) var id: ID
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public private(set) var expiresAt: Date?
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public private(set) var expired: Bool
// sourcery: autoGenerateProperty
@NSManaged public private(set) var multiple: Bool
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public private(set) var votesCount: Int64
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public private(set) var votersCount: Int64
// sourcery: autoGenerateProperty
@NSManaged public private(set) var createdAt: Date
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public private(set) var updatedAt: Date
// sourcery: autoUpdatableObject
@NSManaged public private(set) var isVoting: Bool
// one-to-one relationship
@NSManaged public private(set) var status: Status?
// many-to-many relationship
@NSManaged public private(set) var votedBy: Set<MastodonUser>?
}
extension PollLegacy {
@discardableResult
public static func insert(
into context: NSManagedObjectContext,
property: Property
) -> PollLegacy {
let object: PollLegacy = context.insertObject()
object.configure(property: property)
return object
}
}
extension PollLegacy: Managed {
public static var defaultSortDescriptors: [NSSortDescriptor] {
return [NSSortDescriptor(keyPath: \PollLegacy.createdAt, ascending: false)]
}
}
extension PollLegacy {
static func predicate(domain: String) -> NSPredicate {
return NSPredicate(format: "%K == %@", #keyPath(PollLegacy.domain), domain)
}
static func predicate(id: ID) -> NSPredicate {
return NSPredicate(format: "%K == %@", #keyPath(PollLegacy.id), id)
}
static func predicate(ids: [ID]) -> NSPredicate {
return NSPredicate(format: "%K IN %@", #keyPath(PollLegacy.id), ids)
}
public static func predicate(domain: String, id: ID) -> NSPredicate {
return NSCompoundPredicate(andPredicateWithSubpredicates: [
predicate(domain: domain),
predicate(id: id)
])
}
public static func predicate(domain: String, ids: [ID]) -> NSPredicate {
return NSCompoundPredicate(andPredicateWithSubpredicates: [
predicate(domain: domain),
predicate(ids: ids)
])
}
}
//extension Poll {
//
// public override func awakeFromInsert() {
// super.awakeFromInsert()
// setPrimitiveValue(Date(), forKey: #keyPath(Poll.createdAt))
// }
//
// @discardableResult
// public static func insert(
// into context: NSManagedObjectContext,
// property: Property,
// votedBy: MastodonUser?,
// options: [PollOption]
// ) -> Poll {
// let poll: Poll = context.insertObject()
//
// poll.id = property.id
// poll.expiresAt = property.expiresAt
// poll.expired = property.expired
// poll.multiple = property.multiple
// poll.votesCount = property.votesCount
// poll.votersCount = property.votersCount
//
//
// poll.updatedAt = property.networkDate
//
// if let votedBy = votedBy {
// poll.mutableSetValue(forKey: #keyPath(Poll.votedBy)).add(votedBy)
// }
// poll.mutableSetValue(forKey: #keyPath(Poll.options)).addObjects(from: options)
//
// return poll
// }
//
// public func update(expiresAt: Date?) {
// if self.expiresAt != expiresAt {
// self.expiresAt = expiresAt
// }
// }
//
// public func update(expired: Bool) {
// if self.expired != expired {
// self.expired = expired
// }
// }
//
// public func update(votesCount: Int) {
// if self.votesCount.intValue != votesCount {
// self.votesCount = NSNumber(value: votesCount)
// }
// }
//
// public func update(votersCount: Int?) {
// if self.votersCount?.intValue != votersCount {
// self.votersCount = votersCount.flatMap { NSNumber(value: $0) }
// }
// }
//
// public func update(voted: Bool, by: MastodonUser) {
// if voted {
// if !(votedBy ?? Set()).contains(by) {
// mutableSetValue(forKey: #keyPath(Poll.votedBy)).add(by)
// }
// } else {
// if (votedBy ?? Set()).contains(by) {
// mutableSetValue(forKey: #keyPath(Poll.votedBy)).remove(by)
// }
// }
// }
//
// public func didUpdate(at networkDate: Date) {
// self.updatedAt = networkDate
// }
//
//}
//extension Poll {
// public struct Property {
// public let id: ID
// public let expiresAt: Date?
// public let expired: Bool
// public let multiple: Bool
// public let votesCount: NSNumber
// public let votersCount: NSNumber?
//
// public let networkDate: Date
//
// public init(
// id: Poll.ID,
// expiresAt: Date?,
// expired: Bool,
// multiple: Bool,
// votesCount: Int,
// votersCount: Int?,
// networkDate: Date
// ) {
// self.id = id
// self.expiresAt = expiresAt
// self.expired = expired
// self.multiple = multiple
// self.votesCount = NSNumber(value: votesCount)
// self.votersCount = votersCount.flatMap { NSNumber(value: $0) }
// self.networkDate = networkDate
// }
// }
//}
// MARK: - AutoGenerateProperty
extension PollLegacy: AutoGenerateProperty {
// sourcery:inline:Poll.AutoGenerateProperty
// Generated using Sourcery
// DO NOT EDIT
public struct Property {
public let domain: String
public let id: ID
public let expiresAt: Date?
public let expired: Bool
public let multiple: Bool
public let votesCount: Int64
public let votersCount: Int64
public let createdAt: Date
public let updatedAt: Date
public init(
domain: String,
id: ID,
expiresAt: Date?,
expired: Bool,
multiple: Bool,
votesCount: Int64,
votersCount: Int64,
createdAt: Date,
updatedAt: Date
) {
self.domain = domain
self.id = id
self.expiresAt = expiresAt
self.expired = expired
self.multiple = multiple
self.votesCount = votesCount
self.votersCount = votersCount
self.createdAt = createdAt
self.updatedAt = updatedAt
}
}
public func configure(property: Property) {
self.domain = property.domain
self.id = property.id
self.expiresAt = property.expiresAt
self.expired = property.expired
self.multiple = property.multiple
self.votesCount = property.votesCount
self.votersCount = property.votersCount
self.createdAt = property.createdAt
self.updatedAt = property.updatedAt
}
public func update(property: Property) {
update(expiresAt: property.expiresAt)
update(expired: property.expired)
update(votesCount: property.votesCount)
update(votersCount: property.votersCount)
update(updatedAt: property.updatedAt)
}
// sourcery:end
}
// MARK: - AutoUpdatableObject
extension PollLegacy: AutoUpdatableObject {
// sourcery:inline:Poll.AutoUpdatableObject
// Generated using Sourcery
// DO NOT EDIT
public func update(expiresAt: Date?) {
if self.expiresAt != expiresAt {
self.expiresAt = expiresAt
}
}
public func update(expired: Bool) {
if self.expired != expired {
self.expired = expired
}
}
public func update(votesCount: Int64) {
if self.votesCount != votesCount {
self.votesCount = votesCount
}
}
public func update(votersCount: Int64) {
if self.votersCount != votersCount {
self.votersCount = votersCount
}
}
public func update(updatedAt: Date) {
if self.updatedAt != updatedAt {
self.updatedAt = updatedAt
}
}
public func update(isVoting: Bool) {
if self.isVoting != isVoting {
self.isVoting = isVoting
}
}
// sourcery:end
public func update(voted: Bool, by: MastodonUser) {
if voted {
if !(votedBy ?? Set()).contains(by) {
mutableSetValue(forKey: #keyPath(PollLegacy.votedBy)).add(by)
}
} else {
if (votedBy ?? Set()).contains(by) {
mutableSetValue(forKey: #keyPath(PollLegacy.votedBy)).remove(by)
}
}
}
}

View File

@ -77,8 +77,6 @@ public final class Status: NSManagedObject {
// sourcery: autoUpdatableObject
@NSManaged public private(set) var replyTo: Status?
// sourcery: autoGenerateRelationship
@NSManaged public private(set) var poll: PollLegacy?
// sourcery: autoGenerateRelationship
@NSManaged public private(set) var card: Card?
@ -379,18 +377,15 @@ extension Status: AutoGenerateRelationship {
public struct Relationship {
public let application: Application?
public let reblog: Status?
public let poll: PollLegacy?
public let card: Card?
public init(
application: Application?,
reblog: Status?,
poll: PollLegacy?,
card: Card?
) {
self.application = application
self.reblog = reblog
self.poll = poll
self.card = card
}
}
@ -398,7 +393,6 @@ extension Status: AutoGenerateRelationship {
public func configure(relationship: Relationship) {
self.application = relationship.application
self.reblog = relationship.reblog
self.poll = relationship.poll
self.card = relationship.card
}
// sourcery:end

View File

@ -1,30 +0,0 @@
//
// MastodonPoll.swift
//
//
// Created by MainasuK on 2021-12-9.
//
import Foundation
import CoreDataStack
import MastodonSDK
extension PollLegacy.Property {
public init(
entity: Mastodon.Entity.Poll,
domain: String,
networkDate: Date
) {
self.init(
domain: domain,
id: entity.id,
expiresAt: entity.expiresAt,
expired: entity.expired,
multiple: entity.multiple,
votesCount: Int64(entity.votesCount),
votersCount: Int64(entity.votersCount ?? 0),
createdAt: networkDate,
updatedAt: networkDate
)
}
}

View File

@ -79,7 +79,6 @@ extension Persistence.Status {
isNewInsertion: false
)
} else {
var poll: PollLegacy? = nil
let card = createCard(in: managedObjectContext, context: context)
@ -88,7 +87,6 @@ extension Persistence.Status {
let relationship = Status.Relationship(
application: application,
reblog: reblog,
poll: poll,
card: card
)
let status = create(