From 3cba0bce348e54b8be281275eb9427c8eda8b031 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 24 Dec 2022 12:20:13 -0500 Subject: [PATCH] Update pinned timelines when changed remotely --- .../MastodonCachePersistentStore.swift | 18 +++++++++++++----- .../Timeline/TimelinesPageViewController.swift | 17 +++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Tusker/CoreData/MastodonCachePersistentStore.swift b/Tusker/CoreData/MastodonCachePersistentStore.swift index 25f62436d9..93c8deb1d5 100644 --- a/Tusker/CoreData/MastodonCachePersistentStore.swift +++ b/Tusker/CoreData/MastodonCachePersistentStore.swift @@ -507,24 +507,28 @@ class MastodonCachePersistentStore: NSPersistentCloudKitContainer { self.backgroundContext.performAndWait { if let result = try? self.backgroundContext.execute(req) as? NSPersistentHistoryResult, let transactions = result.result as? [NSPersistentHistoryTransaction] { - var changes: (hashtags: Bool, instances: Bool) = (false, false) + var changedHashtags = false + var changedInstances = false var changedTimelinePositions: [NSManagedObjectID] = [] + var changedAccountPrefs = false outer: for transaction in transactions { for change in transaction.changes ?? [] { if change.changedObjectID.entity.name == "SavedHashtag" { - changes.hashtags = true + changedHashtags = true } else if change.changedObjectID.entity.name == "SavedInstance" { - changes.instances = true + changedInstances = true } else if change.changedObjectID.entity.name == "TimelinePosition" { changedTimelinePositions.append(change.changedObjectID) + } else if change.changedObjectID.entity.name == "AccountPreferences" { + changedAccountPrefs = true } } } DispatchQueue.main.async { - if changes.hashtags { + if changedHashtags { NotificationCenter.default.post(name: .savedHashtagsChanged, object: nil) } - if changes.instances { + if changedInstances { NotificationCenter.default.post(name: .savedInstancesChanged, object: nil) } for id in changedTimelinePositions { @@ -533,6 +537,9 @@ class MastodonCachePersistentStore: NSPersistentCloudKitContainer { } NotificationCenter.default.post(name: .timelinePositionChanged, object: timelinePosition) } + if changedAccountPrefs { + NotificationCenter.default.post(name: .accountPreferencesChangedRemotely, object: nil) + } } } } @@ -543,4 +550,5 @@ class MastodonCachePersistentStore: NSPersistentCloudKitContainer { extension Foundation.Notification.Name { static let timelinePositionChanged = Notification.Name("timelinePositionChanged") + static let accountPreferencesChangedRemotely = Notification.Name("accountPreferencesChangedRemotely") } diff --git a/Tusker/Screens/Timeline/TimelinesPageViewController.swift b/Tusker/Screens/Timeline/TimelinesPageViewController.swift index cf64b7f9bc..129b5057d9 100644 --- a/Tusker/Screens/Timeline/TimelinesPageViewController.swift +++ b/Tusker/Screens/Timeline/TimelinesPageViewController.swift @@ -9,6 +9,7 @@ import UIKit import SwiftUI import Pachyderm +import Combine class TimelinesPageViewController: SegmentedPageViewController { @@ -18,7 +19,7 @@ class TimelinesPageViewController: SegmentedPageViewController() init(mastodonController: MastodonController) { self.mastodonController = mastodonController @@ -63,12 +64,16 @@ class TimelinesPageViewController: SegmentedPageViewController