Skip to content

Commit

Permalink
Merge pull request #1324 from planetary-social/fix-duplicate-authors
Browse files Browse the repository at this point in the history
Fix duplicate authors in db
  • Loading branch information
joshuatbrown authored Jul 22, 2024
2 parents 4098f31 + 23bcda1 commit 0ac47b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fixed an issue where Profile views would sometimes not display any notes.
- Add impersonation flag category and better NIP-56 mapping.
- Add a Tap to Refresh button in empty profiles.
- Support nostr:naddr links to text and long-form content notes.
Expand Down
36 changes: 21 additions & 15 deletions Nos/Service/CurrentUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,27 @@ import Dependencies

@MainActor func setUp() {
if let keyPair {
author = try? Author.findOrCreate(by: keyPair.publicKeyHex, context: viewContext)
authorWatcher = NSFetchedResultsController(
fetchRequest: Author.request(by: keyPair.publicKeyHex),
managedObjectContext: viewContext,
sectionNameKeyPath: nil,
cacheName: nil
)
authorWatcher?.delegate = self
try? authorWatcher?.performFetch()

socialGraph = SocialGraphCache(userKey: keyPair.publicKeyHex, context: backgroundContext)

Task {
await subscribe()
refreshFriendMetadata()
do {
author = try Author.findOrCreate(by: keyPair.publicKeyHex, context: viewContext)
try viewContext.saveIfNeeded()
authorWatcher = NSFetchedResultsController(
fetchRequest: Author.request(by: keyPair.publicKeyHex),
managedObjectContext: viewContext,
sectionNameKeyPath: nil,
cacheName: nil
)
authorWatcher?.delegate = self
try authorWatcher?.performFetch()

socialGraph = SocialGraphCache(userKey: keyPair.publicKeyHex, context: backgroundContext)

Task {
await subscribe()
refreshFriendMetadata()
}
} catch {
crashReporting.report("Serious error in CurrentUser.setUp(): \(error.localizedDescription)")
Log.optional(error)
}
} else {
author = nil
Expand Down
2 changes: 2 additions & 0 deletions Nos/Service/Relay/RelayService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RelayService: ObservableObject {
private var processingQueue = DispatchQueue(label: "RelayService-processing", qos: .userInitiated)
private var parseQueue = ParseQueue()

@Dependency(\.persistenceController) var persistenceController
@Dependency(\.analytics) private var analytics
@MainActor @Dependency(\.currentUser) private var currentUser
@Published var numberOfConnectedRelays: Int = 0
Expand Down Expand Up @@ -400,6 +401,7 @@ extension RelayService {
)
#endif
try self.parseContext.saveIfNeeded()
try self.persistenceController.viewContext.saveIfNeeded()
}
return true
}
Expand Down

0 comments on commit 0ac47b6

Please sign in to comment.