-
Notifications
You must be signed in to change notification settings - Fork 354
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
Open
deepak0x
wants to merge
17
commits into
RocketChat:develop
Choose a base branch
from
deepak0x:fix/embedded-chat-channelname-not-switching
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+296
−37
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
41b242a
feat: enable channel switching by channel name
deepak0x 4612126
fix: resolve lint errors (prettier formatting and code style)
deepak0x 1cb376d
checking final Functionality
deepak0x b47d66c
refactor: remove comments added during channel name switching feature…
deepak0x 1cbe0af
refactor: remove comment from .gitignore
deepak0x f19ab01
fix: remove empty block statement to resolve lint error
deepak0x 903b7b5
fix: format EmbeddedChatApi.ts to pass format check
deepak0x d01c4f8
Merge branch 'develop' into fix/embedded-chat-channelname-not-switching
deepak0x b0067ee
Merge branch 'develop' into fix/embedded-chat-channelname-not-switching
deepak0x 2156d22
Merge branch 'develop' into fix/embedded-chat-channelname-not-switching
deepak0x 551819f
feat: implement channel switching by name with proper error handling
deepak0x c658f77
fix: allow component to render when waiting for authentication
deepak0x aaf85c4
fix: ensure RCInstance is always created when roomId is provided
deepak0x e7fc017
fix: avoid toast hook before provider in EmbeddedChat
deepak0x 3b2e2c0
fix: ensure RCInstance is always created with valid roomId
deepak0x ffca8a8
Merge branch 'develop' into fix/embedded-chat-channelname-not-switching
deepak0x 3065bf6
Merge branch 'develop' into fix/embedded-chat-channelname-not-switching
deepak0x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| node_modules | ||
| .parcel-cache | ||
|
|
||
| .env | ||
| .env.local | ||
| .env.*.local | ||
|
|
||
| # yarn | ||
| .pnp.* | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { useState, useEffect } from 'react'; | ||
| import { EmbeddedChatApi } from '@embeddedchat/api'; | ||
|
|
||
| /** | ||
| * Custom hook to resolve roomId from either explicit roomId or channelName. | ||
| * Returns an object with: | ||
| * - roomId: The resolved room ID, or null if resolution is pending/failed | ||
| * - error: Error message if resolution failed, or null if successful/pending | ||
| * | ||
| * @param {string|null|undefined} roomId - Explicit room ID | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the definitions |
||
| * @param {string|null|undefined} channelName - Channel name to resolve | ||
| * @param {string} host - Rocket.Chat host URL | ||
| * @param {Function} getToken - Token getter function | ||
| * @param {Function} deleteToken - Token deleter function | ||
| * @param {Function} saveToken - Token saver function | ||
| * @param {boolean} isUserAuthenticated - Whether user is authenticated | ||
| * @returns {{roomId: string|null, error: string|null}} - Resolved room ID and error state | ||
| */ | ||
| export const useRoomId = ( | ||
| roomId, | ||
| channelName, | ||
| host, | ||
| getToken, | ||
| deleteToken, | ||
| saveToken, | ||
| isUserAuthenticated | ||
| ) => { | ||
| const [resolvedRoomId, setResolvedRoomId] = useState(() => { | ||
| if (roomId) { | ||
| return { roomId, error: null }; | ||
| } | ||
| return channelName | ||
| ? { roomId: 'GENERAL', error: null } | ||
| : { roomId: 'GENERAL', error: null }; | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| const resolveRoomId = async () => { | ||
| if (roomId) { | ||
| setResolvedRoomId({ roomId, error: null }); | ||
| return; | ||
| } | ||
|
|
||
| if (channelName) { | ||
| if (!isUserAuthenticated) { | ||
| setResolvedRoomId({ roomId: 'GENERAL', error: null }); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const tempRCInstance = new EmbeddedChatApi(host, 'GENERAL', { | ||
| getToken, | ||
| deleteToken, | ||
| saveToken, | ||
| }); | ||
| const roomIdFromName = await tempRCInstance.getRoomIdByName( | ||
| channelName | ||
| ); | ||
| await tempRCInstance.close().catch(console.error); | ||
| if (roomIdFromName) { | ||
| setResolvedRoomId({ roomId: roomIdFromName, error: null }); | ||
| } else { | ||
| setResolvedRoomId({ | ||
| roomId: null, | ||
| error: `Channel "${channelName}" not found or you don't have access to it.`, | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| setResolvedRoomId({ | ||
| roomId: null, | ||
| error: `Failed to resolve channel "${channelName}": ${ | ||
| error.message || 'Unknown error' | ||
| }`, | ||
| }); | ||
| } | ||
| } else { | ||
| setResolvedRoomId({ roomId: 'GENERAL', error: null }); | ||
| } | ||
| }; | ||
|
|
||
| resolveRoomId(); | ||
| }, [ | ||
| roomId, | ||
| channelName, | ||
| host, | ||
| getToken, | ||
| deleteToken, | ||
| saveToken, | ||
| isUserAuthenticated, | ||
| ]); | ||
|
|
||
| return resolvedRoomId; | ||
| }; | ||
Oops, something went wrong.
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.
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 the comments