diff --git a/src/components/structures/LoggedInView.tsx b/src/components/structures/LoggedInView.tsx index 755d2c11568..4e9ada99b26 100644 --- a/src/components/structures/LoggedInView.tsx +++ b/src/components/structures/LoggedInView.tsx @@ -139,6 +139,7 @@ class LoggedInView extends React.Component { protected layoutWatcherRef?: string; protected compactLayoutWatcherRef?: string; protected backgroundImageWatcherRef?: string; + protected timezoneProfileUpdateRef?: string[]; protected resizer?: Resizer; public constructor(props: IProps) { @@ -190,6 +191,21 @@ class LoggedInView extends React.Component { 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 { this.refreshBackgroundImage(); } + private onTimezoneUpdate = async (): Promise => { + 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 { 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(); }