Skip to content

Commit 6b6340a

Browse files
fix: correct UI for archived channels and display channel topic (#905)
* fix: correct UI for archived channels and display channel topic * add appropriate border color to archived box
1 parent 04acec7 commit 6b6340a

7 files changed

Lines changed: 151 additions & 37 deletions

File tree

packages/api/src/EmbeddedChatApi.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,41 @@ export default class EmbeddedChatApi {
485485
}
486486
}
487487

488+
async getRoomInfo() {
489+
try {
490+
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
491+
const response = await fetch(
492+
`${this.host}/api/v1/method.call/rooms%3Aget`,
493+
{
494+
body: JSON.stringify({
495+
message: JSON.stringify({
496+
msg: "method",
497+
id: null,
498+
method: "rooms/get",
499+
params: [],
500+
}),
501+
}),
502+
headers: {
503+
"Content-Type": "application/json",
504+
"X-Auth-Token": authToken,
505+
"X-User-Id": userId,
506+
},
507+
method: "POST",
508+
}
509+
);
510+
511+
const result = await response.json();
512+
513+
if (result.success && result.message) {
514+
const parsedMessage = JSON.parse(result.message);
515+
return parsedMessage;
516+
}
517+
return null;
518+
} catch (err) {
519+
console.error(err);
520+
}
521+
}
522+
488523
async permissionInfo() {
489524
try {
490525
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};

packages/react/src/store/channelStore.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ const useChannelStore = create((set) => ({
44
showChannelinfo: false,
55
isChannelPrivate: false,
66
isChannelReadOnly: false,
7+
isChannelArchived: false,
78
isRoomTeam: false,
89
setShowChannelinfo: (showChannelinfo) => set(() => ({ showChannelinfo })),
910
channelInfo: {},
1011
setChannelInfo: (channelInfo) => set(() => ({ channelInfo })),
1112
setIsChannelPrivate: (isChannelPrivate) => set(() => ({ isChannelPrivate })),
13+
setIsChannelArchived: (isChannelArchived) =>
14+
set(() => ({ isChannelArchived })),
1215
setIsRoomTeam: (isRoomTeam) => set(() => ({ isRoomTeam })),
1316
setIsChannelReadOnly: (isChannelReadOnly) =>
1417
set(() => ({ isChannelReadOnly })),

packages/react/src/views/ChatHeader/ChatHeader.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ const ChatHeader = ({
7373
const setIsChannelPrivate = useChannelStore(
7474
(state) => state.setIsChannelPrivate
7575
);
76+
const setIsChannelArchived = useChannelStore(
77+
(state) => state.setIsChannelArchived
78+
);
7679
const isRoomTeam = useChannelStore((state) => state.isRoomTeam);
7780
const setIsRoomTeam = useChannelStore((state) => state.setIsRoomTeam);
7881
const setIsChannelReadOnly = useChannelStore(
@@ -130,7 +133,6 @@ const ChatHeader = ({
130133
};
131134
const setCanSendMsg = useUserStore((state) => state.setCanSendMsg);
132135
const authenticatedUserId = useUserStore((state) => state.userId);
133-
134136
const handleLogout = useCallback(async () => {
135137
try {
136138
await RCInstance.logout();
@@ -190,6 +192,14 @@ const ChatHeader = ({
190192
message: "Channel doesn't exist. Logging out.",
191193
});
192194
await RCInstance.logout();
195+
} else if (
196+
'errorType' in res &&
197+
res.errorType === 'error-room-archived'
198+
) {
199+
setIsChannelArchived(true);
200+
const roomInfo = await RCInstance.getRoomInfo();
201+
const roomData = roomInfo.result[roomInfo.result.length - 1];
202+
setChannelInfo(roomData);
193203
} else if ('errorType' in res && res.errorType === 'Not Allowed') {
194204
dispatchToastMessage({
195205
type: 'error',
@@ -369,9 +379,9 @@ const ChatHeader = ({
369379
<Avatar
370380
size="36px"
371381
style={{ marginRight: '6px' }}
372-
url={getChannelAvatarURL(channelInfo.name)}
382+
url={getChannelAvatarURL(channelInfo.name || channelName)}
373383
/>
374-
<Box>
384+
<Box css={styles.channelInfoContainer}>
375385
<Box
376386
css={styles.channelName}
377387
onClick={() => setExclusiveState(setShowChannelinfo)}

packages/react/src/views/ChatHeader/ChatHeader.styles.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ const getChatHeaderStyles = ({ theme, mode }) => {
3232
box-shadow: ${theme.shadows[1]};
3333
`,
3434

35+
channelInfoContainer: css`
36+
display: flex;
37+
flex-direction: column;
38+
min-width: 0;
39+
flex: 1;
40+
`,
41+
3542
channelDescription: css`
3643
${rowCentreAlign}
44+
flex: 1;
45+
min-width: 0;
3746
gap: 0.5rem;
3847
`,
3948

@@ -50,7 +59,13 @@ const getChatHeaderStyles = ({ theme, mode }) => {
5059
`,
5160
channelTopic: css`
5261
opacity: 0.8rem;
62+
display: -webkit-box;
63+
-webkit-line-clamp: 1;
64+
-webkit-box-orient: vertical;
65+
word-break: break-word;
66+
overflow: hidden;
5367
font-size: 1rem;
68+
text-overflow: ellipsis;
5469
`,
5570
};
5671
return styles;

packages/react/src/views/ChatInput/ChatInput.js

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ const ChatInput = ({ scrollToBottom }) => {
7474
name: state.name,
7575
}));
7676

77-
const { isChannelPrivate, isChannelReadOnly, channelInfo } = useChannelStore(
78-
(state) => ({
79-
isChannelPrivate: state.isChannelPrivate,
80-
isChannelReadOnly: state.isChannelReadOnly,
81-
channelInfo: state.channelInfo,
82-
})
83-
);
77+
const {
78+
isChannelPrivate,
79+
isChannelReadOnly,
80+
channelInfo,
81+
isChannelArchived,
82+
} = useChannelStore((state) => ({
83+
isChannelPrivate: state.isChannelPrivate,
84+
isChannelReadOnly: state.isChannelReadOnly,
85+
channelInfo: state.channelInfo,
86+
isChannelArchived: state.isChannelArchived,
87+
}));
8488

8589
const { members, setMembersHandler } = useMemberStore((state) => ({
8690
members: state.members,
@@ -540,15 +544,27 @@ const ChatInput = ({ scrollToBottom }) => {
540544
<Input
541545
textArea
542546
rows={1}
543-
disabled={!isUserAuthenticated || !canSendMsg || isRecordingMessage}
547+
disabled={
548+
!isUserAuthenticated ||
549+
!canSendMsg ||
550+
isRecordingMessage ||
551+
isChannelArchived
552+
}
544553
placeholder={
545-
isUserAuthenticated && canSendMsg
546-
? `Message ${channelInfo.name ? `#${channelInfo.name}` : ''}`
547-
: isUserAuthenticated
548-
? 'This room is read only'
554+
isUserAuthenticated
555+
? isChannelArchived
556+
? 'Room archived'
557+
: canSendMsg
558+
? `Message #${channelInfo.name}`
559+
: 'This room is read only'
549560
: 'Sign in to chat'
550561
}
551-
css={styles.textInput}
562+
css={css`
563+
${styles.textInput}
564+
${isChannelArchived &&
565+
isUserAuthenticated &&
566+
`text-align: center;`}
567+
`}
552568
onChange={onTextChange}
553569
onBlur={() => {
554570
sendTypingStop();
@@ -566,22 +582,24 @@ const ChatInput = ({ scrollToBottom }) => {
566582
`}
567583
>
568584
{isUserAuthenticated ? (
569-
<ActionButton
570-
ghost
571-
size="large"
572-
onClick={() => sendMessage()}
573-
type="primary"
574-
disabled={disableButton || isRecordingMessage}
575-
icon="send"
576-
/>
585+
!isChannelArchived ? (
586+
<ActionButton
587+
ghost
588+
size="large"
589+
onClick={() => sendMessage()}
590+
type="primary"
591+
disabled={disableButton || isRecordingMessage}
592+
icon="send"
593+
/>
594+
) : null
577595
) : (
578596
<Button onClick={onJoin} type="primary" disabled={isLoginIn}>
579597
{isLoginIn ? <Throbber /> : 'JOIN'}
580598
</Button>
581599
)}
582600
</Box>
583601
</Box>
584-
{isUserAuthenticated && (
602+
{isUserAuthenticated && !isChannelArchived && (
585603
<ChatInputFormattingToolbar
586604
messageRef={messageRef}
587605
inputRef={inputRef}

packages/react/src/views/RoomInformation/RoomInformation.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import {
77
Popup,
88
useComponentOverrides,
99
Icon,
10+
useTheme,
1011
} from '@embeddedchat/ui-elements';
1112
import RCContext from '../../context/RCInstance';
1213
import { useChannelStore } from '../../store';
1314
import getRoomInformationStyles from './RoomInformation.styles';
1415
import useSetExclusiveState from '../../hooks/useSetExclusiveState';
1516

1617
const Roominfo = () => {
17-
const { RCInstance } = useContext(RCContext);
18-
const styles = getRoomInformationStyles();
18+
const { RCInstance, ECOptions } = useContext(RCContext);
1919
const channelInfo = useChannelStore((state) => state.channelInfo);
2020
const isChannelPrivate = useChannelStore((state) => state.isChannelPrivate);
2121
const isRoomTeam = useChannelStore((state) => state.isRoomTeam);
@@ -26,8 +26,10 @@ const Roominfo = () => {
2626
const host = RCInstance.getHost();
2727
return `${host}/avatar/${channelname}`;
2828
};
29-
29+
const { channelName } = ECOptions ?? {};
3030
const ViewComponent = viewType === 'Popup' ? Popup : Sidebar;
31+
const { theme, mode } = useTheme();
32+
const styles = getRoomInformationStyles(theme, mode);
3133

3234
return (
3335
<ViewComponent
@@ -55,9 +57,24 @@ const Roominfo = () => {
5557
justify-content: center;
5658
`}
5759
>
58-
<Avatar size="100%" url={getChannelAvatarURL(channelInfo.name)} />
60+
<Avatar
61+
size="100%"
62+
url={getChannelAvatarURL(channelInfo.name || channelName)}
63+
/>
5964
</Box>
6065
<Box css={styles.infoContainer}>
66+
<Box css={styles.archivedRoomInfo}>
67+
<Icon
68+
name="report"
69+
size="1.25rem"
70+
fill={
71+
mode === 'light'
72+
? theme.colors.warning
73+
: theme.colors.warningForeground
74+
}
75+
/>
76+
<Box css={styles.archivedText}>Room Archived</Box>
77+
</Box>
6178
<Box css={styles.infoHeader}>
6279
<Icon
6380
name={
@@ -69,26 +86,26 @@ const Roominfo = () => {
6986
margin-right: 0.5rem;
7087
`}
7188
/>
72-
{channelInfo.name}
89+
{channelInfo.name || channelName}
7390
</Box>
7491
{channelInfo.description && (
7592
<>
7693
<Box css={styles.infoHeader}>Description</Box>
7794
<Box css={styles.info}>{channelInfo.description}</Box>
7895
</>
7996
)}
80-
{channelInfo.topic && (
81-
<>
82-
<Box css={styles.infoHeader}>Topic</Box>
83-
<Box css={styles.info}>{channelInfo.topic}</Box>
84-
</>
85-
)}
8697
{channelInfo.announcement && (
8798
<>
8899
<Box css={styles.infoHeader}>Announcement</Box>
89100
<Box css={styles.info}>{channelInfo.announcement}</Box>
90101
</>
91102
)}
103+
{channelInfo.topic && (
104+
<>
105+
<Box css={styles.infoHeader}>Topic</Box>
106+
<Box css={styles.info}>{channelInfo.topic}</Box>
107+
</>
108+
)}
92109
</Box>
93110
</Box>
94111
</ViewComponent>

packages/react/src/views/RoomInformation/RoomInformation.styles.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { css } from '@emotion/react';
22

3-
const getRoomInformationStyles = () => {
3+
const getRoomInformationStyles = (theme, mode) => {
44
const styles = {
55
infoContainer: css`
66
margin: 16px;
@@ -19,6 +19,22 @@ const getRoomInformationStyles = () => {
1919
opacity: 0.7;
2020
font-size: 0.9rem;
2121
`,
22+
23+
archivedRoomInfo: css`
24+
display: flex;
25+
border: 1px solid
26+
${mode === 'light'
27+
? theme.colors.warning
28+
: theme.colors.warningForeground};
29+
border-radius: ${theme.radius};
30+
padding: 0.75rem 1rem;
31+
width: 100%;
32+
gap: 0.75rem;
33+
margin-bottom: 1rem;
34+
`,
35+
archivedText: css`
36+
font-size: 1rem;
37+
`,
2238
};
2339

2440
return styles;

0 commit comments

Comments
 (0)