From cab647636cbb4b4f70a916acf7f7ad688dbfe5eb Mon Sep 17 00:00:00 2001 From: Marcin Czachurski Date: Wed, 26 Apr 2023 15:49:12 +0200 Subject: [PATCH] Fix issue with deleting status from timeline --- Vernissage/Services/HomeTimelineService.swift | 13 ++++--------- .../Sources/WidgetsKit/Widgets/ExpandableText.swift | 2 +- .../Sources/WidgetsKit/Widgets/TagWidget.swift | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Vernissage/Services/HomeTimelineService.swift b/Vernissage/Services/HomeTimelineService.swift index e2514ff..678270c 100644 --- a/Vernissage/Services/HomeTimelineService.swift +++ b/Vernissage/Services/HomeTimelineService.swift @@ -172,20 +172,15 @@ public class HomeTimelineService { // Collection with statuses to remove from database. var dbStatusesToRemove: [StatusData] = [] + let allDbStatuses = StatusDataHandler.shared.getAllStatuses(accountId: account.id, viewContext: backgroundContext) - // Find statuses to delete (older then the last one from API). - if let lastStatus = statuses.last { - let dbOlderStatuses = StatusDataHandler.shared.getAllOlderStatuses(accountId: account.id, - statusId: lastStatus.id, - viewContext: backgroundContext) - if !dbOlderStatuses.isEmpty { - dbStatusesToRemove.append(contentsOf: dbOlderStatuses) - } + // Find statuses to delete (not exiting in the API results). + for dbStatus in allDbStatuses where !statuses.contains(where: { status in status.id == dbStatus.id }) { + dbStatusesToRemove.append(dbStatus) } // Find statuses to delete (duplicates). var existingStatusIds: [String] = [] - let allDbStatuses = StatusDataHandler.shared.getAllStatuses(accountId: account.id, viewContext: backgroundContext) for dbStatus in allDbStatuses { if existingStatusIds.contains(where: { $0 == dbStatus.id }) { dbStatusesToRemove.append(dbStatus) diff --git a/WidgetsKit/Sources/WidgetsKit/Widgets/ExpandableText.swift b/WidgetsKit/Sources/WidgetsKit/Widgets/ExpandableText.swift index deeb8c7..35407b2 100644 --- a/WidgetsKit/Sources/WidgetsKit/Widgets/ExpandableText.swift +++ b/WidgetsKit/Sources/WidgetsKit/Widgets/ExpandableText.swift @@ -1,7 +1,7 @@ // // https://mczachurski.dev // Copyright © 2023 Marcin Czachurski and the repository contributors. -// Licensed under the MIT License. +// Licensed under the Apache License 2.0. // import Foundation diff --git a/WidgetsKit/Sources/WidgetsKit/Widgets/TagWidget.swift b/WidgetsKit/Sources/WidgetsKit/Widgets/TagWidget.swift index f992f0c..0f33276 100644 --- a/WidgetsKit/Sources/WidgetsKit/Widgets/TagWidget.swift +++ b/WidgetsKit/Sources/WidgetsKit/Widgets/TagWidget.swift @@ -31,7 +31,7 @@ public struct TagWidget: View { .fontWeight(.semibold) } .padding(.horizontal, 10) - .padding(.vertical, 6) + .padding(.vertical, 4) .background(Capsule().foregroundColor(self.color)) } }