Skip to content

Add message timestamps - #17

Merged
DefNotArham merged 1 commit into
DefNotArham:mainfrom
dchaudhari7177:feat/message-timestamps
Aug 19, 2026
Merged

Add message timestamps#17
DefNotArham merged 1 commit into
DefNotArham:mainfrom
dchaudhari7177:feat/message-timestamps

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

Closes #16.

The issue is a one-liner, so here is the reading I worked to: chat messages show who and what but never when, which matters in a room that stays open for hours and whose history you can scroll back through.

The data already existed

No backend change was needed. Message.model.ts is declared with { timestamps: true }, so every message document already carries createdAt, and both paths that reach the client already send it:

  • loadMessage.controller.ts returns the documents from Message.find(...)
  • sendMessage.controller.ts emits the created document over new-message

The only thing missing was that the frontend never declared or displayed the field. So this is a two-file frontend change.

What changed

room.store.tsMessageType gains createdAt: string, with a comment noting where it comes from so it does not look like a field someone must now populate by hand.

ChatPanel.tsx — the username line becomes a flex row holding the name and a timestamp:

<time dateTime={message.createdAt} title={formatMessageTimestamp(message.createdAt)}>
  {formatMessageTime(message.createdAt)}
</time>

Choices worth stating:

  • Hours and minutes only in the visible label. It sits inline beside the username in a narrow side panel, so a full date would crowd the name off the line.
  • Full local date and time on hover (title), because a room can outlive a day and 09:14 alone does not say which one.
  • A real <time dateTime> element, so the machine-readable ISO value stays available to assistive technology and is not reduced to decorative text.
  • toLocaleTimeString / toLocaleString with no fixed locale, so the format follows the viewer's own settings rather than hard-coding a 12- or 24-hour convention.
  • Bad input renders nothing. parseMessageDate returns null for a missing or unparseable value and the <time> element is skipped, so an unexpected payload shows no timestamp rather than the string Invalid Date.

No change to the store's send path, the socket wiring, the backend, or the existing auto-scroll behaviour.

Verification

Windows 11, Node v24.17.0, TypeScript 6.0.3.

npm run build reports 4 errors before my change and the same 4 after — all TS7016: Could not find a declaration file for module 'react-icons/...', in Hero.tsx, RoomPage.tsx (×2) and the pre-existing FaCrown import at ChatPanel.tsx:4. They are pre-existing on main and unrelated; my change introduces none, and nothing in the new code is flagged.

You may want @types/react-icons (or a declare module shim) as a separate fix — happy to open that as its own issue if it is not already known.

I was not able to run the app end to end against MongoDB to screenshot the result, so the rendering is verified by types and by reading the payload shape rather than visually. Say the word if you would like the timestamp styled differently.

Messages render as username plus content, with no indication of when they
arrived. In a watch room that stays open for hours, and where users
scroll back through history, there is no way to tell a message from a
minute ago from one from the start of the session.

The data was already there and unused: the Message model sets Mongoose
timestamps, so both the load-messages response and the socket payload
carry createdAt. Only the frontend needed to know about it -- MessageType
gains the field, and ChatPanel renders it beside the username.

Shown as hours and minutes, since it sits next to the name where space is
tight, with the full local date and time on hover because a room can
outlive a day. Wrapped in <time dateTime> so the machine-readable value
survives for assistive technology. An unparseable or missing timestamp
renders nothing rather than "Invalid Date".

Closes DefNotArham#16
@DefNotArham
DefNotArham merged commit 3a67f8f into DefNotArham:main Aug 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants