Skip to content

fix: show Today/Yesterday labels in Livechat message separator#40592

Open
Varun789-mx wants to merge 3 commits into
RocketChat:developfrom
Varun789-mx:fix/message-separator-today-label
Open

fix: show Today/Yesterday labels in Livechat message separator#40592
Varun789-mx wants to merge 3 commits into
RocketChat:developfrom
Varun789-mx:fix/message-separator-today-label

Conversation

@Varun789-mx

@Varun789-mx Varun789-mx commented May 17, 2026

Copy link
Copy Markdown

Proposed changes (including videos or screenshots)

Updated the MessageSeparator component in the Livechat widget to display user-friendly labels instead of the full formatted date.

  • If the message was sent today, the separator now shows: Today
  • If the message was sent yesterday, the separator now shows: Yesterday
  • For all older messages, the existing formatted date (e.g. MAY 15, 2026) is still displayed

This was achieved by adding a getDateLabel helper function that compares the message date against today and yesterday using year/month/day matching before falling back to the default i18n date formatter .

⚠️ Note: Due to a technical issue (OOM error in WSL2 while running the monorepo dev build) the build usually stops on some random package or crashes, I was unable to run and verify this locally. Could a maintainer please run this locally and attach screenshots so I can include them here? Thank you!

Issue(s)

Closes #40588

Steps to test or reproduce

  1. Open the Livechat widget
  2. Send a message or open a conversation that has messages from today
  3. Observe the date separator — it should now display Today instead of the full date (e.g. MAY 17, 2026)
  4. Optionally check a conversation with messages from yesterday — separator should display Yesterday
  5. Check older conversations — full formatted date should still appear as before

Further comments

The fix is minimal and self-contained within packages/livechat/src/components/Messages/MessageSeparator/index.tsx. The isSameDay utility is defined inline; if the team prefers, it can be extracted to a shared helper or replaced with isToday/isYesterday from date-fns if that is already a project dependency.

Summary by CodeRabbit

  • Improvements
    • Message date separators now show localized "Today" and "Yesterday" when applicable; older dates display a locale-formatted date in a consistent uppercase style. Invalid or unrecognized dates render no label.
    • Unread separators now display the updated "Unread Messages" label for clarity and consistent localization.

Review Change Stack

@Varun789-mx Varun789-mx requested review from a team as code owners May 17, 2026 17:35
@dionisio-bot

dionisio-bot Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented May 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b62edfc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@rocket.chat/livechat Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a getDateLabel helper to produce localized "Today"/"Yesterday" or an uppercased formatted date; MessageSeparator now uses this helper for its date prop rendering and shows t('Unread_Messages') when date is absent and unread is true.

Changes

Message separator date display

