diff --git a/src/utils/notifications.ts b/src/utils/notifications.ts index 0064eaf2bc..32296d62e6 100644 --- a/src/utils/notifications.ts +++ b/src/utils/notifications.ts @@ -31,6 +31,9 @@ export function getLocalNotificationAccountDataEventType(deviceId: string): stri } export async function createLocalNotificationSettingsIfNeeded(cli: MatrixClient): Promise { + if (cli.isGuest()) { + return; + } const eventType = getLocalNotificationAccountDataEventType(cli.deviceId); const event = cli.getAccountData(eventType); // New sessions will create an account data event to signify they support diff --git a/test/utils/notifications-test.ts b/test/utils/notifications-test.ts index c44b496608..9848d7e486 100644 --- a/test/utils/notifications-test.ts +++ b/test/utils/notifications-test.ts @@ -30,21 +30,23 @@ jest.mock("../../src/settings/SettingsStore"); describe('notifications', () => { let accountDataStore = {}; - const mockClient = getMockClientWithEventEmitter({ - isGuest: jest.fn().mockReturnValue(false), - getAccountData: jest.fn().mockImplementation(eventType => accountDataStore[eventType]), - setAccountData: jest.fn().mockImplementation((eventType, content) => { - accountDataStore[eventType] = new MatrixEvent({ - type: eventType, - content, - }); - }), - }); - - const accountDataEventKey = getLocalNotificationAccountDataEventType(mockClient.deviceId); + let mockClient; + let accountDataEventKey; beforeEach(() => { + jest.clearAllMocks(); + mockClient = getMockClientWithEventEmitter({ + isGuest: jest.fn().mockReturnValue(false), + getAccountData: jest.fn().mockImplementation(eventType => accountDataStore[eventType]), + setAccountData: jest.fn().mockImplementation((eventType, content) => { + accountDataStore[eventType] = new MatrixEvent({ + type: eventType, + content, + }); + }), + }); accountDataStore = {}; + accountDataEventKey = getLocalNotificationAccountDataEventType(mockClient.deviceId); mocked(SettingsStore).getValue.mockReturnValue(false); }); @@ -55,6 +57,13 @@ describe('notifications', () => { expect(event?.getContent().is_silenced).toBe(true); }); + it('does not do anything for guests', async () => { + mockClient.isGuest.mockReset().mockReturnValue(true); + await createLocalNotificationSettingsIfNeeded(mockClient); + const event = mockClient.getAccountData(accountDataEventKey); + expect(event).toBeFalsy(); + }); + it.each(deviceNotificationSettingsKeys)( 'unsilenced for existing sessions when %s setting is truthy', async (settingKey) => {