Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notifications): do not create native notification for old entries #967

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Antreesy marked this conversation as resolved.
Show resolved Hide resolved
}
}
} 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