Layer / File(s) Summary
Date label helper and MessageSeparator integration
packages/livechat/src/components/Messages/MessageSeparator/index.tsx
Adds isSameDay and getDateLabel(date, t) to validate and compute localized labels (Today/Yesterday) or an uppercased formatted date via message_separator_date; MessageSeparator precomputes dateLabel and renders it when date is present, otherwise shows t('Unread_Messages') when unread.
Changeset entry
.changeset/young-bars-raise.md
Adds a changeset marking @rocket.chat/livechat as a minor release and documents the MessageSeparator date-label behavior change.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels: type: feature

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR implementation fulfills all linked issue #40588 requirements: displays 'Today' for current-day messages, 'Yesterday' for previous-day messages, and formatted dates for older messages via a new getDateLabel helper.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the linked issue requirements; the MessageSeparator component update and Changeset entry are appropriately focused.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: adding 'Today'/'Yesterday' labels to the Livechat message separator component, which is the core objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Varun789-mx Varun789-mx force-pushed the fix/message-separator-today-label branch from eff476c to 32be188 Compare May 17, 2026 17:37

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@Varun789-mx Varun789-mx changed the title Fix/message separator today label fix: show 'Today'/'Yesterday' labels in message separator instead of full date May 17, 2026
@coderabbitai coderabbitai Bot added the type: feature Pull requests that introduces new feature label May 17, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/meteor/app/custom-oauth/server/custom_oauth_server.js`:
- Around line 144-150: The new fetch call that supplies allowList:
settings.get('SSRF_Allowlist') (used when posting to this.tokenPath) enforces a
safe-by-default SSRF whitelist which will block OAuth providers unless admins
configure SSRF_Allowlist; update the project migration/config documentation and
any deployment runbooks to state that OAuth integrations require explicit
configuration of SSRF_Allowlist per provider (or provide examples), and add a
clear admin-facing note where OAuth provider settings are documented
(referencing this.tokenPath and the allowList setting) so operators know to
populate SSRF_Allowlist to restore existing OAuth flows.

In `@packages/livechat/src/components/Messages/MessageSeparator/index.tsx`:
- Line 19: The code assigns messageDate = new Date(date) without validation,
which can produce an Invalid Date and break downstream comparisons/formatting;
update the MessageSeparator component to validate the incoming date string
before creating the Date object (e.g., use Date.parse(date) or construct and
then check isNaN(messageDate.getTime())), and if invalid handle
gracefully—either skip rendering the separator, fall back to a safe default
date, or log/return null so the i18next formatter never receives an Invalid
Date; apply this check around the messageDate creation and any comparisons that
use messageDate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92dd90e7-309b-4992-9980-87778c3e7840

📥 Commits

Reviewing files that changed from the base of the PR and between 80b0f14 and b8f57de.

📒 Files selected for processing (2)
  • apps/meteor/app/custom-oauth/server/custom_oauth_server.js
  • packages/livechat/src/components/Messages/MessageSeparator/index.tsx
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/custom-oauth/server/custom_oauth_server.js
  • packages/livechat/src/components/Messages/MessageSeparator/index.tsx
🧠 Learnings (2)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • packages/livechat/src/components/Messages/MessageSeparator/index.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/livechat/src/components/Messages/MessageSeparator/index.tsx
🔇 Additional comments (3)
apps/meteor/app/custom-oauth/server/custom_oauth_server.js (2)

184-185: LGTM!


291-292: LGTM!

packages/livechat/src/components/Messages/MessageSeparator/index.tsx (1)

57-59: LGTM!

Comment thread apps/meteor/app/custom-oauth/server/custom_oauth_server.js
@Varun789-mx Varun789-mx force-pushed the fix/message-separator-today-label branch 3 times, most recently from 1c757b1 to 39a341e Compare May 17, 2026 17:56
@coderabbitai coderabbitai Bot removed the type: feature Pull requests that introduces new feature label May 17, 2026
use?: any;
};

const getDateLabel = (date: string, t: TFunction): string => {

@psshrijith psshrijith May 22, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this version looks more readable. @Varun789-mx

const isSameDay = (a: Date, b: Date) =>
	a.getFullYear() === b.getFullYear() &&
	a.getMonth() === b.getMonth() &&
	a.getDate() === b.getDate();

const getDateLabel = (date: string, t: TFunction): string => {
	const messageDate = new Date(date);

	if (isNaN(messageDate.getTime())) return '';

	const today = new Date();

	if (isSameDay(messageDate, today)) {
		return t('today');
	}

	const yesterday = new Date(today);
	yesterday.setDate(today.getDate() - 1);

	if (isSameDay(messageDate, yesterday)) {
		return t('yesterday');
	}

	return t('message_separator_date', {
		val: messageDate,
		formatParams: {
			val: {
				month: 'short',
				day: '2-digit',
				year: 'numeric',
			},
		},
	}).toUpperCase();
};

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this LGTM and i place the

const isSameDay = (a: Date, b: Date) =>
	a.getFullYear() === b.getFullYear() &&
	a.getMonth() === b.getMonth() &&
	a.getDate() === b.getDate();

outside the main which will prevent multiple function calls make it more efficient

@Varun789-mx Varun789-mx force-pushed the fix/message-separator-today-label branch from 0e56657 to 7a37084 Compare May 24, 2026 07:20
@coderabbitai coderabbitai Bot added the type: feature Pull requests that introduces new feature label May 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/livechat/src/components/Messages/MessageSeparator/index.tsx (1)

63-64: ⚡ Quick win

Consider more explicit handling of the date label fallback.

The current logic (!!date && getDateLabel(date, t)) || (unread && t('unread_messages')) works correctly, but the fallback behavior when getDateLabel returns an empty string (invalid date) is implicit. While date and unread are mutually exclusive in practice, a more explicit conditional would improve clarity.

♻️ Optional refactor for clarity
-				{(!!date && getDateLabel(date, t)) ||
-					(unread && t('unread_messages'))}
+				{date ? getDateLabel(date, t) : unread ? t('unread_messages') : null}

Or if you prefer to handle the empty string case explicitly:

-				{(!!date && getDateLabel(date, t)) ||
-					(unread && t('unread_messages'))}
+				{date ? getDateLabel(date, t) || null : unread ? t('unread_messages') : null}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/livechat/src/components/Messages/MessageSeparator/index.tsx` around
lines 63 - 64, The current inline expression in MessageSeparator ((!!date &&
getDateLabel(date, t)) || (unread && t('unread_messages'))) can silently treat
an empty string from getDateLabel as falsy; change to an explicit check: compute
a dateLabel by calling getDateLabel only when date is present (e.g., const
dateLabel = date ? getDateLabel(date, t) : ''), then render dateLabel if it is
non-empty else render unread ? t('unread_messages') : null so that empty string
from getDateLabel is handled explicitly; update the JSX in the MessageSeparator
component to use these variables (dateLabel, unread, t).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/livechat/src/components/Messages/MessageSeparator/index.tsx`:
- Line 34: MessageSeparator calls t('today') when isSameDay(messageDate, today)
but there is no "today" key in the i18n files, so add a "today" translation
entry to the English locale used by the app (e.g., in
packages/i18n/src/locales/en.i18n.json or the livechat package i18n file) with
the appropriate string (and mirror it in other locale files as needed), or
update MessageSeparator to use an existing translation key instead of
t('today'); ensure the change targets the MessageSeparator component where
t('today') is invoked so the label localizes correctly.

---

Nitpick comments:
In `@packages/livechat/src/components/Messages/MessageSeparator/index.tsx`:
- Around line 63-64: The current inline expression in MessageSeparator ((!!date
&& getDateLabel(date, t)) || (unread && t('unread_messages'))) can silently
treat an empty string from getDateLabel as falsy; change to an explicit check:
compute a dateLabel by calling getDateLabel only when date is present (e.g.,
const dateLabel = date ? getDateLabel(date, t) : ''), then render dateLabel if
it is non-empty else render unread ? t('unread_messages') : null so that empty
string from getDateLabel is handled explicitly; update the JSX in the
MessageSeparator component to use these variables (dateLabel, unread, t).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3ddcede5-84bf-4d35-9354-989941436cb0

📥 Commits

Reviewing files that changed from the base of the PR and between 39a341e and 7a37084.

📒 Files selected for processing (1)
  • packages/livechat/src/components/Messages/MessageSeparator/index.tsx
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/livechat/src/components/Messages/MessageSeparator/index.tsx
🧠 Learnings (2)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • packages/livechat/src/components/Messages/MessageSeparator/index.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/livechat/src/components/Messages/MessageSeparator/index.tsx
🔇 Additional comments (1)
packages/livechat/src/components/Messages/MessageSeparator/index.tsx (1)

18-21: LGTM!

Comment thread packages/livechat/src/components/Messages/MessageSeparator/index.tsx Outdated
@Varun789-mx Varun789-mx force-pushed the fix/message-separator-today-label branch from 7a37084 to c45be93 Compare May 24, 2026 08:03
@Varun789-mx Varun789-mx force-pushed the fix/message-separator-today-label branch from 9895ac5 to f287989 Compare May 24, 2026 08:19
@Varun789-mx Varun789-mx requested a review from psshrijith May 24, 2026 08:20
@coderabbitai coderabbitai Bot removed the type: feature Pull requests that introduces new feature label May 24, 2026
@Varun789-mx Varun789-mx changed the title fix: show 'Today'/'Yesterday' labels in message separator instead of full date fix: show Today/Yesterday labels in Livechat message separator May 24, 2026
@Varun789-mx

Copy link
Copy Markdown
Author

this still required QA ASSURED and milestone for this pr @psshrijith can you please add it so that it can be merged

@psshrijith

Copy link
Copy Markdown

let me check @Varun789-mx , i am not sure about this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Message separator currently displays date instead of “Today” for current day messages

2 participants