Fixes to ensure account data values do not go stale (#9331)
* Fixes to ensure account data values do not go stale * Remove unneeded cli.off * fix test
This commit is contained in:
parent
3c5ff30177
commit
3e076c8246
3 changed files with 58 additions and 2 deletions
|
@ -16,10 +16,12 @@ limitations under the License.
|
|||
|
||||
import { useCallback, useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
ClientEvent,
|
||||
IMyDevice,
|
||||
IPusher,
|
||||
LOCAL_NOTIFICATION_SETTINGS_PREFIX,
|
||||
MatrixClient,
|
||||
MatrixEvent,
|
||||
PUSHER_DEVICE_ID,
|
||||
PUSHER_ENABLED,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
@ -32,6 +34,7 @@ import { LocalNotificationSettings } from "matrix-js-sdk/src/@types/local_notifi
|
|||
import MatrixClientContext from "../../../../contexts/MatrixClientContext";
|
||||
import { _t } from "../../../../languageHandler";
|
||||
import { DevicesDictionary, DeviceWithVerification } from "./types";
|
||||
import { useEventEmitter } from "../../../../hooks/useEventEmitter";
|
||||
|
||||
const isDeviceVerified = (
|
||||
matrixClient: MatrixClient,
|
||||
|
@ -161,6 +164,16 @@ export const useOwnDevices = (): DevicesState => {
|
|||
refreshDevices();
|
||||
}, [refreshDevices]);
|
||||
|
||||
useEventEmitter(matrixClient, ClientEvent.AccountData, (event: MatrixEvent): void => {
|
||||
const type = event.getType();
|
||||
if (type.startsWith(LOCAL_NOTIFICATION_SETTINGS_PREFIX.name)) {
|
||||
const newSettings = new Map(localNotificationSettings);
|
||||
const deviceId = type.slice(type.lastIndexOf(".") + 1);
|
||||
newSettings.set(deviceId, event.getContent<LocalNotificationSettings>());
|
||||
setLocalNotificationSettings(newSettings);
|
||||
}
|
||||
});
|
||||
|
||||
const isCurrentDeviceVerified = !!devices[currentDeviceId]?.isVerified;
|
||||
|
||||
const requestDeviceVerification = isCurrentDeviceVerified && userId
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue