Fix amount of new notifications indicator
This commit is contained in:
parent
8de6c937ec
commit
bd56408ce8
|
@ -67,16 +67,20 @@ public class NotificationsService {
|
|||
// There can be more then 80 newest notifications, that's why we have to sometimes send more then one request.
|
||||
while true {
|
||||
do {
|
||||
let downloadedNotifications = try await client.notifications(minId: newestNotificationId, limit: 80)
|
||||
let linkable = try await client.notifications(minId: newestNotificationId, limit: 80)
|
||||
let visibleNotifications = linkable.data.filter({ $0.id != lastSeenNotificationId })
|
||||
|
||||
guard let firstNotification = downloadedNotifications.data.first else {
|
||||
guard let firstNotification = visibleNotifications.first else {
|
||||
break
|
||||
}
|
||||
|
||||
notifications.append(contentsOf: visibleNotifications)
|
||||
|
||||
guard let minId = linkable.link?.minId else {
|
||||
break
|
||||
}
|
||||
|
||||
let visibleNotifications = downloadedNotifications.data.filter({ $0.id != lastSeenNotificationId })
|
||||
|
||||
notifications.append(contentsOf: visibleNotifications)
|
||||
newestNotificationId = firstNotification.id
|
||||
newestNotificationId = minId
|
||||
} catch {
|
||||
ErrorService.shared.handle(error, message: "global.error.errorDuringDownloadingNewStatuses")
|
||||
break
|
||||
|
|
|
@ -241,7 +241,7 @@ struct VernissageApp: App {
|
|||
let modelContext = self.modelContainer.mainContext
|
||||
|
||||
if let account = self.applicationState.account {
|
||||
self.applicationState.amountOfNewStatuses = await NotificationsService.shared.amountOfNewNotifications(for: account, modelContext: modelContext)
|
||||
self.applicationState.amountOfNewNotifications = await NotificationsService.shared.amountOfNewNotifications(for: account, modelContext: modelContext)
|
||||
try? await NotificationsService.shared.setBadgeCount(self.applicationState.amountOfNewStatuses)
|
||||
} else {
|
||||
try? await NotificationsService.shared.setBadgeCount(0)
|
||||
|
|
Loading…
Reference in New Issue