Skip to content

feat: real-time thread synchronization and event listeners (#1350) - #1407

Open
Diwaspant132 wants to merge 1 commit into
RocketChat:developfrom
Diwaspant132:feat/realtime-thread-sync-and-listeners
Open

Diwaspant132 wants to merge 1 commit into
RocketChat:developfrom
Diwaspant132:feat/realtime-thread-sync-and-listeners

Conversation

@Diwaspant132

Copy link
Copy Markdown

Description

Addresses #1350 and resolves the longstanding TODO at line 239 in EmbeddedChatApi.ts.

Previously, thread metrics (tcount, tlm, and replies) were not synchronized to parent messages in state.messages in real time. When another user replied to a thread, the thread reply counter and metrics button (BubbleThreadBtn / MessageMetrics) on the parent message in the main channel would not appear or update without a full browser reload. Additionally, deleting thread messages failed to decrement parent counters, deleting parent messages left orphaned thread panes on screen, and thread replies falsely triggered the main channel unread message indicator.

This PR introduces real-time thread event listeners in @embeddedchat/api and unifies thread state synchronization across @embeddedchat/react.


Key Changes

  1. @embeddedchat/api (EmbeddedChatApi.ts):

    • Added onThreadMessageCallbacks and onThreadMessageDeleteCallbacks arrays.
    • Added public listener methods: addThreadMessageListener, removeThreadMessageListener, addThreadMessageDeleteListener, and removeThreadMessageDeleteListener.
    • Subscribed to stream-room-messages with tmid filtering and notify-room deleteMessage with thread dispatching.
    • Fixed TypeScript error catch (error: any) at line 195.
  2. @embeddedchat/react (messageStore.js):

    • upsertMessage: Synchronizes parent tcount, tlm, and replies in state.messages in real time; keeps threadMainMessage synced when open.
    • removeMessage: Decrements parent tcount when a thread message is removed; closes active thread modal (isThreadOpen: false, threadMainMessage: null, threadMessages: []) when parent is deleted.
    • replaceMessage: Concurrently synchronizes edits across messages, threadMessages, and threadMainMessage.
  3. ChatBody.js:

    • Added !message.tmid check to avoid thread replies falsely triggering the main scroll-down unread banner.
  4. Unit Tests (packages/react/src/store/messageStore.test.mjs):

    • Added 6 unit tests verifying all thread state transitions with 100% pass rate.

Verification

  • yarn --cwd packages/react test: 6/6 tests passing (230ms).
  • yarn --cwd packages/api build: Rollup & TypeScript declarations (dist/index.d.ts) compile cleanly with 0 errors.
  • yarn format:check: 100% Prettier compliant.
  • yarn --cwd packages/react lint: 0 errors.

Fixes #1350

…t#1350)

- Add real-time thread message and thread delete event listeners to EmbeddedChatApi (resolves line 239 TODO)
- Dispatch incoming thread replies (tmid) to onThreadMessageCallbacks and thread deletes to onThreadMessageDeleteCallbacks
- Synchronize thread reply counts (tcount), last reply timestamps (tlm), and participant arrays (replies) in messageStore in real time
- Handle thread message deletion by decrementing parent tcount and active threadMainMessage tcount
- Automatically close active thread modal and reset threadMessages when parent message is deleted
- Synchronize message edits across messages, threadMessages, and threadMainMessage in replaceMessage
- Prevent thread replies from falsely triggering the main channel unread pill in ChatBody
- Add unit test suite with 100% pass rate validating real-time thread state transitions

Signed-off-by: Diwaspant132 <diwaspanta132@gmail.com>
@Diwaspant132

Copy link
Copy Markdown
Author

@Aryan-Verma-999 can u review this pr

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement thread message event listeners

1 participant