-
Notifications
You must be signed in to change notification settings - Fork 340
Fix/embedded chat channelname not switching #1048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Fix/embedded chat channelname not switching #1048
Conversation
- Add channelName to roomId resolution using Rocket.Chat API - Implement resolvedRoomId state management to handle dynamic room resolution - Fix re-instantiation logic to properly clear messages when switching channels - Wait for authentication before resolving channelName to prevent 401 errors - Update ChatHeader and ChatInput to prioritize channelName prop for display Fixes: Channel switching now works correctly when only channelName is provided
|
|
||
| const EmbeddedChat = (props) => { | ||
| const [config, setConfig] = useState(() => props); | ||
| // Track if roomId was explicitly provided (not just the default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove all the comments
|
@Spiral-Memory I removed all the comments... |
|
@Spiral-Memory I fixed that yarn lint issue |
|
@Spiral-Memory fixed the EmbeddedChatApi.ts to pass format check |
| if (data?.success && data?.room?._id) { | ||
| setResolvedRoomId(data.room._id); | ||
| } else { | ||
| setResolvedRoomId('GENERAL'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to have this fallback ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set this If a user provides a channelName that doesn't exist or they lack access, falling back to 'GENERAL' hides the failure.
|
Hi @deepak0x
Rather than manually handling hasMounted, we could use a key-based approach. A custom hook, like useRoomId or something similar, could also be created. Please look into finding a more elegant and efficient solution. |
|
Sure @Spiral-Memory |
- Add getRoomIdByName method to EmbeddedChatApi for resolving channel names to room IDs - Create useRoomId custom hook to encapsulate room ID resolution logic - Refactor EmbeddedChat to use key-based approach instead of manual state tracking - Remove fallback to GENERAL when channel name resolution fails - Display clear error messages when channel not found or inaccessible - Show error UI and toast notifications for failed channel resolution - Maintain backward compatibility with explicit roomId prop
- Use temporary 'GENERAL' roomId when channelName is provided but user is not authenticated yet - Only show error UI when there's an actual error, not when waiting for auth - Fixes e2e tests that were failing due to component not rendering
|
Hey @Spiral-Memory |
- Use roomId prop as fallback when resolvedRoomId is not available - Ensure component renders when explicit roomId is provided in e2e tests - Fixes e2e test failures where component was not rendering
a95c222 to
aaf85c4
Compare
- Remove toast dispatch usage before ToastBarProvider is mounted - Prevent render crash that hid the embedded chat in e2e tests
- Add null check before creating RCInstance to prevent errors - Ensure component always renders when roomId is provided - Fixes e2e test failures where component was not visible
Enable Channel Switching by Channel Name
Closes #452
Overview
This PR adds the ability to switch channels using channel names instead of requiring room IDs. Previously, users had to find and provide the room ID to switch channels, which was difficult. Now, users can simply provide the channel name (e.g., "public", "embedded", "general") and the component will automatically resolve it to the correct room ID.
Problem
Before this change, the
EmbeddedChatcomponent only supported switching channels usingroomId. Channel IDs are not user-friendly and difficult to find, making it hard for developers to integrate the component with specific channels.Solution
The component now supports channel switching using the
channelNameprop. WhenchannelNameis provided:Changes
Core Functionality
resolvedRoomIdstate to manage dynamically resolved room IDsexplicitRoomIdstate to track when a room ID is explicitly provided/api/v1/rooms.info?roomName=...API endpointUI Updates
ChatHeaderto prioritizechannelNameprop for displayChatInputplaceholder to usechannelNamewhen availableAPI Changes
EmbeddedChatApi.channelInfo()to check for authentication before making API callsUsage
Using Channel Name (New)
Using Room ID (Still Supported)
How It Works
roomIdis explicitly provided, it is used directlychannelNameis provided:Before / After
Technical Details
Testing