import React from 'react';
import { User } from '@sendbird/chat';
import {
Avatar,
Box,
Icon,
PressBox,
Text,
createStyleSheet,
useUIKitTheme,
} from '@sendbird/uikit-react-native-foundation';
import { SendbirdFileMessage, SendbirdGroupChannel, SendbirdMessage, SendbirdUserMessage } from '@sendbird/uikit-utils';
import { useLocalization } from '../../hooks/useContext';
const AVATAR_LIMIT = 5;
type Props = {
channel: SendbirdGroupChannel;
message: SendbirdMessage;
onPress?: (message: SendbirdUserMessage | SendbirdFileMessage) => void;
};
const createRepliedUserAvatars = (mostRepliedUsers: User[]) => {
if (!mostRepliedUsers || mostRepliedUsers.length === 0) return null;
const { palette } = useUIKitTheme();
return mostRepliedUsers.slice(0, AVATAR_LIMIT).map((user, index) => {
if (index < AVATAR_LIMIT - 1) {
return (
);
} else {
return (
);
}
});
};
const GroupChannelMessageReplyInfo = ({ channel, message, onPress }: Props) => {
const { STRINGS } = useLocalization();
const { select, palette } = useUIKitTheme();
if (!channel || !message.threadInfo || !message.threadInfo.replyCount) return null;
const replyCountText = STRINGS.GROUP_CHANNEL_THREAD.REPLY_COUNT(message.threadInfo.replyCount || 0, 99);
const onPressReply = () => {
onPress?.(message as SendbirdUserMessage | SendbirdFileMessage);
};
return (
{createRepliedUserAvatars(message.threadInfo.mostRepliedUsers)}
{replyCountText}
);
};
const styles = createStyleSheet({
replyContainer: {
flexDirection: 'row',
alignItems: 'center',
},
avatarContainer: {
marginEnd: 4,
},
avatarOverlay: {
position: 'absolute',
top: 0,
start: 0,
end: 0,
bottom: 0,
borderRadius: 10,
},
plusIcon: {
position: 'absolute',
top: 3,
start: 3,
end: 0,
bottom: 0,
},
});
export default React.memo(GroupChannelMessageReplyInfo);