From ce0e56b84e3c140074c6bd6c7c7fbc5fd2aa7885 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Fri, 4 Nov 2022 16:25:11 +0100 Subject: [PATCH] Add showsReblog to CoreData/persistence (#365) --- .../CoreData.xcdatamodeld/.xccurrentversion | 2 +- .../CoreData 4.xcdatamodel/contents | 254 ++++++++++++++++++ .../Entity/Mastodon/MastodonUser.swift | 15 +- .../Persistence+MastodonUser.swift | 1 + 4 files changed, 270 insertions(+), 2 deletions(-) create mode 100644 MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 4.xcdatamodel/contents diff --git a/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/.xccurrentversion b/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/.xccurrentversion index cdd244c9c..1d5ea989f 100644 --- a/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/.xccurrentversion +++ b/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - CoreData 3.xcdatamodel + CoreData 4.xcdatamodel diff --git a/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 4.xcdatamodel/contents b/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 4.xcdatamodel/contents new file mode 100644 index 000000000..7604028f1 --- /dev/null +++ b/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 4.xcdatamodel/contents @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonUser.swift b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonUser.swift index 85e844b09..760985d68 100644 --- a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonUser.swift +++ b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonUser.swift @@ -89,7 +89,8 @@ final public class MastodonUser: NSManagedObject { @NSManaged public private(set) var endorsedBy: Set @NSManaged public private(set) var domainBlocking: Set @NSManaged public private(set) var domainBlockingBy: Set - + @NSManaged public private(set) var showingReblogs: Set + @NSManaged public private(set) var showingReblogsBy: Set } extension MastodonUser { @@ -521,6 +522,7 @@ extension MastodonUser: AutoUpdatableObject { } } } + public func update(isDomainBlocking: Bool, by mastodonUser: MastodonUser) { if isDomainBlocking { if !self.domainBlockingBy.contains(mastodonUser) { @@ -533,4 +535,15 @@ extension MastodonUser: AutoUpdatableObject { } } + 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) + } + } + } } diff --git a/MastodonSDK/Sources/MastodonCore/Persistence/Persistence+MastodonUser.swift b/MastodonSDK/Sources/MastodonCore/Persistence/Persistence+MastodonUser.swift index eb69c36d1..8571a11cf 100644 --- a/MastodonSDK/Sources/MastodonCore/Persistence/Persistence+MastodonUser.swift +++ b/MastodonSDK/Sources/MastodonCore/Persistence/Persistence+MastodonUser.swift @@ -157,5 +157,6 @@ extension Persistence.MastodonUser { user.update(isBlocking: relationship.blocking, by: me) relationship.domainBlocking.flatMap { user.update(isDomainBlocking: $0, by: me) } relationship.blockedBy.flatMap { me.update(isBlocking: $0, by: user) } + relationship.showingReblogs.flatMap { me.update(isShowingReblogs: $0, by: user) } } }