Fix duplicate entry after reblog (IOS-176)

This commit is contained in:
Marcus Kida 2023-11-27 11:54:01 +01:00
parent 4cb845e0bd
commit faac99cd10
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
1 changed files with 13 additions and 2 deletions

View File

@ -112,10 +112,21 @@ extension HomeTimelineViewModel.LoadLatestState {
viewModel.homeTimelineNavigationBarTitleViewModel.newPostsIncoming()
}
let newRecords: [MastodonFeed] = newStatuses.map {
var newRecords: [MastodonFeed] = newStatuses.map {
MastodonFeed.fromStatus(.fromEntity($0), kind: .home)
}
viewModel.fetchedResultsController.records = newRecords + viewModel.fetchedResultsController.records
viewModel.fetchedResultsController.records = {
var oldRecords = viewModel.fetchedResultsController.records
for (i, record) in newRecords.enumerated() {
if let index = oldRecords.firstIndex(where: { $0.status?.reblog?.id == record.id || $0.status?.id == record.id }) {
oldRecords[index] = record
if newRecords.count > index {
newRecords.remove(at: i)
}
}
}
return (newRecords + oldRecords).removingDuplicates()
}()
}
viewModel.timelineIsEmpty.value = latestStatusIDs.isEmpty && statuses.isEmpty