Skip to content
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
8 changes: 8 additions & 0 deletions src/notifications/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const resolveIcon = async (
const notifications = new Map();
const notificationTypes = new Map<string, 'voice' | 'text'>();
const notificationCategories = new Map<string, 'DOWNLOADS' | 'SERVER'>();
const repliedNotifications = new Set<string>();
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const createNotification = async (
id: string,
Expand Down Expand Up @@ -79,6 +80,8 @@ const createNotification = async (
});

notification.addListener('show', () => {
repliedNotifications.delete(id);

dispatchSingle({
type: NOTIFICATIONS_NOTIFICATION_SHOWN,
payload: { id },
Expand Down Expand Up @@ -126,6 +129,11 @@ const createNotification = async (
});

notification.addListener('reply', (_event, reply) => {
if (repliedNotifications.has(id)) {
return;
}
repliedNotifications.add(id);

dispatchSingle({
type: NOTIFICATIONS_NOTIFICATION_REPLIED,
payload: { id, reply },
Expand Down
34 changes: 34 additions & 0 deletions src/notifications/main/setup.main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ describe('notifications/main setupNotifications', () => {
});
};

const repliedCalls = () =>
dispatchSingle.mock.calls.filter(
([action]) => action.type === NOTIFICATIONS_NOTIFICATION_REPLIED
);

it('creates a notification and wires show/click/close/reply/action', async () => {
await create({
title: 'Hello',
Expand Down Expand Up @@ -181,6 +186,35 @@ describe('notifications/main setupNotifications', () => {
);
});

it('dispatches a duplicated reply event exactly once', async () => {
await create({ title: 'Hello', tag: 'reply-once' });

const notification = notificationInstances[0];
notification.emit('reply', {}, 'hi there');
notification.emit('reply', {}, 'hi there');

expect(repliedCalls()).toHaveLength(1);
expect(repliedCalls()[0][0].payload).toEqual({
id: 'reply-once',
reply: 'hi there',
});
});

it('accepts another reply after the notification is shown again', async () => {
await create({ title: 'Hello', tag: 'reply-again' });

const notification = notificationInstances[0];
notification.emit('reply', {}, 'first reply');
notification.emit('show');
notification.emit('reply', {}, 'second reply');

expect(repliedCalls()).toHaveLength(2);
expect(repliedCalls()[1][0].payload).toEqual({
id: 'reply-again',
reply: 'second reply',
});
});

it('draws attention for voice notifications', async () => {
await create({
title: 'Call',
Expand Down
Loading