-
Notifications
You must be signed in to change notification settings - Fork 587
feat(dashboard): Show triggered reminders instead of upcoming ones #19263
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
Open
nickvergessen
wants to merge
1
commit into
main
Choose a base branch
from
feat/noid/show-triggered-reminders-on-dashboard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import type { getReminderNotificationsResponse } from '../types/index.ts' | ||
|
|
||
| import axios from '@nextcloud/axios' | ||
| import { generateOcsUrl } from '@nextcloud/router' | ||
|
|
||
| /** | ||
| * Fetches the reminder notifications of the user, that is the reminders which already triggered | ||
| * and were not dismissed yet. Requires the `list-filter` capability of the notifications app. | ||
| */ | ||
| async function getReminderNotifications(): getReminderNotificationsResponse { | ||
| return axios.get(generateOcsUrl('apps/notifications/api/v2/notifications'), { | ||
| params: { | ||
| app: 'spreed', | ||
| objectType: 'reminder', | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * Dismisses a single notification of the user | ||
| * | ||
| * @param notificationId The id of the notification | ||
| */ | ||
| async function dismissNotification(notificationId: number) { | ||
| return axios.delete(generateOcsUrl('apps/notifications/api/v2/notifications/{notificationId}', { | ||
| notificationId, | ||
| })) | ||
| } | ||
|
|
||
| export { | ||
| dismissNotification, | ||
| getReminderNotifications, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { createPinia, setActivePinia } from 'pinia' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { ATTENDEE } from '../../constants.ts' | ||
| import { generateOCSErrorResponse, generateOCSResponse } from '../../test-helpers.js' | ||
|
|
||
| vi.mock('../../services/CapabilitiesManager.ts', () => ({ | ||
| hasNotificationsFeature: vi.fn(), | ||
| hasTalkFeature: vi.fn(), | ||
| })) | ||
| vi.mock('../../services/notificationsService.ts', () => ({ | ||
| dismissNotification: vi.fn(), | ||
| getReminderNotifications: vi.fn(), | ||
| })) | ||
| vi.mock('../../services/remindersService.js', () => ({ | ||
| getUpcomingReminders: vi.fn(), | ||
| removeMessageReminder: vi.fn(), | ||
| })) | ||
| vi.mock('../../services/dashboardService.ts', () => ({ | ||
| getDashboardEventRooms: vi.fn(), | ||
| })) | ||
|
|
||
| /** | ||
| * Load a fresh dashboard store, as the supported reminder source is read from the capabilities | ||
| * once when the module is evaluated. | ||
| * | ||
| * @param {boolean} supportsListFilter Whether the notifications app can filter by app and object | ||
| */ | ||
| async function setupStore(supportsListFilter) { | ||
| vi.resetModules() | ||
| const { hasNotificationsFeature, hasTalkFeature } = await import('../../services/CapabilitiesManager.ts') | ||
| hasTalkFeature.mockReturnValue(true) | ||
| hasNotificationsFeature.mockReturnValue(supportsListFilter) | ||
|
|
||
| const notificationsService = await import('../../services/notificationsService.ts') | ||
| const remindersService = await import('../../services/remindersService.js') | ||
| const { useDashboardStore } = await import('../dashboard.ts') | ||
|
|
||
| setActivePinia(createPinia()) | ||
| return { store: useDashboardStore(), notificationsService, remindersService } | ||
| } | ||
|
|
||
| describe('dashboardStore', () => { | ||
| const reminderNotification = { | ||
| notification_id: 9, | ||
| app: 'spreed', | ||
| user: 'remindertester', | ||
| datetime: '2026-09-03T15:39:03+00:00', | ||
| object_type: 'reminder', | ||
| object_id: 'u8u7if2f/3', | ||
| subject: 'Reminder: Other Person in private conversation', | ||
| message: 'Hello there, remember this one', | ||
| link: 'http://localhost/index.php/call/u8u7if2f#message_3', | ||
| subjectRichParameters: { | ||
| user: { type: 'user', id: 'reminderother', name: 'Other Person' }, | ||
| call: { type: 'call', id: '1', name: 'Other Person' }, | ||
| }, | ||
| messageRich: 'Hello there, remember this one', | ||
| messageRichParameters: [], | ||
| } | ||
|
|
||
| const upcomingReminder = { | ||
| messageId: 3, | ||
| roomToken: 'u8u7if2f', | ||
| actorId: 'reminderother', | ||
| actorType: ATTENDEE.ACTOR_TYPE.USERS, | ||
| actorDisplayName: 'Other Person', | ||
| message: 'Hello there, remember this one', | ||
| messageParameters: {}, | ||
| reminderTimestamp: 1788449943, | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| setActivePinia(createPinia()) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| describe('fetching reminders', () => { | ||
| it('parses triggered reminders out of the notifications of the user', async () => { | ||
| // Arrange | ||
| const { store, notificationsService } = await setupStore(true) | ||
| notificationsService.getReminderNotifications.mockResolvedValueOnce(generateOCSResponse({ payload: [reminderNotification] })) | ||
|
|
||
| // Act | ||
| await store.fetchReminders() | ||
|
|
||
| // Assert | ||
| expect(notificationsService.getReminderNotifications).toHaveBeenCalled() | ||
| expect(store.remindersInitialised).toBe(true) | ||
| expect(store.reminders).toEqual([{ | ||
| notificationId: 9, | ||
| roomToken: 'u8u7if2f', | ||
| messageId: 3, | ||
| actorId: 'reminderother', | ||
| actorType: ATTENDEE.ACTOR_TYPE.USERS, | ||
| actorDisplayName: 'Other Person', | ||
| message: 'Hello there, remember this one', | ||
| messageParameters: {}, | ||
| reminderTimestamp: 1788449943, | ||
| }]) | ||
| }) | ||
|
|
||
| it('reads the message id and thread id out of the object id', async () => { | ||
| // Arrange | ||
| const { store, notificationsService } = await setupStore(true) | ||
| notificationsService.getReminderNotifications.mockResolvedValueOnce(generateOCSResponse({ payload: [{ ...reminderNotification, object_id: 'u8u7if2f/3/2' }] })) | ||
|
|
||
| // Act | ||
| await store.fetchReminders() | ||
|
|
||
| // Assert | ||
| expect(store.reminders[0].roomToken).toBe('u8u7if2f') | ||
| expect(store.reminders[0].messageId).toBe(3) | ||
| }) | ||
|
|
||
| it('falls back to the subject when a sensitive conversation hides the message', async () => { | ||
| // Arrange | ||
| const { store, notificationsService } = await setupStore(true) | ||
| notificationsService.getReminderNotifications.mockResolvedValueOnce(generateOCSResponse({ | ||
| payload: [{ | ||
| ...reminderNotification, | ||
| object_id: 'u8u7if2f', | ||
| subject: 'Reminder in a private conversation', | ||
| subjectRichParameters: [], | ||
| messageRich: '', | ||
| messageRichParameters: [], | ||
| }], | ||
| })) | ||
|
|
||
| // Act | ||
| await store.fetchReminders() | ||
|
|
||
| // Assert | ||
| expect(store.reminders[0].messageId).toBe(0) | ||
| expect(store.reminders[0].actorDisplayName).toBe('Reminder in a private conversation') | ||
| expect(store.reminders[0].messageParameters).toEqual({}) | ||
| }) | ||
|
|
||
| it('shows nothing when no app registered a notifier and the endpoint answers 204', async () => { | ||
| // Arrange | ||
| const { store, notificationsService } = await setupStore(true) | ||
| notificationsService.getReminderNotifications.mockResolvedValueOnce({ status: 204, data: '' }) | ||
|
|
||
| // Act | ||
| await store.fetchReminders() | ||
|
|
||
| // Assert | ||
| expect(store.reminders).toEqual([]) | ||
| expect(store.remindersInitialised).toBe(true) | ||
| }) | ||
|
|
||
| it('falls back to upcoming reminders without the notifications capability', async () => { | ||
| // Arrange | ||
| const { store, notificationsService, remindersService } = await setupStore(false) | ||
| remindersService.getUpcomingReminders.mockResolvedValueOnce(generateOCSResponse({ payload: [upcomingReminder] })) | ||
|
|
||
| // Act | ||
| await store.fetchReminders() | ||
|
|
||
| // Assert | ||
| expect(notificationsService.getReminderNotifications).not.toHaveBeenCalled() | ||
| expect(store.reminders).toEqual([{ ...upcomingReminder, notificationId: null }]) | ||
| }) | ||
| }) | ||
|
|
||
| describe('removing reminders', () => { | ||
| it('dismisses the notification of a reminder that already triggered', async () => { | ||
| // Arrange | ||
| const { store, notificationsService, remindersService } = await setupStore(true) | ||
| notificationsService.getReminderNotifications.mockResolvedValueOnce(generateOCSResponse({ payload: [reminderNotification] })) | ||
| await store.fetchReminders() | ||
|
|
||
| // Act | ||
| await store.removeReminder('u8u7if2f', 3, 9) | ||
|
|
||
| // Assert | ||
| expect(notificationsService.dismissNotification).toHaveBeenCalledWith(9) | ||
| expect(remindersService.removeMessageReminder).not.toHaveBeenCalled() | ||
| expect(store.reminders).toEqual([]) | ||
| }) | ||
|
|
||
| it('deletes the reminder itself when it did not trigger yet', async () => { | ||
| // Arrange | ||
| const { store, notificationsService, remindersService } = await setupStore(false) | ||
| remindersService.getUpcomingReminders.mockResolvedValueOnce(generateOCSResponse({ payload: [upcomingReminder] })) | ||
| await store.fetchReminders() | ||
|
|
||
| // Act | ||
| await store.removeReminder('u8u7if2f', 3) | ||
|
|
||
| // Assert | ||
| expect(remindersService.removeMessageReminder).toHaveBeenCalledWith('u8u7if2f', 3) | ||
| expect(notificationsService.dismissNotification).not.toHaveBeenCalled() | ||
| expect(store.reminders).toEqual([]) | ||
| }) | ||
|
|
||
| it('keeps the list untouched when dismissing fails', async () => { | ||
| // Arrange | ||
| const { store, notificationsService } = await setupStore(true) | ||
| notificationsService.getReminderNotifications.mockResolvedValueOnce(generateOCSResponse({ payload: [reminderNotification] })) | ||
| await store.fetchReminders() | ||
| const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}) | ||
| notificationsService.dismissNotification.mockRejectedValueOnce(generateOCSErrorResponse({ payload: null, status: 404 })) | ||
|
|
||
| // Act | ||
| await store.removeReminder('u8u7if2f', 3, 9) | ||
|
|
||
| // Assert | ||
| expect(store.reminders).toHaveLength(1) | ||
| consoleErrorSpy.mockRestore() | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placeholder element uses
t('spreed', 'Message reminders'), maybe also reuse it here?