BetterTimestamps: add option to hide date on today's messages/divider
This commit is contained in:
parent
5189265133
commit
61977e5b9b
3 changed files with 21 additions and 1 deletions
|
|
@ -1,9 +1,18 @@
|
|||
import { moment } from "@vendetta/metro/common";
|
||||
import { storage } from "@vendetta/plugin";
|
||||
|
||||
export type TimestampMode = "calendar" | "relative" | "custom" | "iso";
|
||||
|
||||
export default function renderTimestamp(timestamp: any, mode: TimestampMode = storage.selected): string {
|
||||
try {
|
||||
if (
|
||||
storage.hideDateIfToday &&
|
||||
(mode === "calendar" || mode === "custom") &&
|
||||
typeof timestamp.isSame === "function" &&
|
||||
timestamp.isSame(moment(), "day")
|
||||
) {
|
||||
return timestamp.format("LT");
|
||||
}
|
||||
switch (mode) {
|
||||
case "calendar": return timestamp.calendar();
|
||||
case "relative": return timestamp.fromNow();
|
||||
|
|
|
|||
|
|
@ -42,7 +42,12 @@ export default function patchRowManager(): () => void {
|
|||
const parsed = parseTimestamp(row.message.timestamp);
|
||||
row.message.__customTimestamp = wrapTimestamp(parsed);
|
||||
} 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 {
|
||||
// Leave this row's timestamp untouched.
|
||||
|
|
|
|||
|
|
@ -47,6 +47,12 @@ export default function Settings() {
|
|||
})}
|
||||
</TableRowGroup>
|
||||
<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
|
||||
label="Always show name & avatar"
|
||||
subLabel="Shows the username, avatar, and timestamp on every message instead of grouping consecutive messages"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue