Add message timestamps - #17
Merged
DefNotArham merged 1 commit intoAug 19, 2026
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsis declared with{ timestamps: true }, so every message document already carriescreatedAt, and both paths that reach the client already send it:loadMessage.controller.tsreturns the documents fromMessage.find(...)sendMessage.controller.tsemits the created document overnew-messageThe 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.ts—MessageTypegainscreatedAt: 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:Choices worth stating:
title), because a room can outlive a day and09:14alone does not say which one.<time dateTime>element, so the machine-readable ISO value stays available to assistive technology and is not reduced to decorative text.toLocaleTimeString/toLocaleStringwith no fixed locale, so the format follows the viewer's own settings rather than hard-coding a 12- or 24-hour convention.parseMessageDatereturnsnullfor a missing or unparseable value and the<time>element is skipped, so an unexpected payload shows no timestamp rather than the stringInvalid 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 buildreports 4 errors before my change and the same 4 after — allTS7016: Could not find a declaration file for module 'react-icons/...', inHero.tsx,RoomPage.tsx(×2) and the pre-existingFaCrownimport atChatPanel.tsx:4. They are pre-existing onmainand unrelated; my change introduces none, and nothing in the new code is flagged.You may want
@types/react-icons(or adeclare moduleshim) 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.