Skip to content

Commit

Permalink
Merge pull request #967 from nextcloud/fix/961/notification-threshold
Browse files Browse the repository at this point in the history
fix(notifications): do not create native notification for old entries
  • Loading branch information
Antreesy authored Dec 10, 2024
2 parents c82240a + bb01c82 commit 9d308d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/talk/renderer/notifications/notifications.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ const refreshData = async (lastETag) => {
BrowserStorage.setItem('status', '' + response.status)
if (response.status !== 204) {
BrowserStorage.setItem('headers', JSON.stringify(response.headers))
BrowserStorage.setItem('data', JSON.stringify(response.data.ocs.data.map(remapAttributes)))
const data = response.data.ocs.data.map(remapAttributes)
BrowserStorage.setItem('data', JSON.stringify(data))
const notificationThresholdId = parseInt(BrowserStorage.getItem('notificationThresholdId') ?? 0, 10)
if (data.length && data[0].notificationId > notificationThresholdId) {
/**
* Notifications older than this ID will not create a native notification.
* see https://github.com/nextcloud/notifications/commit/6a543679b4de8af65cc82baa233ae17ffbbbc1af
*/
BrowserStorage.setItem('notificationThresholdId', data[0].notificationId)
}
}
} catch (error) {
if (error?.response?.status) {
Expand Down Expand Up @@ -104,5 +113,6 @@ export async function getNotificationsData(tabId, lastETag, forceRefresh, hasNot
data: JSON.parse(BrowserStorage.getItem('data') || '[]'),
tabId: BrowserStorage.getItem('tabId'),
lastUpdated: parseInt(BrowserStorage.getItem('lastUpdated'), 10),
notificationThresholdId: parseInt(BrowserStorage.getItem('notificationThresholdId') ?? 0, 10),
}
}
6 changes: 5 additions & 1 deletion src/talk/renderer/notifications/notifications.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function createNotificationStore() {
notifications: [],
lastETag: null,
lastTabId: null,
notificationThresholdId: 0,
userStatus: null,
tabId: null,
/** @type {number} */
Expand Down Expand Up @@ -224,8 +225,11 @@ export function createNotificationStore() {
state.lastETag = response.headers.etag
state.lastTabId = response.tabId
state.notifications = response.data.filter((notification) => notification.app === 'spreed')
const newNotifications = state.notifications.filter((notification) => !notificationsSet.has(notification.notificationId))
const newNotifications = state.notifications.filter((notification) => {
return !notificationsSet.has(notification.notificationId) && notification.notificationId > state.notificationThresholdId
})
notificationsSet = new Set(state.notifications.map((notification) => notification.notificationId))
state.notificationThresholdId = response.notificationThresholdId
if (state.backgroundFetching) {
for (const notification of newNotifications) {
await showNativeNotification(notification)
Expand Down

0 comments on commit 9d308d1

Please sign in to comment.