feat(timezones): show recipient timezone in dms + fix showLocalTimezone (#1244)

* feat(timezones): show recipient timezone in dms

* fix(timezones): make sure showOwnTimezone is not bypassed

* fix(timezones): prevent showLocalTimezone from minifying every timezone instead of just local
This commit is contained in:
Luca 2026-07-11 02:24:35 +02:00 • committed by GitHub
parent a9e077fc3a
commit 634820dbaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,7 +14,7 @@ import { Devs, EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { Message, User } from "@vencord/discord-types";
import { findByPropsLazy, findCssClassesLazy } from "@webpack";
import { Button, Menu, openModal, showToast, Toasts, Tooltip, useEffect, UserStore, useState } from "@webpack/common";
import { Button, ChannelStore, Menu, openModal, showToast, Toasts, Tooltip, useEffect, UserStore, useState } from "@webpack/common";
import { deleteTimezone, getTimezone, loadDatabaseTimezones, setUserDatabaseTimezone } from "./database";
import { SetTimezoneModal } from "./TimezoneModal";
@ -66,6 +66,12 @@ export const settings = definePluginSettings({
default: true
},
recipientTimezoneInDms: {
type: OptionType.BOOLEAN,
description: "In DMs, show the recipient's timezone on your messages",
default: false
},
showProfileTime: {
type: OptionType.BOOLEAN,
description: "Show time in profiles",
@ -201,13 +207,13 @@ const TimestampComponent = ErrorBoundary.wrap(({ userId, timestamp, type }: Prop
if (settings.store.showTimezoneInfo) {
const userTimezone = getSystemTimezone();
if (timezone === userTimezone && !settings.store.showLocalTimezone) {
isLocal = timezone === userTimezone;
if (isLocal && !settings.store.showLocalTimezone) {
displayTime = "local";
isLocal = true;
} else {
const timezoneInfo = getTimezoneAbbreviation(timezone, currentTime);
const tz = timezoneInfo || timezone;
const hideLocalTime = settings.store.showLocalTimezone && type === "message";
const hideLocalTime = isLocal && type === "message";
displayTime = hideLocalTime ? tz : `${shortTime} ${tz}`;
}
}
@ -349,9 +355,20 @@ export default definePlugin({
},
renderMessageTimezone: (props?: { message?: Message; }) => {
if (!settings.store.showMessageHeaderTime || !props?.message) return null;
if (props.message.author.id === UserStore.getCurrentUser().id && !settings.store["Show Own Timezone"]) return null;
const { showMessageHeaderTime, recipientTimezoneInDms, "Show Own Timezone": showOwnTimezone } = settings.store;
return <TimestampComponent userId={props.message.author.id} timestamp={props.message.timestamp.toISOString()} type="message" />;
if (!showMessageHeaderTime || !props?.message) return null;
let userId = props.message.author.id;
if (userId === UserStore.getCurrentUser().id) {
const channel = recipientTimezoneInDms ? ChannelStore.getChannel(props.message.channel_id) : undefined;
const recipientId = channel?.type === 1 ? channel.recipients[0] : undefined;
if (recipientId && resolveUserTimezone(recipientId)) userId = recipientId;
else if (!showOwnTimezone) return null;
}
return <TimestampComponent userId={userId} timestamp={props.message.timestamp.toISOString()} type="message" />;
}
});