From d8d0ca800742e5500fef11365edff3df9dfeac95 Mon Sep 17 00:00:00 2001 From: Anirban Singha Date: Wed, 15 Jan 2025 17:11:02 +0530 Subject: [PATCH] fix: correct UI for archived channels and display channel topic --- packages/api/src/EmbeddedChatApi.ts | 35 +++++++++++ packages/react/src/store/channelStore.js | 3 + .../react/src/views/ChatHeader/ChatHeader.js | 16 ++++- .../src/views/ChatHeader/ChatHeader.styles.js | 15 +++++ .../react/src/views/ChatInput/ChatInput.js | 62 ++++++++++++------- .../views/RoomInformation/RoomInformation.js | 31 ++++++---- .../RoomInformation/RoomInformation.styles.js | 15 ++++- 7 files changed, 140 insertions(+), 37 deletions(-) diff --git a/packages/api/src/EmbeddedChatApi.ts b/packages/api/src/EmbeddedChatApi.ts index 3a1c3b5f9..89dcf7b00 100644 --- a/packages/api/src/EmbeddedChatApi.ts +++ b/packages/api/src/EmbeddedChatApi.ts @@ -485,6 +485,41 @@ export default class EmbeddedChatApi { } } + async getRoomInfo() { + try { + const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; + const response = await fetch( + `${this.host}/api/v1/method.call/rooms%3Aget`, + { + body: JSON.stringify({ + message: JSON.stringify({ + msg: "method", + id: null, + method: "rooms/get", + params: [], + }), + }), + headers: { + "Content-Type": "application/json", + "X-Auth-Token": authToken, + "X-User-Id": userId, + }, + method: "POST", + } + ); + + const result = await response.json(); + + if (result.success && result.message) { + const parsedMessage = JSON.parse(result.message); + return parsedMessage; + } + return null; + } catch (err) { + console.error(err); + } + } + async permissionInfo() { try { const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; diff --git a/packages/react/src/store/channelStore.js b/packages/react/src/store/channelStore.js index 2ba08bddb..23dd2d1db 100644 --- a/packages/react/src/store/channelStore.js +++ b/packages/react/src/store/channelStore.js @@ -4,10 +4,13 @@ const useChannelStore = create((set) => ({ showChannelinfo: false, isChannelPrivate: false, isChannelReadOnly: false, + isChannelArchived: false, setShowChannelinfo: (showChannelinfo) => set(() => ({ showChannelinfo })), channelInfo: {}, setChannelInfo: (channelInfo) => set(() => ({ channelInfo })), setIsChannelPrivate: (isChannelPrivate) => set(() => ({ isChannelPrivate })), + setIsChannelArchived: (isChannelArchived) => + set(() => ({ isChannelArchived })), setIsChannelReadOnly: (isChannelReadOnly) => set(() => ({ isChannelReadOnly })), })); diff --git a/packages/react/src/views/ChatHeader/ChatHeader.js b/packages/react/src/views/ChatHeader/ChatHeader.js index 5f2dbf43e..9cc13738d 100644 --- a/packages/react/src/views/ChatHeader/ChatHeader.js +++ b/packages/react/src/views/ChatHeader/ChatHeader.js @@ -73,6 +73,9 @@ const ChatHeader = ({ const setIsChannelPrivate = useChannelStore( (state) => state.setIsChannelPrivate ); + const setIsChannelArchived = useChannelStore( + (state) => state.setIsChannelArchived + ); const setIsChannelReadOnly = useChannelStore( (state) => state.setIsChannelReadOnly ); @@ -131,7 +134,6 @@ const ChatHeader = ({ }; const setCanSendMsg = useUserStore((state) => state.setCanSendMsg); const authenticatedUserId = useUserStore((state) => state.userId); - const handleLogout = useCallback(async () => { try { await RCInstance.logout(); @@ -190,6 +192,14 @@ const ChatHeader = ({ message: "Channel doesn't exist. Logging out.", }); await RCInstance.logout(); + } else if ( + 'errorType' in res && + res.errorType === 'error-room-archived' + ) { + setIsChannelArchived(true); + const roomInfo = await RCInstance.getRoomInfo(); + const roomData = roomInfo.result[roomInfo.result.length - 1]; + setChannelInfo(roomData); } else if ('errorType' in res && res.errorType === 'Not Allowed') { dispatchToastMessage({ type: 'error', @@ -369,9 +379,9 @@ const ChatHeader = ({ - + setExclusiveState(setShowChannelinfo)} diff --git a/packages/react/src/views/ChatHeader/ChatHeader.styles.js b/packages/react/src/views/ChatHeader/ChatHeader.styles.js index 54770d8a5..46a9ecd32 100644 --- a/packages/react/src/views/ChatHeader/ChatHeader.styles.js +++ b/packages/react/src/views/ChatHeader/ChatHeader.styles.js @@ -32,8 +32,17 @@ const getChatHeaderStyles = ({ theme, mode }) => { box-shadow: ${theme.shadows[1]}; `, + channelInfoContainer: css` + display: flex; + flex-direction: column; + min-width: 0; + flex: 1; + `, + channelDescription: css` ${rowCentreAlign} + flex: 1; + min-width: 0; gap: 0.5rem; `, @@ -50,7 +59,13 @@ const getChatHeaderStyles = ({ theme, mode }) => { `, channelTopic: css` opacity: 0.8rem; + display: -webkit-box; + -webkit-line-clamp: 1; + -webkit-box-orient: vertical; + word-break: break-word; + overflow: hidden; font-size: 1rem; + text-overflow: ellipsis; `, }; return styles; diff --git a/packages/react/src/views/ChatInput/ChatInput.js b/packages/react/src/views/ChatInput/ChatInput.js index 33f40d7af..fca024584 100644 --- a/packages/react/src/views/ChatInput/ChatInput.js +++ b/packages/react/src/views/ChatInput/ChatInput.js @@ -74,13 +74,17 @@ const ChatInput = ({ scrollToBottom }) => { name: state.name, })); - const { isChannelPrivate, isChannelReadOnly, channelInfo } = useChannelStore( - (state) => ({ - isChannelPrivate: state.isChannelPrivate, - isChannelReadOnly: state.isChannelReadOnly, - channelInfo: state.channelInfo, - }) - ); + const { + isChannelPrivate, + isChannelReadOnly, + channelInfo, + isChannelArchived, + } = useChannelStore((state) => ({ + isChannelPrivate: state.isChannelPrivate, + isChannelReadOnly: state.isChannelReadOnly, + channelInfo: state.channelInfo, + isChannelArchived: state.isChannelArchived, + })); const { members, setMembersHandler } = useMemberStore((state) => ({ members: state.members, @@ -521,15 +525,27 @@ const ChatInput = ({ scrollToBottom }) => { { sendTypingStop(); @@ -547,14 +563,16 @@ const ChatInput = ({ scrollToBottom }) => { `} > {isUserAuthenticated ? ( - sendMessage()} - type="primary" - disabled={disableButton || isRecordingMessage} - icon="send" - /> + !isChannelArchived ? ( + sendMessage()} + type="primary" + disabled={disableButton || isRecordingMessage} + icon="send" + /> + ) : null ) : (