import React from 'react'
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'
import type { ConversationData } from '@xuqm/rn-sdk'
import { formatTime } from '../utils/format'
interface Props {
item: ConversationData & { targetName?: string; targetAvatar?: string }
onPress(): void
}
function Avatar({ name, uri }: { name: string; uri?: string }) {
const letter = (name || '?').charAt(0).toUpperCase()
return (
{letter}
)
}
function lastMsgPreview(item: ConversationData): string {
switch (item.lastMsgType) {
case 'IMAGE': return '[图片]'
case 'VIDEO': return '[视频]'
case 'AUDIO': return '[语音]'
case 'FILE': return '[文件]'
default: return item.lastMsgContent
}
}
export default function ConversationItem({ item, onPress }: Props) {
return (
{item.targetName ?? item.targetId}
{item.lastMsgTime ? formatTime(item.lastMsgTime) : ''}
{item.isMuted ? '[已静音] ' : ''}{lastMsgPreview(item)}
{item.unreadCount > 0 && (
{item.unreadCount > 99 ? '99+' : item.unreadCount}
)}
)
}
const styles = StyleSheet.create({
row: { flexDirection: 'row', padding: 12, alignItems: 'center', backgroundColor: '#fff' },
avatar: { width: 48, height: 48, borderRadius: 8, backgroundColor: '#07C160', alignItems: 'center', justifyContent: 'center', marginRight: 12 },
avatarText: { color: '#fff', fontSize: 20, fontWeight: '600' },
body: { flex: 1 },
topRow: { flexDirection: 'row', justifyContent: 'space-between', marginBottom: 4 },
name: { flex: 1, fontSize: 16, fontWeight: '500', color: '#111', marginRight: 8 },
time: { fontSize: 12, color: '#999' },
bottomRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' },
preview: { flex: 1, fontSize: 14, color: '#888', marginRight: 8 },
muted: { color: '#bbb' },
badge: { backgroundColor: '#ff3b30', borderRadius: 10, minWidth: 20, height: 20, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 4 },
badgeText: { color: '#fff', fontSize: 11, fontWeight: '700' },
})