diff --git a/CHANGELOG.md b/CHANGELOG.md index 40c320c0d..5cd454b09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update font styles on Thread, Edit Profile, and Settings screens. - Fix issue with uploading photos on Mac. - Re-design the confirmation dialog that appears when you delete your NIP-05. +- Fixed a bug where liking a note could cause other notes to appear liked. ## [0.1.6] - 2024-03-07Z diff --git a/Nos/Controller/PagedNoteDataSource.swift b/Nos/Controller/PagedNoteDataSource.swift index 8f951d6d1..3a5154d2e 100644 --- a/Nos/Controller/PagedNoteDataSource.swift +++ b/Nos/Controller/PagedNoteDataSource.swift @@ -18,9 +18,10 @@ class PagedNoteDataSource: NSObject, UICol private var emptyPlaceholder: () -> EmptyPlaceholder let pageSize = 10 - private var cellReuseID = "Cell" - private var headerReuseID = "Header" - private var footerReuseID = "Footer" + // We intentionally generate unique IDs for cell reuse to get around + // [this issue](https://github.com/planetary-social/nos/issues/873) + lazy var headerReuseID = { "Header-\(self.description)" }() + lazy var footerReuseID = { "Footer-\(self.description)" }() init( databaseFilter: NSFetchRequest, @@ -42,7 +43,8 @@ class PagedNoteDataSource: NSObject, UICol self.header = header self.emptyPlaceholder = emptyPlaceholder - collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: cellReuseID) + super.init() + collectionView.register( UICollectionViewCell.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, @@ -53,8 +55,6 @@ class PagedNoteDataSource: NSObject, UICol forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: footerReuseID ) - - super.init() self.fetchedResultsController.delegate = self @@ -99,7 +99,13 @@ class PagedNoteDataSource: NSObject, UICol } let note = fetchedResultsController.object(at: indexPath) + + // We intentionally generate unique IDs for cell reuse to get around + // [this issue](https://github.com/planetary-social/nos/issues/873) + let cellReuseID = note.identifier ?? "error" + collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: cellReuseID) let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellReuseID, for: indexPath) + cell.contentConfiguration = UIHostingConfiguration { NoteButton(note: note, hideOutOfNetwork: false, displayRootMessage: true) }