Fixes silenced notification preventing notification prompt to be shown (#9336)
This commit is contained in:
parent
a704a2fbb7
commit
c2e2f406af
7 changed files with 10 additions and 75 deletions
|
@ -18,36 +18,10 @@ import { LOCAL_NOTIFICATION_SETTINGS_PREFIX } from "matrix-js-sdk/src/@types/eve
|
|||
import { LocalNotificationSettings } from "matrix-js-sdk/src/@types/local_notifications";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
|
||||
export const deviceNotificationSettingsKeys = [
|
||||
"notificationsEnabled",
|
||||
"notificationBodyEnabled",
|
||||
"audioNotificationsEnabled",
|
||||
];
|
||||
|
||||
export function getLocalNotificationAccountDataEventType(deviceId: string): string {
|
||||
return `${LOCAL_NOTIFICATION_SETTINGS_PREFIX.name}.${deviceId}`;
|
||||
}
|
||||
|
||||
export async function createLocalNotificationSettingsIfNeeded(cli: MatrixClient): Promise<void> {
|
||||
const eventType = getLocalNotificationAccountDataEventType(cli.deviceId);
|
||||
const event = cli.getAccountData(eventType);
|
||||
// New sessions will create an account data event to signify they support
|
||||
// remote toggling of push notifications on this device. Default `is_silenced=true`
|
||||
// For backwards compat purposes, older sessions will need to check settings value
|
||||
// to determine what the state of `is_silenced`
|
||||
if (!event) {
|
||||
// If any of the above is true, we fall in the "backwards compat" case,
|
||||
// and `is_silenced` will be set to `false`
|
||||
const isSilenced = !deviceNotificationSettingsKeys.some(key => SettingsStore.getValue(key));
|
||||
|
||||
await cli.setAccountData(eventType, {
|
||||
is_silenced: isSilenced,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function localNotificationsAreSilenced(cli: MatrixClient): boolean {
|
||||
const eventType = getLocalNotificationAccountDataEventType(cli.deviceId);
|
||||
const event = cli.getAccountData(eventType);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue