BetterTimestamps: add option to hide date on today's messages/divider

This commit is contained in:
Ally Founder 2026-08-18 22:30:34 -04:00
parent 5189265133
commit 61977e5b9b
3 changed files with 21 additions and 1 deletions

View file

@ -1,9 +1,18 @@
import { moment } from "@vendetta/metro/common";
import { storage } from "@vendetta/plugin"; import { storage } from "@vendetta/plugin";
export type TimestampMode = "calendar" | "relative" | "custom" | "iso"; export type TimestampMode = "calendar" | "relative" | "custom" | "iso";
export default function renderTimestamp(timestamp: any, mode: TimestampMode = storage.selected): string { export default function renderTimestamp(timestamp: any, mode: TimestampMode = storage.selected): string {
try { try {
if (
storage.hideDateIfToday &&
(mode === "calendar" || mode === "custom") &&
typeof timestamp.isSame === "function" &&
timestamp.isSame(moment(), "day")
) {
return timestamp.format("LT");
}
switch (mode) { switch (mode) {
case "calendar": return timestamp.calendar(); case "calendar": return timestamp.calendar();
case "relative": return timestamp.fromNow(); case "relative": return timestamp.fromNow();

View file

@ -42,7 +42,12 @@ export default function patchRowManager(): () => void {
const parsed = parseTimestamp(row.message.timestamp); const parsed = parseTimestamp(row.message.timestamp);
row.message.__customTimestamp = wrapTimestamp(parsed); row.message.__customTimestamp = wrapTimestamp(parsed);
} else if (row.rowType === "day") { } else if (row.rowType === "day") {
row.text = renderTimestamp(moment(row.text, "LL")); const parsed = moment(row.text, "LL");
if (storage.hideDateIfToday && parsed.isValid() && parsed.isSame(moment(), "day")) {
row.text = "Today";
} else {
row.text = renderTimestamp(parsed);
}
} }
} catch { } catch {
// Leave this row's timestamp untouched. // Leave this row's timestamp untouched.

View file

@ -47,6 +47,12 @@ export default function Settings() {
})} })}
</TableRowGroup> </TableRowGroup>
<TableRowGroup title="Layout"> <TableRowGroup title="Layout">
<TableSwitchRow
label="Hide date if today"
subLabel="Show time only for today's messages and just 'Today' for today's divider. Calendar & Custom formats only."
value={!!storage.hideDateIfToday}
onValueChange={(v: boolean) => { storage.hideDateIfToday = v; }}
/>
<TableSwitchRow <TableSwitchRow
label="Always show name & avatar" label="Always show name & avatar"
subLabel="Shows the username, avatar, and timestamp on every message instead of grouping consecutive messages" subLabel="Shows the username, avatar, and timestamp on every message instead of grouping consecutive messages"