mirror of
https://github.com/mastodon/mastodon-ios
synced 2025-04-11 22:58:02 +02:00
chore: add index meta and missing reverse relationship for SearchHistory
This commit is contained in:
parent
9b99796475
commit
ccd26c144f
@ -85,7 +85,7 @@
|
||||
<attribute name="typeRaw" attributeType="String"/>
|
||||
<attribute name="updatedAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="userID" attributeType="String"/>
|
||||
<relationship name="account" maxCount="1" deletionRule="Nullify" destinationEntity="MastodonUser"/>
|
||||
<relationship name="account" maxCount="1" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="notifications" inverseEntity="MastodonUser"/>
|
||||
<relationship name="status" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="inNotifications" inverseEntity="Status"/>
|
||||
<uniquenessConstraints>
|
||||
<uniquenessConstraint>
|
||||
@ -132,6 +132,7 @@
|
||||
<relationship name="muted" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Status" inverseName="mutedBy" inverseEntity="Status"/>
|
||||
<relationship name="muting" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="mutingBy" inverseEntity="MastodonUser"/>
|
||||
<relationship name="mutingBy" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="muting" inverseEntity="MastodonUser"/>
|
||||
<relationship name="notifications" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonNotification" inverseName="account" inverseEntity="MastodonNotification"/>
|
||||
<relationship name="pinnedStatus" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="pinnedBy" inverseEntity="Status"/>
|
||||
<relationship name="privateNotes" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="PrivateNote" inverseName="to" inverseEntity="PrivateNote"/>
|
||||
<relationship name="privateNotesTo" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="PrivateNote" inverseName="from" inverseEntity="PrivateNote"/>
|
||||
@ -181,8 +182,10 @@
|
||||
</entity>
|
||||
<entity name="SearchHistory" representedClassName=".SearchHistory" syncable="YES">
|
||||
<attribute name="createAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="domain" attributeType="String" defaultValueString=""/>
|
||||
<attribute name="identifier" attributeType="UUID" usesScalarValueType="NO"/>
|
||||
<attribute name="updatedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="userID" attributeType="String" defaultValueString=""/>
|
||||
<relationship name="account" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="searchHistory" inverseEntity="MastodonUser"/>
|
||||
<relationship name="hashtag" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Tag" inverseName="searchHistory" inverseEntity="Tag"/>
|
||||
<relationship name="status" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="searchHistory" inverseEntity="Status"/>
|
||||
@ -281,12 +284,12 @@
|
||||
<element name="HomeTimelineIndex" positionX="0" positionY="0" width="128" height="134"/>
|
||||
<element name="MastodonAuthentication" positionX="0" positionY="0" width="128" height="209"/>
|
||||
<element name="MastodonNotification" positionX="9" positionY="162" width="128" height="164"/>
|
||||
<element name="MastodonUser" positionX="0" positionY="0" width="128" height="719"/>
|
||||
<element name="MastodonUser" positionX="0" positionY="0" width="128" height="734"/>
|
||||
<element name="Mention" positionX="0" positionY="0" width="128" height="149"/>
|
||||
<element name="Poll" positionX="0" positionY="0" width="128" height="194"/>
|
||||
<element name="PollOption" positionX="0" positionY="0" width="128" height="134"/>
|
||||
<element name="PrivateNote" positionX="0" positionY="0" width="128" height="89"/>
|
||||
<element name="SearchHistory" positionX="0" positionY="0" width="128" height="119"/>
|
||||
<element name="SearchHistory" positionX="0" positionY="0" width="128" height="149"/>
|
||||
<element name="Setting" positionX="72" positionY="162" width="128" height="164"/>
|
||||
<element name="Status" positionX="0" positionY="0" width="128" height="614"/>
|
||||
<element name="Subscription" positionX="81" positionY="171" width="128" height="179"/>
|
||||
|
@ -47,6 +47,7 @@ final public class MastodonUser: NSManagedObject {
|
||||
|
||||
// one-to-many relationship
|
||||
@NSManaged public private(set) var statuses: Set<Status>?
|
||||
@NSManaged public private(set) var notifications: Set<MastodonNotification>?
|
||||
|
||||
// many-to-many relationship
|
||||
@NSManaged public private(set) var favourite: Set<Status>?
|
||||
|
@ -11,6 +11,8 @@ import CoreData
|
||||
public final class SearchHistory: NSManagedObject {
|
||||
public typealias ID = UUID
|
||||
@NSManaged public private(set) var identifier: ID
|
||||
@NSManaged public private(set) var domain: String
|
||||
@NSManaged public private(set) var userID: MastodonUser.ID
|
||||
@NSManaged public private(set) var createAt: Date
|
||||
@NSManaged public private(set) var updatedAt: Date
|
||||
|
||||
@ -37,9 +39,12 @@ extension SearchHistory {
|
||||
@discardableResult
|
||||
public static func insert(
|
||||
into context: NSManagedObjectContext,
|
||||
property: Property,
|
||||
account: MastodonUser
|
||||
) -> SearchHistory {
|
||||
let searchHistory: SearchHistory = context.insertObject()
|
||||
searchHistory.domain = property.domain
|
||||
searchHistory.userID = property.userID
|
||||
searchHistory.account = account
|
||||
return searchHistory
|
||||
}
|
||||
@ -47,9 +52,12 @@ extension SearchHistory {
|
||||
@discardableResult
|
||||
public static func insert(
|
||||
into context: NSManagedObjectContext,
|
||||
property: Property,
|
||||
hashtag: Tag
|
||||
) -> SearchHistory {
|
||||
let searchHistory: SearchHistory = context.insertObject()
|
||||
searchHistory.domain = property.domain
|
||||
searchHistory.userID = property.userID
|
||||
searchHistory.hashtag = hashtag
|
||||
return searchHistory
|
||||
}
|
||||
@ -57,20 +65,35 @@ extension SearchHistory {
|
||||
@discardableResult
|
||||
public static func insert(
|
||||
into context: NSManagedObjectContext,
|
||||
property: Property,
|
||||
status: Status
|
||||
) -> SearchHistory {
|
||||
let searchHistory: SearchHistory = context.insertObject()
|
||||
searchHistory.domain = property.domain
|
||||
searchHistory.userID = property.userID
|
||||
searchHistory.status = status
|
||||
return searchHistory
|
||||
}
|
||||
}
|
||||
|
||||
public extension SearchHistory {
|
||||
func update(updatedAt: Date) {
|
||||
extension SearchHistory {
|
||||
public func update(updatedAt: Date) {
|
||||
setValue(updatedAt, forKey: #keyPath(SearchHistory.updatedAt))
|
||||
}
|
||||
}
|
||||
|
||||
extension SearchHistory {
|
||||
public struct Property {
|
||||
public let domain: String
|
||||
public let userID: MastodonUser.ID
|
||||
|
||||
public init(domain: String, userID: MastodonUser.ID) {
|
||||
self.domain = domain
|
||||
self.userID = userID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension SearchHistory: Managed {
|
||||
public static var defaultSortDescriptors: [NSSortDescriptor] {
|
||||
return [NSSortDescriptor(keyPath: \SearchHistory.updatedAt, ascending: false)]
|
||||
|
@ -12,7 +12,7 @@
|
||||
<key>CoreDataStack.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>21</integer>
|
||||
<integer>22</integer>
|
||||
</dict>
|
||||
<key>Mastodon - ASDK.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
@ -37,12 +37,12 @@
|
||||
<key>NotificationService.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>22</integer>
|
||||
<integer>23</integer>
|
||||
</dict>
|
||||
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>23</integer>
|
||||
<integer>21</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
|
@ -81,6 +81,9 @@ extension SearchHistoryViewModel {
|
||||
|
||||
extension SearchHistoryViewModel {
|
||||
func persistSearchHistory(for item: SearchHistoryItem) {
|
||||
guard let box = context.authenticationService.activeMastodonAuthenticationBox.value else { return }
|
||||
let property = SearchHistory.Property(domain: box.domain, userID: box.userID)
|
||||
|
||||
switch item {
|
||||
case .account(let objectID):
|
||||
let managedObjectContext = context.backgroundManagedObjectContext
|
||||
@ -89,7 +92,7 @@ extension SearchHistoryViewModel {
|
||||
if let searchHistory = user.searchHistory {
|
||||
searchHistory.update(updatedAt: Date())
|
||||
} else {
|
||||
SearchHistory.insert(into: managedObjectContext, account: user)
|
||||
SearchHistory.insert(into: managedObjectContext, property: property, account: user)
|
||||
}
|
||||
}
|
||||
.sink { result in
|
||||
@ -104,7 +107,7 @@ extension SearchHistoryViewModel {
|
||||
if let searchHistory = hashtag.searchHistory {
|
||||
searchHistory.update(updatedAt: Date())
|
||||
} else {
|
||||
SearchHistory.insert(into: managedObjectContext, hashtag: hashtag)
|
||||
SearchHistory.insert(into: managedObjectContext, property: property, hashtag: hashtag)
|
||||
}
|
||||
}
|
||||
.sink { result in
|
||||
|
@ -142,6 +142,7 @@ extension SearchResultViewModel {
|
||||
extension SearchResultViewModel {
|
||||
func persistSearchHistory(for item: SearchResultItem) {
|
||||
guard let box = context.authenticationService.activeMastodonAuthenticationBox.value else { return }
|
||||
let property = SearchHistory.Property(domain: box.domain, userID: box.userID)
|
||||
let domain = box.domain
|
||||
|
||||
switch item {
|
||||
@ -160,7 +161,7 @@ extension SearchResultViewModel {
|
||||
if let searchHistory = user.searchHistory {
|
||||
searchHistory.update(updatedAt: Date())
|
||||
} else {
|
||||
SearchHistory.insert(into: managedObjectContext, account: user)
|
||||
SearchHistory.insert(into: managedObjectContext, property: property, account: user)
|
||||
}
|
||||
}
|
||||
.sink { result in
|
||||
@ -178,7 +179,7 @@ extension SearchResultViewModel {
|
||||
if let searchHistory = hashtag.searchHistory {
|
||||
searchHistory.update(updatedAt: Date())
|
||||
} else {
|
||||
SearchHistory.insert(into: managedObjectContext, hashtag: hashtag)
|
||||
SearchHistory.insert(into: managedObjectContext, property: property, hashtag: hashtag)
|
||||
}
|
||||
}
|
||||
.sink { result in
|
||||
|
Loading…
x
Reference in New Issue
Block a user