Fix sync failing with feeds lacking title

This commit is contained in:
Shadowfacts 2023-10-02 22:35:07 -04:00
parent 749e109165
commit ef215e8bdc
5 changed files with 45 additions and 6 deletions

View File

@ -9,7 +9,7 @@ import Foundation
public struct Feed: Decodable, Sendable {
public let id: FervorID
public let title: String
public let title: String?
public let url: URL?
public let serviceURL: URL?
public let feedURL: URL
@ -20,7 +20,7 @@ public struct Feed: Decodable, Sendable {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(FervorID.self, forKey: .id)
self.title = try container.decode(String.self, forKey: .title)
self.title = try container.decodeIfPresent(String.self, forKey: .title)
self.url = try container.decode(URL?.self, forKey: .url)
self.serviceURL = try container.decodeIfPresent(URL.self, forKey: .serviceURL)
self.feedURL = try container.decode(URL.self, forKey: .feedURL)

View File

@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Reader 3.xcdatamodel</string>
<string>Reader 4.xcdatamodel</string>
</dict>
</plist>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22222" systemVersion="22G91" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Feed" representedClassName="Feed" syncable="YES">
<attribute name="id" attributeType="String"/>
<attribute name="lastUpdated" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="title" optional="YES" attributeType="String"/>
<attribute name="url" optional="YES" attributeType="URI"/>
<relationship name="groups" toMany="YES" deletionRule="Nullify" destinationEntity="Group" inverseName="feeds" inverseEntity="Group"/>
<relationship name="items" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="Item" inverseName="feed" inverseEntity="Item"/>
</entity>
<entity name="Group" representedClassName="Group" syncable="YES">
<attribute name="id" attributeType="String"/>
<attribute name="title" attributeType="String"/>
<relationship name="feeds" toMany="YES" deletionRule="Nullify" destinationEntity="Feed" inverseName="groups" inverseEntity="Feed"/>
</entity>
<entity name="Item" representedClassName="Item" versionHashModifier="5" syncable="YES">
<attribute name="author" optional="YES" attributeType="String"/>
<attribute name="content" optional="YES" attributeType="String"/>
<attribute name="excerpt" optional="YES" attributeType="String"/>
<attribute name="generatedExcerpt" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="id" attributeType="String"/>
<attribute name="needsReadStateSync" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="published" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="read" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="title" optional="YES" attributeType="String"/>
<attribute name="url" optional="YES" attributeType="URI"/>
<relationship name="feed" maxCount="1" deletionRule="Nullify" destinationEntity="Feed" inverseName="items" inverseEntity="Feed"/>
<fetchIndex name="byID">
<fetchIndexElement property="id" type="Binary" order="ascending"/>
</fetchIndex>
<fetchIndex name="byRead">
<fetchIndexElement property="read" type="Binary" order="ascending"/>
</fetchIndex>
</entity>
<entity name="SyncState" representedClassName="SyncState" syncable="YES" codeGenerationType="class">
<attribute name="lastSync" attributeType="Date" usesScalarValueType="NO"/>
</entity>
<fetchRequest name="FetchRequest" entity="Item" predicateString="TRUEPREDICATE"/>
</model>

View File

@ -74,8 +74,8 @@ actor FervorController {
setSyncState(.groupsAndFeeds)
logger.info("Syncing groups and feeds")
async let groups = try client.groups()
async let feeds = try client.feeds()
let groups = try await client.groups()
let feeds = try await client.feeds()
try await persistentContainer.sync(serverGroups: groups, serverFeeds: feeds)
setSyncState(.items)

View File

@ -24,7 +24,7 @@ enum ItemListType: Hashable, Equatable {
case let .group(group):
return group.title
case let .feed(feed):
return feed.title!
return feed.title ?? feed.url?.host() ?? "Unknown Feed"
}
}