Do not create account data event for guests (#9407)

* Do not create account data event for guests

* fix test
This commit is contained in:
Germain 2022-10-13 13:15:34 +01:00 committed by GitHub
parent 7a1c47a23e
commit 714ba6db94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 12 deletions

View file

@ -31,6 +31,9 @@ export function getLocalNotificationAccountDataEventType(deviceId: string): stri
} }
export async function createLocalNotificationSettingsIfNeeded(cli: MatrixClient): Promise<void> { export async function createLocalNotificationSettingsIfNeeded(cli: MatrixClient): Promise<void> {
if (cli.isGuest()) {
return;
}
const eventType = getLocalNotificationAccountDataEventType(cli.deviceId); const eventType = getLocalNotificationAccountDataEventType(cli.deviceId);
const event = cli.getAccountData(eventType); const event = cli.getAccountData(eventType);
// New sessions will create an account data event to signify they support // New sessions will create an account data event to signify they support

View file

@ -30,7 +30,12 @@ jest.mock("../../src/settings/SettingsStore");
describe('notifications', () => { describe('notifications', () => {
let accountDataStore = {}; let accountDataStore = {};
const mockClient = getMockClientWithEventEmitter({ let mockClient;
let accountDataEventKey;
beforeEach(() => {
jest.clearAllMocks();
mockClient = getMockClientWithEventEmitter({
isGuest: jest.fn().mockReturnValue(false), isGuest: jest.fn().mockReturnValue(false),
getAccountData: jest.fn().mockImplementation(eventType => accountDataStore[eventType]), getAccountData: jest.fn().mockImplementation(eventType => accountDataStore[eventType]),
setAccountData: jest.fn().mockImplementation((eventType, content) => { setAccountData: jest.fn().mockImplementation((eventType, content) => {
@ -40,11 +45,8 @@ describe('notifications', () => {
}); });
}), }),
}); });
const accountDataEventKey = getLocalNotificationAccountDataEventType(mockClient.deviceId);
beforeEach(() => {
accountDataStore = {}; accountDataStore = {};
accountDataEventKey = getLocalNotificationAccountDataEventType(mockClient.deviceId);
mocked(SettingsStore).getValue.mockReturnValue(false); mocked(SettingsStore).getValue.mockReturnValue(false);
}); });
@ -55,6 +57,13 @@ describe('notifications', () => {
expect(event?.getContent().is_silenced).toBe(true); 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)( it.each(deviceNotificationSettingsKeys)(
'unsilenced for existing sessions when %s setting is truthy', 'unsilenced for existing sessions when %s setting is truthy',
async (settingKey) => { async (settingKey) => {