Skip to content

Commit 45f3dfe

Browse files
authored
Tune chat text sizing (#891)
1 parent 29f6ccf commit 45f3dfe

10 files changed

Lines changed: 261 additions & 55 deletions

File tree

‎desktop/src/features/channels/ui/ChannelPane.tsx‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,16 @@ export const ChannelPane = React.memo(function ChannelPane({
164164
}: ChannelPaneProps) {
165165
const timelineScrollRef = React.useRef<HTMLDivElement>(null);
166166
const composerWrapperRef = React.useRef<HTMLDivElement>(null);
167+
const isNonMemberView =
168+
activeChannel !== null &&
169+
!activeChannel.isMember &&
170+
activeChannel.visibility === "open" &&
171+
!activeChannel.archivedAt;
172+
const hasMainComposerOverlay = !isNonMemberView;
167173
useComposerHeightPadding(
168174
timelineScrollRef,
169175
composerWrapperRef,
170-
isSinglePanelView,
176+
`${isSinglePanelView}:${hasMainComposerOverlay}`,
171177
);
172178

173179
// Scope the edit target to the correct composer: if the message being edited
@@ -225,12 +231,6 @@ export const ChannelPane = React.memo(function ChannelPane({
225231
return true;
226232
}, [findLastOwnEditable, onEdit, threadHeadMessage, threadMessages]);
227233

228-
const isNonMemberView =
229-
activeChannel !== null &&
230-
!activeChannel.isMember &&
231-
activeChannel.visibility === "open" &&
232-
!activeChannel.archivedAt;
233-
234234
const isComposerDisabled =
235235
!activeChannel?.isMember ||
236236
activeChannel.archivedAt !== null ||
@@ -309,6 +309,7 @@ export const ChannelPane = React.memo(function ChannelPane({
309309
currentPubkey={currentPubkey}
310310
fetchOlder={fetchOlder}
311311
followThreadById={followThreadById}
312+
hasComposerOverlay={hasMainComposerOverlay}
312313
hasOlderMessages={hasOlderMessages}
313314
isFetchingOlder={isFetchingOlder}
314315
isFollowingThreadById={isFollowingThreadById}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import {
5+
formatDayHeading,
6+
formatShortMonthDayOrdinal,
7+
formatThreadSummaryLastReplyTime,
8+
} from "./dateFormatters.ts";
9+
10+
function localUnixSeconds(year, monthIndex, day) {
11+
return new Date(year, monthIndex, day, 12).getTime() / 1_000;
12+
}
13+
14+
function weekday(date) {
15+
return new Intl.DateTimeFormat("en-US", { weekday: "long" }).format(date);
16+
}
17+
18+
function month(date) {
19+
return new Intl.DateTimeFormat("en-US", { month: "long" }).format(date);
20+
}
21+
22+
test("formatShortMonthDayOrdinal formats month before ordinal day", () => {
23+
assert.equal(
24+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 19)),
25+
"May 19th",
26+
);
27+
});
28+
29+
test("formatShortMonthDayOrdinal handles ordinal suffixes", () => {
30+
assert.equal(
31+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 1)),
32+
"May 1st",
33+
);
34+
assert.equal(
35+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 2)),
36+
"May 2nd",
37+
);
38+
assert.equal(
39+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 3)),
40+
"May 3rd",
41+
);
42+
assert.equal(
43+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 4)),
44+
"May 4th",
45+
);
46+
assert.equal(
47+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 11)),
48+
"May 11th",
49+
);
50+
assert.equal(
51+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 12)),
52+
"May 12th",
53+
);
54+
assert.equal(
55+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 13)),
56+
"May 13th",
57+
);
58+
assert.equal(
59+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 21)),
60+
"May 21st",
61+
);
62+
assert.equal(
63+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 22)),
64+
"May 22nd",
65+
);
66+
assert.equal(
67+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 23)),
68+
"May 23rd",
69+
);
70+
assert.equal(
71+
formatShortMonthDayOrdinal(localUnixSeconds(2026, 4, 31)),
72+
"May 31st",
73+
);
74+
});
75+
76+
test("formatThreadSummaryLastReplyTime expands relative units", () => {
77+
const now = localUnixSeconds(2026, 4, 19);
78+
79+
assert.equal(formatThreadSummaryLastReplyTime(now - 30, now), "just now");
80+
assert.equal(formatThreadSummaryLastReplyTime(now - 60, now), "1 minute ago");
81+
assert.equal(
82+
formatThreadSummaryLastReplyTime(now - 180, now),
83+
"3 minutes ago",
84+
);
85+
assert.equal(
86+
formatThreadSummaryLastReplyTime(now - 3_600, now),
87+
"1 hour ago",
88+
);
89+
assert.equal(
90+
formatThreadSummaryLastReplyTime(now - 10_800, now),
91+
"3 hours ago",
92+
);
93+
assert.equal(
94+
formatThreadSummaryLastReplyTime(now - 86_400, now),
95+
"1 day ago",
96+
);
97+
assert.equal(
98+
formatThreadSummaryLastReplyTime(now - 345_600, now),
99+
"4 days ago",
100+
);
101+
});
102+
103+
test("formatThreadSummaryLastReplyTime uses ordinal dates for older replies", () => {
104+
const now = localUnixSeconds(2026, 5, 15);
105+
const replyAt = localUnixSeconds(2026, 4, 19);
106+
107+
assert.equal(formatThreadSummaryLastReplyTime(replyAt, now), "on May 19th");
108+
});
109+
110+
test("formatDayHeading omits the year for current-year dates", () => {
111+
const now = new Date();
112+
const date = new Date(now.getFullYear(), (now.getMonth() + 6) % 12, 19, 12);
113+
114+
assert.equal(
115+
formatDayHeading(date.getTime() / 1_000),
116+
`${weekday(date)}, ${month(date)} 19th`,
117+
);
118+
});
119+
120+
test("formatDayHeading includes the year for other years", () => {
121+
const year = new Date().getFullYear() - 1;
122+
const date = new Date(year, 4, 19, 12);
123+
124+
assert.equal(
125+
formatDayHeading(date.getTime() / 1_000),
126+
`${weekday(date)}, May 19th, ${year}`,
127+
);
128+
});

