Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Automatically update timezone when setting changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Sep 6, 2024
1 parent d9238c7 commit e78dfc2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/components/structures/LoggedInView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand All @@ -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");

Check failure on line 222 in src/components/structures/LoggedInView.tsx

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Property 'deleteExtendedProfileProperty' does not exist on type 'MatrixClient'.
} 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)

Check failure on line 233 in src/components/structures/LoggedInView.tsx

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Property 'setExtendedProfileProperty' does not exist on type 'MatrixClient'.
} 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);
Expand All @@ -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();
}

Expand Down

0 comments on commit e78dfc2

Please sign in to comment.