News: fix duplicate news items from multiple SideStore release channel sources

This commit is contained in:
naturecodevoid
2023-02-02 07:35:24 -08:00
committed by Spidy123222
parent d853791ad2
commit f2b555beae
2 changed files with 14 additions and 1 deletions

View File

@@ -103,6 +103,7 @@
<attribute name="externalURL" optional="YES" attributeType="URI"/>
<attribute name="identifier" attributeType="String"/>
<attribute name="imageURL" optional="YES" attributeType="URI"/>
<attribute name="isDuplicate" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isSilent" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES"/>
<attribute name="sortIndex" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="sourceIdentifier" optional="YES" attributeType="String"/>

View File

@@ -32,6 +32,15 @@ public class NewsItem: NSManagedObject, Decodable, Fetchable
@NSManaged public var storeApp: StoreApp?
@NSManaged public var source: Source?
@objc public var isDuplicate: Bool {
if self.source == nil { return false }
// Hide news from sources that begin with the SideStore identifier, and aren't from the same source as the current SideStore source
if self.source!.identifier.starts(with: Bundle.Info.appbundleIdentifier) && self.source!.identifier != Source.altStoreIdentifier { return true }
return false
}
private enum CodingKeys: String, CodingKey
{
case identifier
@@ -86,6 +95,9 @@ public extension NewsItem
{
@nonobjc class func fetchRequest() -> NSFetchRequest<NewsItem>
{
return NSFetchRequest<NewsItem>(entityName: "NewsItem")
let fetchRequest = NSFetchRequest<NewsItem>(entityName: "NewsItem")
fetchRequest.predicate = NSPredicate(format: "%K == NO",
#keyPath(NewsItem.isDuplicate))
return fetchRequest
}
}