diff --git a/res/css/views/right_panel/_UserInfo.pcss b/res/css/views/right_panel/_UserInfo.pcss index 186eb78a32f..b0824f704f6 100644 --- a/res/css/views/right_panel/_UserInfo.pcss +++ b/res/css/views/right_panel/_UserInfo.pcss @@ -132,6 +132,12 @@ limitations under the License. } } + .mx_UserInfo_timezone { + .mx_UserInfo_profileStatus { + margin: var(--cpd-space-1x) 0; + } + } + .mx_PresenceLabel { font: var(--cpd-font-body-sm-regular); opacity: 1; diff --git a/src/components/structures/LoggedInView.tsx b/src/components/structures/LoggedInView.tsx index 4e9ada99b26..1a92748375a 100644 --- a/src/components/structures/LoggedInView.tsx +++ b/src/components/structures/LoggedInView.tsx @@ -191,19 +191,9 @@ class LoggedInView extends React.Component { this.refreshBackgroundImage, ); - this.timezoneProfileUpdateRef = [ - SettingsStore.watchSetting( - "userTimezonePublish", - null, - this.onTimezoneUpdate, - ), - SettingsStore.watchSetting( - "userTimezone", - null, - this.onTimezoneUpdate, - ), - + SettingsStore.watchSetting("userTimezonePublish", null, this.onTimezoneUpdate), + SettingsStore.watchSetting("userTimezone", null, this.onTimezoneUpdate), ]; this.resizer = this.createResizer(); @@ -215,7 +205,7 @@ class LoggedInView extends React.Component { } private onTimezoneUpdate = async (): Promise => { - console.log('Triggering timezoen update', SettingsStore); + console.log("Triggering timezoen update", SettingsStore); if (!SettingsStore.getValue("userTimezonePublish")) { // Ensure it's deleted try { @@ -230,7 +220,7 @@ class LoggedInView extends React.Component { return; } try { - await this._matrixClient.setExtendedProfileProperty("us.cloke.msc4175.tz", currentTimezone) + await this._matrixClient.setExtendedProfileProperty("us.cloke.msc4175.tz", currentTimezone); } catch (ex) { console.warn("Failed to update user profile with current timezone", ex); } @@ -246,7 +236,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.timezoneProfileUpdateRef?.forEach((s) => SettingsStore.unwatchSetting(s)); this.resizer?.detach(); } diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index 60af901975e..4b707f589d1 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -29,7 +29,6 @@ import { User, Device, EventType, - MatrixError, } from "matrix-js-sdk/src/matrix"; import { KnownMembership } from "matrix-js-sdk/src/types"; import { UserVerificationStatus, VerificationRequest } from "matrix-js-sdk/src/crypto-api"; @@ -1703,7 +1702,6 @@ export const UserInfoHeader: React.FC<{ ); } - const timezoneInfo = useUserTimezone(member.userId); const e2eIcon = e2eStatus ? : null; @@ -1738,7 +1736,14 @@ export const UserInfoHeader: React.FC<{ {e2eIcon} - {presenceLabel} {timezoneInfo && {timezoneInfo.friendly}} + {presenceLabel} + + + + {timezoneInfo?.friendly ?? ""} + + + userIdentifier} border={false}> {userIdentifier} diff --git a/src/components/views/settings/UserPersonalInfoSettings.tsx b/src/components/views/settings/UserPersonalInfoSettings.tsx index 721d7227b0c..a4e3c1e4d06 100644 --- a/src/components/views/settings/UserPersonalInfoSettings.tsx +++ b/src/components/views/settings/UserPersonalInfoSettings.tsx @@ -131,11 +131,7 @@ export const UserPersonalInfoSettings: React.FC = - + { +export const useUserTimezone = (userId: string): { timezone: string; friendly: string } | null => { const [timezone, setTimezone] = useState(); const [updateInterval, setUpdateInterval] = useState(); const [friendly, setFriendly] = useState(); @@ -23,17 +39,19 @@ export const useUserTimezone = (userId: string): { timezone: string, friendly: s if (supported !== undefined) { return; } - cli.doesServerSupportExtendedProfiles().then(setSupported).catch((ex) => { - console.warn("Unable to determine if extended profiles are supported", ex); - }); - }, [supported]); + cli.doesServerSupportExtendedProfiles() + .then(setSupported) + .catch((ex) => { + console.warn("Unable to determine if extended profiles are supported", ex); + }); + }, [supported, cli]); useEffect(() => { return () => { if (updateInterval) { clearInterval(updateInterval); } - } + }; }, [updateInterval]); useEffect(() => { @@ -42,21 +60,28 @@ export const useUserTimezone = (userId: string): { timezone: string, friendly: s } (async () => { try { - const tz = await cli.getExtendedProfileProperty(userId, 'us.cloke.msc4175.tz'); + const tz = await cli.getExtendedProfileProperty(userId, "us.cloke.msc4175.tz"); if (typeof tz !== "string") { // Err, definitely not a tz. - throw Error('Timezone value was not a string'); + throw Error("Timezone value was not a string"); } // This will validate the timezone for us. - Intl.DateTimeFormat(undefined, {timeZone: tz}); + // eslint-disable-next-line new-cap + Intl.DateTimeFormat(undefined, { timeZone: tz }); - const updateTime = () => { + const updateTime = (): void => { const currentTime = new Date(); - const friendly = currentTime.toLocaleString(undefined, { timeZone: tz, hour12: true, hour: "2-digit", minute: "2-digit", timeZoneName: "shortOffset"}); + const friendly = currentTime.toLocaleString(undefined, { + timeZone: tz, + hour12: true, + hour: "2-digit", + minute: "2-digit", + timeZoneName: "shortOffset", + }); setTimezone(tz); setFriendly(friendly); setUpdateInterval(setTimeout(updateTime, (60 - currentTime.getSeconds()) * 1000)); - } + }; updateTime(); } catch (ex) { setTimezone(undefined); @@ -66,10 +91,10 @@ export const useUserTimezone = (userId: string): { timezone: string, friendly: s // No timezone set, ignore. return; } - console.error('Could not render current timezone for user', ex); + console.error("Could not render current timezone for user", ex); } })(); - }, [supported, userId]); + }, [supported, userId, cli]); if (!timezone || !friendly) { return null; @@ -77,6 +102,6 @@ export const useUserTimezone = (userId: string): { timezone: string, friendly: s return { friendly, - timezone + timezone, }; -} \ No newline at end of file +}; diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 876b88f743f..c0d61c1506a 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -16,6 +16,7 @@ limitations under the License. */ import React, { ReactNode } from "react"; +import { UNSTABLE_MSC4133_EXTENDED_PROFILES } from "matrix-js-sdk/src/matrix"; import { _t, _td, TranslationKey } from "../languageHandler"; import { @@ -43,7 +44,6 @@ import ServerSupportUnstableFeatureController from "./controllers/ServerSupportU import { WatchManager } from "./WatchManager"; import { CustomTheme } from "../theme"; import AnalyticsController from "./controllers/AnalyticsController"; -import { UNSTABLE_MSC4133_EXTENDED_PROFILES } from "matrix-js-sdk/src/client" export const defaultWatchManager = new WatchManager();