You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-09-03 07:02:05 +03:00
Automatically update timezone when setting changes.
This commit is contained in:
@@ -139,6 +139,7 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||
protected layoutWatcherRef?: string;
|
||||
protected compactLayoutWatcherRef?: string;
|
||||
protected backgroundImageWatcherRef?: string;
|
||||
protected timezoneProfileUpdateRef?: string[];
|
||||
protected resizer?: Resizer<ICollapseConfig, CollapseItem>;
|
||||
|
||||
public constructor(props: IProps) {
|
||||
@@ -190,6 +191,21 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||
this.refreshBackgroundImage,
|
||||
);
|
||||
|
||||
|
||||
this.timezoneProfileUpdateRef = [
|
||||
SettingsStore.watchSetting(
|
||||
"userTimezonePublish",
|
||||
null,
|
||||
this.onTimezoneUpdate,
|
||||
),
|
||||
SettingsStore.watchSetting(
|
||||
"userTimezone",
|
||||
null,
|
||||
this.onTimezoneUpdate,
|
||||
),
|
||||
|
||||
];
|
||||
|
||||
this.resizer = this.createResizer();
|
||||
this.resizer.attach();
|
||||
|
||||
@@ -198,6 +214,28 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||
this.refreshBackgroundImage();
|
||||
}
|
||||
|
||||
private onTimezoneUpdate = async (): Promise<void> => {
|
||||
console.log('Triggering timezoen update', SettingsStore);
|
||||
if (!SettingsStore.getValue("userTimezonePublish")) {
|
||||
// Ensure it's deleted
|
||||
try {
|
||||
await this._matrixClient.deleteExtendedProfileProperty("us.cloke.msc4175.tz");
|
||||
} catch (ex) {
|
||||
console.warn("Failed to delete timezone from user profile", ex);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const currentTimezone = SettingsStore.getValue("userTimezone");
|
||||
if (!currentTimezone || typeof currentTimezone !== "string") {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this._matrixClient.setExtendedProfileProperty("us.cloke.msc4175.tz", currentTimezone)
|
||||
} catch (ex) {
|
||||
console.warn("Failed to update user profile with current timezone", ex);
|
||||
}
|
||||
};
|
||||
|
||||
public componentWillUnmount(): void {
|
||||
document.removeEventListener("keydown", this.onNativeKeyDown, false);
|
||||
LegacyCallHandler.instance.removeListener(LegacyCallHandlerEvent.CallState, this.onCallState);
|
||||
@@ -208,6 +246,7 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||
if (this.layoutWatcherRef) SettingsStore.unwatchSetting(this.layoutWatcherRef);
|
||||
if (this.compactLayoutWatcherRef) SettingsStore.unwatchSetting(this.compactLayoutWatcherRef);
|
||||
if (this.backgroundImageWatcherRef) SettingsStore.unwatchSetting(this.backgroundImageWatcherRef);
|
||||
this.timezoneProfileUpdateRef?.forEach(s => SettingsStore.unwatchSetting(s));
|
||||
this.resizer?.detach();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user