import clsx from 'clsx' import {DisplayUser} from 'common/api/user-types' import {ChatMessage, PrivateChatMessage} from 'common/chat-message' import {compassUserId} from 'common/profiles/constants' import {first, last} from 'lodash' import {Dispatch, memo, SetStateAction, useRef, useState} from 'react' import {MessageActions} from 'web/components/chat/message-actions' import {MessageReactions} from 'web/components/chat/message-reactions' import {Col} from 'web/components/layout/col' import {Modal, MODAL_CLASS} from 'web/components/layout/modal' import {Row} from 'web/components/layout/row' import {MultipleOrSingleAvatars} from 'web/components/multiple-or-single-avatars' import {RelativeTimestamp} from 'web/components/relative-timestamp' import {Avatar} from 'web/components/widgets/avatar' import {Content} from 'web/components/widgets/editor' import {UserAvatarAndBadge} from 'web/components/widgets/user-link' export function ChatMessageItem(props: { chats: ChatMessage[] currentUser: DisplayUser | undefined | null otherUser?: DisplayUser | null onReplyClick?: (chat: ChatMessage) => void beforeSameUser: boolean firstOfUser: boolean hideAvatar: boolean onRequestEdit?: (chat: ChatMessage) => void setMessages?: Dispatch> }) { const { chats, onReplyClick, currentUser, otherUser, beforeSameUser, firstOfUser, hideAvatar, onRequestEdit, setMessages, } = props const chat = first(chats) const [emojiOpenForId, setEmojiOpenForId] = useState(null) const [emojiKey, setEmojiKey] = useState(0) const longPressTimerRef = useRef | null>(null) if (!chat) return null // console.log('chat', chat) const isMe = currentUser?.id === chat.userId const {username, avatarUrl, id} = !isMe && otherUser ? otherUser : isMe && currentUser ? currentUser : {username: '', avatarUrl: undefined, id: ''} const startLongPress = (messageId: number) => { if (longPressTimerRef.current) clearTimeout(longPressTimerRef.current) longPressTimerRef.current = setTimeout(() => { setEmojiOpenForId(messageId) setEmojiKey((k) => k + 1) }, 500) } const cancelLongPress = () => { if (longPressTimerRef.current) { clearTimeout(longPressTimerRef.current) longPressTimerRef.current = null } } return ( {!isMe && !hideAvatar && ( )} {chats.map((chat) => (
startLongPress(chat.id)} onMouseUp={cancelLongPress} onMouseLeave={cancelLongPress} onTouchStart={() => startLongPress(chat.id)} onTouchEnd={cancelLongPress} onTouchCancel={cancelLongPress} >
{/* Hidden host for emoji picker, opened via long-press */}
| undefined, }} className={clsx('ml-2', isMe ? 'justify-end' : 'justify-start')} setMessages={setMessages} />
{chat.visibility !== 'system_status' && ( {/*{!isMe &&*/} {/* */} {/* {name}*/} {/* */} {/*}*/} {onReplyClick && (
{/* onReplyClick?.(chat)}*/} {/*>*/} {/* */} {/**/} onRequestEdit?.(chat)} className="text-xs group-last:block" />
)}
)}
))}
) } export const SystemChatMessageItem = memo(function SystemChatMessageItem(props: { chats: ChatMessage[] otherUsers: DisplayUser[] | undefined }) { const {chats, otherUsers} = props const chat = last(chats) const [showUsers, setShowUsers] = useState(false) if (!chat) return null const totalUsers = otherUsers?.length || 1 const hideAvatar = (chat.visibility === 'system_status' && chat.userId === compassUserId && chats.length === 1) || totalUsers < 2 return ( {totalUsers > 1 ? ( {totalUsers} user{totalUsers > 1 ? 's' : ''} joined the chat! ) : ( <> {chat.visibility !== 'system_status' && (
)} )} {!hideAvatar && ( setShowUsers(true)} /> )} {showUsers && ( )}
) }) export const MultiUserModal = (props: { showUsers: boolean setShowUsers: (show: boolean) => void otherUsers: DisplayUser[] }) => { const {showUsers, setShowUsers, otherUsers} = props return ( {otherUsers?.map((user) => ( ))} ) } function MessageAvatar(props: { beforeSameUser: boolean userAvatarUrl?: string username?: string userId: string }) { const {beforeSameUser, userAvatarUrl, username} = props return ( ) }