import * as React from 'react'; import { View } from 'react-native'; import { ContactModel, createForwardMessage, GroupModel, useChatContext, } from '../../chat'; import { useI18nContext } from '../../i18n'; import type { ChatMessage } from '../../rename.chat'; import { TabPage, TabPageHeader } from '../../ui/TabPage'; import { ContactList, ContactListProps } from '../ContactList'; import { GroupList, GroupListProps } from '../GroupList'; import { useMessageSnapshot } from '../hooks/useMessageSnapshot'; import { TopNavigationBar, TopNavigationBarLeft } from '../TopNavigationBar'; import type { PropsWithBack, PropsWithNavigationBar, PropsWithRef, } from '../types'; export type SelectContactListProps = Pick< ContactListProps, 'containerStyle' | 'onClickedSearch' | 'selectedData' > & { index: number; currentIndex: number; selectedMsgs?: ChatMessage[]; }; export function SelectContactList(props: SelectContactListProps) { return ( ); } export type SelectGroupListProps = Pick & { index: number; currentIndex: number; selectedMsgs?: ChatMessage[]; }; export function SelectGroupList(props: SelectGroupListProps) { return ( ); } export type MessageForwardSelectorRef = { forwardMessage: (data: ContactModel | GroupModel) => void; }; export type MessageForwardSelectorProps = PropsWithNavigationBar & PropsWithBack & PropsWithRef & { onClickedSearch?: (data?: any) => void; selectedData?: ContactModel[]; selectedMsgs?: ChatMessage[]; propsRef?: React.MutableRefObject; }; export function MessageForwardSelector(props: MessageForwardSelectorProps) { const { propsRef, navigationBarVisible, customNavigationBar, onBack, onClickedSearch, selectedData, selectedMsgs, } = props; const { tr } = useI18nContext(); const [height, setHeight] = React.useState(undefined); const im = useChatContext(); const { getMessageSnapshot } = useMessageSnapshot(); const onForwardMessage = React.useCallback( (data: ContactModel | GroupModel) => { let convId; let convType = 0; if ((data as any)?.userId) { convId = (data as ContactModel).userId; convType = 0; } else if ((data as any)?.groupId) { convId = (data as GroupModel).groupId; convType = 1; } if (convId) { if (selectedMsgs) { const newMsg = createForwardMessage({ msgs: selectedMsgs, targetId: convId, targetType: convType, getSummary: (msgs) => { const list = [] as string[]; for (const msg of msgs) { list.push(getMessageSnapshot(msg)); } return list.join('\n'); }, }); if (newMsg) { im.messageManager.sendMessage(newMsg); } } } }, [getMessageSnapshot, im.messageManager, selectedMsgs] ); if (propsRef?.current) { propsRef.current.forwardMessage = onForwardMessage; } return ( { setHeight(event.nativeEvent.layout.height); }} > {navigationBarVisible !== false ? ( customNavigationBar ? ( <>{customNavigationBar} ) : ( } Right={} /> ) ) : null} ); }