import * as React from 'react'; import { Dimensions, Platform, Pressable, View } from 'react-native'; import { useConfigContext } from '../../config'; import { useColors } from '../../hook'; import { useI18nContext } from '../../i18n'; import { usePaletteContext } from '../../theme'; import { Icon } from '../../ui/Image'; import { SingleLineText } from '../../ui/Text'; import { Avatar, GroupAvatar, StatusAvatar, useAvatarStatus } from '../Avatar'; import { BackButton } from '../Back'; import { TopNavigationBar, TopNavigationBarElementType, TopNavigationBarRightList, TopNavigationBarRightTextList, } from '../TopNavigationBar'; import { StatusType } from '../types'; import type { ConversationDetailModelType, ConversationSelectModeType, } from './types'; type _ConversationDetailNavigationBarProps = { convId: string; convType: number; convName?: string; convAvatar?: string; type: ConversationDetailModelType; selectMode?: ConversationSelectModeType; onBack?: (data?: any) => void; onClickedAvatar?: () => void; NavigationBar?: TopNavigationBarElementType; doNotDisturb?: boolean; newThreadName?: string; onClickedThread?: () => void; onClickedVoice?: () => void; onClickedVideo?: () => void; onClickedAV?: () => void; onClickedPinMessage?: () => void; onClickedThreadMore?: () => void; onCancelMultiSelected?: () => void; parentName?: string; messageTyping?: boolean; }; export const ConversationDetailNavigationBar = ( props: _ConversationDetailNavigationBarProps ): React.ReactElement => { const { onBack, onClickedAvatar, convAvatar, convName, convId, convType, NavigationBar, doNotDisturb, type: comType, newThreadName, onClickedVoice, onClickedThread, onClickedVideo, onClickedAV, onClickedThreadMore, onClickedPinMessage, selectMode = 'common', onCancelMultiSelected, parentName, messageTyping, } = props; const [status, setStatus] = React.useState(); const { enableThread, enableAVMeeting, enablePresence, enableMessagePin } = useConfigContext(); // const im = useChatContext(); const { addAvatarStatusListener, removeAvatarStatusListener } = useAvatarStatus(); const { tr } = useI18nContext(); const { colors } = usePaletteContext(); const { getColor } = useColors({ text_disable: { light: colors.neutral[7], dark: colors.neutral[3], }, text_enable: { light: colors.neutral[5], dark: colors.neutral[6], }, t3: { light: colors.neutral[7], dark: colors.neutral[5], }, }); const getData = React.useCallback(() => { const ret = { textList: [] as string[], iconNameList: [] as string[], onClickedList: [] as (() => void)[], render: null as any, }; do { if (comType === 'chat' || comType === 'search') { if (selectMode === 'common') { if (enableMessagePin && (convType === 1 || convType === 0)) { ret.iconNameList.push('pin_2'); ret.onClickedList.push(() => { onClickedPinMessage?.(); }); } if (enableThread && convType === 1) { ret.iconNameList.push('hashtag_in_bubble_fill'); ret.onClickedList.push(() => { onClickedThread?.(); }); ret.render = TopNavigationBarRightList; } if (enableAVMeeting) { if (convType === 0) { ret.iconNameList.push('phone_pick'); ret.iconNameList.push('video_camera'); ret.onClickedList.push(() => { onClickedVoice?.(); }); ret.onClickedList.push(() => { onClickedVideo?.(); }); } else { ret.iconNameList.push('phonen_camera'); ret.onClickedList.push(() => { onClickedAV?.(); }); } ret.render = TopNavigationBarRightList; } } else if (selectMode === 'multi') { ret.textList.push(tr('cancel')); ret.onClickedList.push(() => { onCancelMultiSelected?.(); }); ret.render = TopNavigationBarRightTextList; } } else if (comType === 'thread') { if (selectMode === 'common') { ret.iconNameList.push('ellipsis_vertical'); ret.onClickedList.push(() => { onClickedThreadMore?.(); }); ret.render = TopNavigationBarRightList; } else if (selectMode === 'multi') { } } } while (false); return ret; }, [ comType, convType, enableAVMeeting, enableMessagePin, enableThread, onCancelMultiSelected, onClickedAV, onClickedPinMessage, onClickedThread, onClickedThreadMore, onClickedVideo, onClickedVoice, selectMode, tr, ]); const rightProps = React.useMemo(() => { const ret = getData(); return { textList: ret.textList, iconNameList: ret.iconNameList, onClickedList: ret.onClickedList, render: ret.render, }; }, [getData]); React.useEffect(() => { const listener = (params: { status: StatusType }) => { setStatus(params.status); }; const sub = addAvatarStatusListener(listener); return () => { removeAvatarStatusListener(sub); }; }, [addAvatarStatusListener, removeAvatarStatusListener]); if (NavigationBar) { // return { NavigationBar }; return <>{NavigationBar}; } return ( {selectMode !== 'multi' ? : null} {comType === 'chat' || comType === 'search' ? ( {enablePresence === true && convType === 0 ? ( ) : convType === 0 ? ( ) : ( )} ) : null} {comType === 'chat' || comType === 'search' ? (convName ?? convId) : (newThreadName ?? convId)} {(comType === 'chat' || comType === 'search') && doNotDisturb === true ? ( ) : null} {convType === 0 ? ( messageTyping === true ? ( {tr('_uikit_message_typing')} ) : enablePresence === true && status && status?.length > 0 ? ( {tr(status ?? '')} ) : null ) : convType === 1 ? ( comType === 'thread' ? ( {`#${parentName}`} ) : null ) : null} } Right={rightProps.render} RightProps={rightProps} /> ); };