‎desktop/src/features/messages/lib/dateFormatters.ts‎

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* - `formatFullDateTime` — verbose string for tooltips
66
* ("Wednesday, April 2, 2026 at 2:34 PM").
77
* - `formatDayHeading` — label for day dividers / sticky headers.
8-
* Returns "Today", "Yesterday", or a date like "Monday, March 31, 2026".
8+
* Returns "Today", "Yesterday", or a date like "Monday, March 31st".
99
* - `isSameDay` — compare two unix-second timestamps.
1010
*/
1111

@@ -23,11 +23,16 @@ const FULL_DATE_TIME_FORMATTER = new Intl.DateTimeFormat("en-US", {
2323
minute: "2-digit",
2424
});
2525

26-
const DAY_HEADING_FORMATTER = new Intl.DateTimeFormat("en-US", {
26+
const WEEKDAY_FORMATTER = new Intl.DateTimeFormat("en-US", {
2727
weekday: "long",
28-
year: "numeric",
28+
});
29+
30+
const LONG_MONTH_FORMATTER = new Intl.DateTimeFormat("en-US", {
2931
month: "long",
30-
day: "numeric",
32+
});
33+
34+
const SHORT_MONTH_FORMATTER = new Intl.DateTimeFormat("en-US", {
35+
month: "short",
3136
});
3237

3338
/** Short clock time, e.g. "2:34 PM". */
@@ -42,7 +47,8 @@ export function formatFullDateTime(unixSeconds: number): string {
4247

4348
/**
4449
* Human-friendly day label for dividers and sticky headers.
45-
* Returns "Today", "Yesterday", or a full date like "Monday, March 31, 2026".
50+
* Returns "Today", "Yesterday", a current-year date like "Monday, March 31st",
51+
* or a prior-year date like "Monday, March 31st, 2025".
4652
*/
4753
export function formatDayHeading(unixSeconds: number): string {
4854
const date = new Date(unixSeconds * 1_000);
@@ -58,18 +64,81 @@ export function formatDayHeading(unixSeconds: number): string {
5864
return "Yesterday";
5965
}
6066

61-
return DAY_HEADING_FORMATTER.format(date);
67+
const dateLabel = `${WEEKDAY_FORMATTER.format(date)}, ${formatMonthDayOrdinal(
68+
date,
69+
LONG_MONTH_FORMATTER,
70+
)}`;
71+
return date.getFullYear() === now.getFullYear()
72+
? dateLabel
73+
: `${dateLabel}, ${date.getFullYear()}`;
6274
}
6375

6476
/** True when two unix-second timestamps fall on the same calendar day (local time). */
6577
export function isSameDay(a: number, b: number): boolean {
6678
return isSameDayDate(new Date(a * 1_000), new Date(b * 1_000));
6779
}
6880

81+
/** Short month + ordinal day, e.g. "May 19th". */
82+
export function formatShortMonthDayOrdinal(unixSeconds: number): string {
83+
return formatMonthDayOrdinal(
84+
new Date(unixSeconds * 1_000),
85+
SHORT_MONTH_FORMATTER,
86+
);
87+
}
88+
89+
/**
90+
* Relative thread-summary timestamp with expanded units, e.g. "3 hours ago",
91+
* falling back to "on May 19th" for older replies.
92+
*/
93+
export function formatThreadSummaryLastReplyTime(
94+
unixSeconds: number,
95+
nowSeconds = Date.now() / 1_000,
96+
): string {
97+
const diff = Math.max(0, nowSeconds - unixSeconds);
98+
99+
if (diff < 60) return "just now";
100+
if (diff < 3_600) return formatAgo(Math.floor(diff / 60), "minute");
101+
if (diff < 86_400) return formatAgo(Math.floor(diff / 3_600), "hour");
102+
if (diff < 604_800) return formatAgo(Math.floor(diff / 86_400), "day");
103+
104+
return `on ${formatShortMonthDayOrdinal(unixSeconds)}`;
105+
}
106+
69107
function isSameDayDate(a: Date, b: Date): boolean {
70108
return (
71109
a.getFullYear() === b.getFullYear() &&
72110
a.getMonth() === b.getMonth() &&
73111
a.getDate() === b.getDate()
74112
);
75113
}
114+
115+
function formatMonthDayOrdinal(
116+
date: Date,
117+
monthFormatter: Intl.DateTimeFormat,
118+
): string {
119+
return `${monthFormatter.format(date)} ${date.getDate()}${ordinalSuffix(
120+
date.getDate(),
121+
)}`;
122+
}
123+
124+
function formatAgo(value: number, unit: string): string {
125+
return `${value} ${unit}${value === 1 ? "" : "s"} ago`;
126+
}
127+
128+
function ordinalSuffix(day: number): string {
129+
const lastTwoDigits = day % 100;
130+
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
131+
return "th";
132+
}
133+
134+
switch (day % 10) {
135+
case 1:
136+
return "st";
137+
case 2:
138+
return "nd";
139+
case 3:
140+
return "rd";
141+
default:
142+
return "th";
143+
}
144+
}

‎desktop/src/features/messages/ui/MessageRow.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export const MessageRow = React.memo(
148148
return (
149149
<Markdown
150150
channelNames={channelNames}
151-
className="max-w-full"
151+
className="max-w-full text-[15px] leading-6"
152152
content={message.body}
153153
customEmoji={customEmoji}
154154
imetaByUrl={imetaByUrl}
@@ -200,11 +200,11 @@ export const MessageRow = React.memo(
200200
);
201201

202202
const authorNode = message.pubkey ? (
203-
<span className="truncate text-sm font-semibold leading-none tracking-tight hover:underline">
203+
<span className="truncate text-[15px] font-semibold leading-none tracking-tight hover:underline">
204204
{message.author}
205205
</span>
206206
) : (
207-
<h3 className="truncate text-sm font-semibold leading-none tracking-tight">
207+
<h3 className="truncate text-[15px] font-semibold leading-none tracking-tight">
208208
{message.author}
209209
</h3>
210210
);

‎desktop/src/features/messages/ui/MessageThreadSummaryRow.tsx‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,13 @@ import type {
33
TimelineThreadSummaryParticipant,
44
} from "@/features/messages/lib/threadPanel";
55
import type { TimelineMessage } from "@/features/messages/types";
6+
import { formatThreadSummaryLastReplyTime } from "@/features/messages/lib/dateFormatters";
67
import { UserAvatar } from "@/shared/ui/UserAvatar";
78

89
const MESSAGE_TEXT_OFFSET_PX = 54;
910
const MESSAGE_BODY_OFFSET_PX = MESSAGE_TEXT_OFFSET_PX + 4;
1011
const NESTED_REPLY_OFFSET_PX = 28;
1112

12-
function formatLastReplyTime(unixSeconds: number): string {
13-
const now = Date.now() / 1_000;
14-
const diff = now - unixSeconds;
15-
16-
if (diff < 60) return "just now";
17-
if (diff < 3_600) return `${Math.floor(diff / 60)}m ago`;
18-
if (diff < 86_400) return `${Math.floor(diff / 3_600)}h ago`;
19-
if (diff < 604_800) return `${Math.floor(diff / 86_400)}d ago`;
20-
21-
const date = new Date(unixSeconds * 1_000).toLocaleDateString(undefined, {
22-
month: "short",
23-
day: "numeric",
24-
});
25-
return `on ${date}`;
26-
}
27-
2813
function ParticipantAvatar({
2914
hasNextParticipant,
3015
participant,
@@ -69,7 +54,7 @@ export function MessageThreadSummaryRow({
6954
const marginLeftPx = indentPx + MESSAGE_BODY_OFFSET_PX;
7055
const replyLabel = summary.replyCount === 1 ? "reply" : "replies";
7156
const summaryAriaLabel = summary.lastReplyAt
72-
? `View thread with ${summary.replyCount} ${replyLabel}, last reply ${formatLastReplyTime(summary.lastReplyAt)}`
57+
? `View thread with ${summary.replyCount} ${replyLabel}, last reply ${formatThreadSummaryLastReplyTime(summary.lastReplyAt)}`
7358
: `View thread with ${summary.replyCount} ${replyLabel}`;
7459
const depthGuideOffsets =
7560
visibleDepth === 0
@@ -137,7 +122,8 @@ export function MessageThreadSummaryRow({
137122
className="col-start-1 row-start-1 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0"
138123
data-testid="message-thread-summary-last-reply"
139124
>
140-
last reply {formatLastReplyTime(summary.lastReplyAt)}
125+
last reply{" "}
126+
{formatThreadSummaryLastReplyTime(summary.lastReplyAt)}
141127
</span>
142128
<span
143129
className="col-start-1 row-start-1 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"

0 commit comments

Comments
 (0)