Skip to content

Commit

Permalink
renaming, refactoring, and fixing relationship
Browse files Browse the repository at this point in the history
joshuatbrown committed Dec 17, 2024
1 parent 89beadf commit 3c2bd5f
Showing 5 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Nos/Models/CoreData/AuthorList+CoreDataClass.swift
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ public class AuthorList: Event {
let authorList = existingAuthorList ?? AuthorList(context: context)
authorList.createdAt = jsonEvent.createdDate
authorList.author = owner
authorList.owner = owner
authorList.identifier = jsonEvent.id
authorList.replaceableIdentifier = replaceableID
authorList.kind = jsonEvent.kind
@@ -55,7 +56,7 @@ public class AuthorList: Event {
) -> NSFetchRequest<AuthorList> {
let fetchRequest = NSFetchRequest<AuthorList>(entityName: "AuthorList")
fetchRequest.predicate = NSPredicate(
format: "replaceableIdentifier = %@ AND author = %@ AND kind = %i",
format: "replaceableIdentifier = %@ AND owner = %@ AND kind = %i",
replaceableID,
owner,
kind
11 changes: 11 additions & 0 deletions Nos/Models/CoreData/Generated/AuthorList+CoreDataProperties.swift
Original file line number Diff line number Diff line change
@@ -7,9 +7,20 @@ extension AuthorList {
NSFetchRequest<AuthorList>(entityName: "AuthorList")
}

/// The URL of an image representing the list.
@NSManaged public var image: URL?

/// The description of the list.
@NSManaged public var listDescription: String?

/// The title of the list.
@NSManaged public var title: String?

/// The owner of the list; the ``Author`` who created it.
/// Duplicates ``author`` but Core Data won't allow for multiple relationships to have the same inverse.
@NSManaged public var owner: Author?

/// The set of unique authors in this list.
@NSManaged public var authors: Set<Author>
}

Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<relationship name="follows" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="Follow" inverseName="source" inverseEntity="Follow"/>
<relationship name="includedInLists" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="AuthorList" inverseName="authors" inverseEntity="AuthorList"/>
<relationship name="incomingNotifications" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="NosNotification" inverseName="user" inverseEntity="NosNotification"/>
<relationship name="lists" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="AuthorList"/>
<relationship name="lists" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="AuthorList" inverseName="owner" inverseEntity="AuthorList"/>
<relationship name="relays" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Relay" inverseName="authors" inverseEntity="Relay"/>
<uniquenessConstraints>
<uniquenessConstraint>
@@ -34,6 +34,7 @@
<attribute name="listDescription" optional="YES" attributeType="String"/>
<attribute name="title" optional="YES" attributeType="String"/>
<relationship name="authors" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Author" inverseName="includedInLists" inverseEntity="Author"/>
<relationship name="owner" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Author" inverseName="lists" inverseEntity="Author"/>
</entity>
<entity name="AuthorReference" representedClassName="AuthorReference" syncable="YES">
<attribute name="pubkey" optional="YES" attributeType="String"/>
4 changes: 2 additions & 2 deletions Nos/Service/EventProcessor.swift
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ extension EventProcessor {
skipVerification: Bool
) throws -> AuthorList {
let authorList = try AuthorList.createOrUpdate(from: jsonEvent, in: parseContext)
if skipVerification == false {
if !skipVerification {
guard try authorList.verifySignature() else {
parseContext.delete(authorList)
Log.info("Invalid signature on author list: \(jsonEvent) from \(relay?.address ?? "error")")
@@ -104,7 +104,7 @@ extension EventProcessor {
throw EventError.missingAuthor
}

if skipVerification == false {
if !skipVerification {
guard try event.verifySignature(for: publicKey) else {
parseContext.delete(event)
Log.info("Invalid signature on event: \(jsonEvent) from \(relay?.address ?? "error")")
4 changes: 2 additions & 2 deletions Nos/Service/Relay/RelayService.swift
Original file line number Diff line number Diff line change
@@ -271,7 +271,7 @@ extension RelayService {
return await fetchEvents(matching: contactFilter)
}

func requestFollowSets(
func requestAuthorLists(
for authorKey: RawAuthorID?,
since: Date?
) async -> SubscriptionCancellable {
@@ -300,7 +300,7 @@ extension RelayService {

subscriptions.append(await requestMetadata(for: authorKey, since: lastUpdateMetadata))
subscriptions.append(await requestContactList(for: authorKey, since: lastUpdatedContactList))
subscriptions.append(await requestFollowSets(for: authorKey, since: lastUpdatedFollowSets))
subscriptions.append(await requestAuthorLists(for: authorKey, since: lastUpdatedFollowSets))

return SubscriptionCancellable(cancellables: subscriptions, relayService: self)
}

0 comments on commit 3c2bd5f

Please sign in to comment.