Skip to content

Email for professionals and teams

[thread] improve style for unread messages

Hieu Nguyen (Jack)fe1a4f92c9c6
diff --git a/src/app/(dashboard)/inbox/[messageId]/page.tsx b/src/app/(dashboard)/inbox/[messageId]/page.tsx
index 13dffa1..f0ecb3a 100644
--- a/src/app/(dashboard)/inbox/[messageId]/page.tsx
+++ b/src/app/(dashboard)/inbox/[messageId]/page.tsx
@@ -182,7 +182,7 @@ export default function MessageDetailPage() {
<article className="px-6 py-4">
<div className="flex items-start justify-between pb-5">
<div>
- <p className="text-sm text-neutral-900">
+ <p className="text-sm text-neutral-900 mt-1.25">
<b>
{message.direction === "inbound" ? (
<ContactDetailsTrigger
diff --git a/src/app/api/messages/route.ts b/src/app/api/messages/route.ts
index 2227626..a05172d 100644
--- a/src/app/api/messages/route.ts
+++ b/src/app/api/messages/route.ts
@@ -163,7 +163,7 @@ export async function GET(request: Request) {
.select({
threadId: messages.threadId,
total: count(),
- unread: sum(sql`case when ${messages.read} = 0 and ${messages.direction} = 'inbound' then 1 else 0 end`),
+ unread: sum(sql`case when ${messages.read} = 0 then 1 else 0 end`),
})
.from(messages)
.where(and(scope, inArray(messages.threadId, threadIds), isNotNull(messages.threadId), notInArray(messages.status, ["draft", "trash"])))
diff --git a/src/components/messages/conversation-thread.tsx b/src/components/messages/conversation-thread.tsx
index fcb1a83..8b2e21c 100644
--- a/src/components/messages/conversation-thread.tsx
+++ b/src/components/messages/conversation-thread.tsx
@@ -17,6 +17,7 @@ import {
getConversationSenderEmail,
partitionThread,
} from "./conversation-thread-utils";
+import clsx from "clsx";
/**
* The other messages in a conversation, ordered oldest to newest and collapsed
@@ -47,8 +48,8 @@ export function ConversationThread({
aria-label={position === "before" ? "Earlier messages in this conversation" : "Later messages in this conversation"}
className={cn(position === (latestMessagesFirst ? "before" : "after") ? "pb-6" : "")}
>
- <ol className={cn(!collapsed && "divide-y divide-neutral-200/50", "border-b border-neutral-200")}>
- <li className={latestMessagesFirst ? "border-t" : "border-t-0"}>
+ <ol className={cn(!collapsed && "divide-y divide-neutral-200/50", latestMessagesFirst ? "border-y" : "border-b", "border-neutral-200")}>
+ <li className={"border-t-0" }>
<ConversationMessageCard
message={firstMessage}
mailboxId={mailboxId}
@@ -160,7 +161,7 @@ export function ConversationMessageCard({
{expanded && recipients && <span className="text-xs font-normal text-neutral-500">to {recipients}</span>}
</div>
{!expanded && (
- <span className="block truncate text-[13px] text-neutral-500">{message.snippet || "No preview"}</span>
+ <span className={clsx( !locallyRead ? "font-semibold" : "text-neutral-500", "block truncate text-[13px]")}>{message.snippet || "No preview"}</span>
)}
</span>
</button>
@@ -177,14 +178,6 @@ export function ConversationMessageCard({
</div>
{expanded && body && (
<div className="pb-4 pt-2">
- {/* <p className="mb-3 text-xs text-neutral-500">
- {message.direction === "inbound" ? (
- <ContactDetailsTrigger mailboxId={mailboxId} address={message.fromAddr} name={sender} />
- ) : (
- sender
- )}{" "}
- &lt;{getEmailAddress(message.fromAddr)}&gt;
- </p> */}
{body.html ? (
<div className="email-body max-w-none text-sm text-neutral-900" dangerouslySetInnerHTML={{ __html: body.html }} />
) : (
diff --git a/src/components/messages/message-folder-page.tsx b/src/components/messages/message-folder-page.tsx
index d317ead..f323cf0 100644
--- a/src/components/messages/message-folder-page.tsx
+++ b/src/components/messages/message-folder-page.tsx
@@ -28,6 +28,7 @@ import {
getMessageParty,
getMessagePartyClassName,
getMessagePreview,
+ isMessageListRowUnread,
formatEmailPageTitle,
getMailboxAddress,
runBulkMessageAction,
@@ -50,12 +51,13 @@ function MessageListRow({
const Icon = config.icon;
const { openDraftComposer } = useCompose();
const [read, setRead] = useState(message.read);
+ const [threadUnread, setThreadUnread] = useState(message.threadUnread);
const [starred, setStarred] = useState(message.starred);
useEffect(() => setRead(message.read), [message.read]);
+ useEffect(() => setThreadUnread(message.threadUnread), [message.threadUnread]);
useEffect(() => setStarred(message.starred), [message.starred]);
- const rowMessage = { ...message, read, starred };
- // A conversation row is unread when any message in it still is.
- const unread = (rowMessage.direction === "inbound" && !rowMessage.read) || (message.threadUnread ?? 0) > 0;
+ const rowMessage = { ...message, read, starred, threadUnread };
+ const unread = isMessageListRowUnread(rowMessage);
const draggable = config.folder === "inbox" && message.direction === "inbound";
const party = getMessageParty(rowMessage, config.folder, currentAccountName);
const preview = getMessagePreview(rowMessage, config.folder);
@@ -63,15 +65,18 @@ function MessageListRow({
const navigation = useMessageNavigation(href, rowMessage);
function onMessageNavigate(event: MouseEvent<HTMLAnchorElement>) {
- if (unread && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
+ if (!read && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
+ const previousThreadUnread = threadUnread;
setRead(true);
- dispatchMessageCountsDelta({ inboxUnreadDelta: -1 });
+ if (previousThreadUnread !== undefined) setThreadUnread(Math.max(0, previousThreadUnread - 1));
+ if (message.direction === "inbound") dispatchMessageCountsDelta({ inboxUnreadDelta: -1 });
void runBulkMessageAction([message.id], "read", false).catch(() => {
setRead(false);
- dispatchMessageCountsDelta({ inboxUnreadDelta: 1 });
+ setThreadUnread(previousThreadUnread);
+ if (message.direction === "inbound") dispatchMessageCountsDelta({ inboxUnreadDelta: 1 });
});
}
- navigation.onNavigate(event, unread);
+ navigation.onNavigate(event, !read);
}
if (compact && config.folder !== "drafts") {
diff --git a/src/components/messages/utils.ts b/src/components/messages/utils.ts
index 765bb84..87efaa1 100644
--- a/src/components/messages/utils.ts
+++ b/src/components/messages/utils.ts
@@ -29,10 +29,16 @@ export function formatRecipientSummary(toAddr: string, firstContactName?: string
export function getMessagePartyClassName(message: Message, folder: MessageFolderConfig["folder"]) {
if (folder === "drafts") return "truncate font-semibold text-red-600";
- const unread = message.direction === "inbound" && !message.read;
+ const unread = isMessageListRowUnread(message);
return `truncate ${unread ? "font-bold text-neutral-900" : "text-neutral-800"}`;
}
+/** A grouped row is read only after every message represented by it is read. */
+export function isMessageListRowUnread(message: Message): boolean {
+ if (message.threadMessageIds) return (message.threadUnread ?? 0) > 0;
+ return message.direction === "inbound" && !message.read;
+}
+
export function getMessagePreview(message: Message, folder: MessageFolderConfig["folder"]) {
if (folder === "drafts") return message.snippet || message.toAddr || "No content";
return message.snippet || "No preview";
diff --git a/src/hooks/types.d.ts b/src/hooks/types.d.ts
index 55b5ea3..bed1531 100644
--- a/src/hooks/types.d.ts
+++ b/src/hooks/types.d.ts
@@ -32,7 +32,7 @@ export type Message = {
references?: string | null;
/** Messages in the same conversation (excluding drafts and trash), when the list API computed it. */
threadCount?: number;
- /** Unread inbound messages in the conversation. */
+ /** Unread messages in the conversation; zero means the grouped thread is read. */
threadUnread?: number;
/** In conversation view: every message this row stands for within the current folder. */
threadMessageIds?: string[];