Skip to content

Commit

Permalink
[AC-2264] fix: handle channel not found error case (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 authored Jun 5, 2024
1 parent 489d4d3 commit 576298e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/uikit
21 changes: 16 additions & 5 deletions src/components/CustomChannelComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ReactDOM from 'react-dom';
import styled from 'styled-components';

import useSendbirdStateContext from '@uikit/hooks/useSendbirdStateContext';
import ChannelUI from '@uikit/modules/GroupChannel/components/GroupChannelUI';
import GroupChannelUI from '@uikit/modules/GroupChannel/components/GroupChannelUI';
import Message from '@uikit/modules/GroupChannel/components/Message';
import MessageInputWrapper from '@uikit/modules/GroupChannel/components/MessageInputWrapper';
import { useGroupChannelContext } from '@uikit/modules/GroupChannel/context/GroupChannelProvider';
Expand All @@ -19,8 +19,11 @@ import MessageDataContent from './MessageDataContent';
import WelcomeMessages from './messages/WelcomeMessages';
import StaticRepliesPanel from './StaticRepliesPanel';
import { useConstantState } from '../context/ConstantContext';
import { useWidgetSession } from '../context/WidgetSettingContext';
import useAutoDismissMobileKyeboardHandler from '../hooks/useAutoDismissMobileKyeboardHandler';
import {
useWidgetSession,
useWidgetSetting,
} from '../context/WidgetSettingContext';
import useAutoDismissMobileKeyboardHandler from '../hooks/useAutoDismissMobileKeyboardHandler';
import { useBlockWhileBotResponding } from '../hooks/useBlockWhileBotResponding';
import { useResetHistoryOnConnected } from '../hooks/useResetHistoryOnConnected';
import { useScrollOnStreaming } from '../hooks/useScrollOnStreaming';
Expand Down Expand Up @@ -137,6 +140,7 @@ export function CustomChannelComponent() {
scrollToBottom,
refresh,
} = useGroupChannelContext();
const { resetSession } = useWidgetSetting();
const { userId: currentUserId } = useWidgetSession();

// NOTE: Filter out messages that should not be displayed.
Expand Down Expand Up @@ -173,7 +177,7 @@ export function CustomChannelComponent() {
enableEmojiFeedback
);

useAutoDismissMobileKyeboardHandler();
useAutoDismissMobileKeyboardHandler();
useResetHistoryOnConnected();
useScrollOnStreaming({
isLastBotMessage,
Expand Down Expand Up @@ -238,9 +242,16 @@ export function CustomChannelComponent() {
const welcomeMessageTimeStamp =
lastWelcomeMessageCreatedAt ?? firstMessageCreatedAt;

const resetReqCounter = useRef(0);

return (
<Root height={'100%'} isStaticReplyVisible={isStaticReplyVisible}>
<ChannelUI
<GroupChannelUI
onChannelFetchFailed={() => {
if (resetReqCounter.current > 5) return;
resetReqCounter.current += 1;
resetSession();
}}
renderFileUploadIcon={() => <></>}
renderVoiceMessageIcon={() => <></>}
renderMessageInput={() => (
Expand Down
8 changes: 7 additions & 1 deletion src/context/WidgetSettingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Context = {
botStyle: BotStyle;
widgetSession: WidgetSession | null;
initManualSession: (sdk: SendbirdChatWith<[GroupChannelModule]>) => void;
resetSession: () => Promise<void>;
};

const WidgetSettingContext = createContext<Context | null>(null);
Expand Down Expand Up @@ -76,7 +77,10 @@ export const WidgetSettingProvider = ({
null
);

async function initSessionByStrategy(strategy: 'auto' | 'manual') {
async function initSessionByStrategy(
strategy: 'auto' | 'manual',
clearCache = false
) {
const cachedSession = getWidgetSessionCache({
appId,
botId,
Expand All @@ -85,6 +89,7 @@ export const WidgetSettingProvider = ({
const reuseCachedSession = ((
cache: typeof cachedSession
): cache is NonNullable<typeof cachedSession> => {
if (clearCache) return false;
if (!cache || cache.strategy !== strategy) return false;
if (cache.strategy === 'manual') {
// NOTE: There is no need to check the expiration of the session if it is managed manually.
Expand Down Expand Up @@ -195,6 +200,7 @@ export const WidgetSettingProvider = ({
},
widgetSession,
initManualSession,
resetSession: () => initSessionByStrategy(sessionStrategy, true),
}}
>
{widgetSession ? children : null}
Expand Down

0 comments on commit 576298e

Please sign in to comment.