Refresh application statuses after account switch

This commit is contained in:
Marcin Czachurski 2023-10-22 14:20:32 +02:00
parent 1199b67765
commit bfde175aab
1 changed files with 20 additions and 0 deletions

View File

@ -328,8 +328,28 @@ struct MainView: View {
// Set account as default (application will open this account after restart).
ApplicationSettingsHandler.shared.set(accountId: signedInAccountModel.id, modelContext: modelContext)
// Refresh new photos and notifications.
_ = await (self.calculateNewPhotosInBackground(), self.calculateNewNotificationsInBackground())
}
}
}
}
private func calculateNewPhotosInBackground() async {
if let account = self.applicationState.account {
self.applicationState.amountOfNewStatuses = await HomeTimelineService.shared.amountOfNewStatuses(
for: account,
includeReblogs: self.applicationState.showReboostedStatuses,
hideStatusesWithoutAlt: self.applicationState.hideStatusesWithoutAlt,
modelContext: modelContext
)
}
}
private func calculateNewNotificationsInBackground() async {
if let account = self.applicationState.account {
self.applicationState.newNotificationsHasBeenAdded = await NotificationsService.shared.newNotificationsHasBeenAdded(for: account, modelContext: modelContext)
}
}
}