import Foundation import SwiftUI extension AppModel { func invalidateContent() { withContentUpdates { clearContent() } } func clearContent() { for pending in postLoadTasks.values { pending.task.cancel() } postLoadTasks = [:] for pending in profileLoadTasks.values { pending.task.cancel() } profileLoadTasks = [:] resetSearch(query: "", kind: .accounts) resetSavedPosts() moderationDecisions.removeAll(keepingCapacity: true) moderationExpiryCandidates.removeAll(keepingCapacity: true) scheduleModerationExpiry(nil) contentInputsChanged() refreshNotificationsTask?.cancel() refreshNotificationsTask = nil refreshNotificationsID = UUID() feedRefreshTask?.cancel() feedRefreshTask = nil feedRefreshID = UUID() isRefreshingFeed = false notificationsReadThrough = nil initialNotificationsTask?.cancel() initialNotificationsTask = nil initialNotificationsRequest = UUID() hasLoadedNotifications = false contentGeneration = UUID() clearPadContent() clearCachedContent() cursor = nil hasMorePosts = false feedRequest = nil moreFeedRequest = nil postRequests = [:] profileRequests = [:] moreProfileRequests = [:] notificationsRequest = nil moreNotificationsRequest = nil isLoading = false isLoadingMore = false isLoadingPost = false loadingPostIDs = [] failedPostIDs = [] postErrors = [:] feedErrorMessage = nil retryFeedPage = false loadingProfileIDs = [] loadingMoreProfileIDs = [] isLoadingNotifications = false isLoadingMoreNotifications = false resumeNotificationLoads() resumeFeedLoads() } private func clearCachedContent() { posts = [] timelinePostIDs = [] replyContexts = [:] repostedBy = [:] threadContexts = [:] threadPositions = [:] profiles = [:] profileLoadedAt = [:] avatars.clear() inlineImages.clear() preparedPostText.removeAll() authorPosts = [:] profileCursors = [:] profileRepostedBy = [:] profileErrors = [:] failedProfileRefreshIDs = [] notifications = [] notificationPageStarts = [] notificationsCursor = nil notificationRequestedCursors = [] notificationPendingPageStart = false notificationsErrorMessage = nil failedNotificationsPage = false hasMoreNotifications = false } private func clearPadContent() { for state in padStates.values { state.request = nil state.isLoading = false state.isLoadingMore = false state.hasMore = false state.cursor = nil state.posts = [] state.replyContexts = [:] state.repostedBy = [:] state.rows = [] state.errorMessage = nil } } }