完善家长留言录音与会话展示

This commit is contained in:
stu2not
2026-05-28 18:15:10 +08:00
parent 38fef3d2af
commit b2f5631461
2 changed files with 150 additions and 23 deletions

View File

@@ -296,6 +296,17 @@ function getPeerDisplayName(peerKind: PeerKind, peerId?: string, peerName?: stri
return getParticipantDisplayName(peerKind, peerId, peerName)
}
function getParentConversationName(parentUserId: number | null, peerId: string, peerName: string | null | undefined, context: BindingContext): string {
if (parentUserId && parentUserId === context.currentUserId) return '家长沟通'
const displayName = getParticipantDisplayName('parent', peerId, peerName)
return `${displayName}的留言记录`
}
function canSendParentConversation(parentUserId: number | null, context: BindingContext): boolean {
return Boolean(parentUserId && parentUserId === context.currentUserId)
}
function getConversationRank(conversation: ChatConversation): number {
if (isParentChildConversation(conversation.conversationTypeName)) return 0
return 1
@@ -371,27 +382,34 @@ function toImConversation(item: ChildConversationItem, context: BindingContext):
const isParentConversation = isParentChildConversation(item.conversation_type_name)
const peerKind: PeerKind = item.peer_type === 'parent' ? 'parent' : 'child'
const meta = PEER_META[peerKind]
const parentUserId = isParentConversation ? parseNumericId(item.peer_id) : null
const canSend = isParentConversation ? canSendParentConversation(parentUserId, context) : false
const parentConversationName = getParentConversationName(parentUserId, item.peer_id, item.peer_name, context)
return {
id: item.conversation_id,
key: `im-${item.conversation_id}`,
source: 'im',
peerKind,
name: isParentConversation ? '家长沟通' : getPeerDisplayName(peerKind, item.peer_id, item.peer_name),
name: isParentConversation ? parentConversationName : getPeerDisplayName(peerKind, item.peer_id, item.peer_name),
avatar: meta.icon,
typeLabel: isParentConversation ? '家长沟通' : meta.label,
description: isParentConversation ? '家长通过微信小程序和孩子直接沟通' : meta.description,
lastMessage: item.last_message_preview || (isParentConversation ? '还没有消息,点进去发送第一条' : '暂无消息'),
typeLabel: isParentConversation ? (canSend ? '家长沟通' : '留言记录') : meta.label,
description: isParentConversation
? canSend
? '家长通过微信小程序和孩子直接沟通'
: '其他家长和孩子的留言记录'
: meta.description,
lastMessage: item.last_message_preview || (isParentConversation ? (canSend ? '还没有消息,点进去发送第一条' : '暂无留言记录') : '暂无消息'),
time: formatListTime(item.last_message_at),
sortAt: item.last_message_at || '',
conversationTypeName: item.conversation_type_name,
peerId: item.peer_id,
childId: context.childId,
childName: context.childName,
parentUserId: isParentConversation ? parseNumericId(item.peer_id) : null,
parentUserId,
deviceId: context.deviceId,
channelLabel: isParentConversation ? '微信小程序' : '设备端',
canSend: isParentConversation,
canSend,
}
}
@@ -596,6 +614,7 @@ export async function getCharacter(options: {
channelLabel,
canSend = false,
} = options
const context = await getBindingContext()
if (source === 'ai') {
const meta = getAiMeta(roleKey)
@@ -618,10 +637,14 @@ export async function getCharacter(options: {
}
if (isParentChildConversation(conversationTypeName)) {
const normalizedParentUserId = parentUserId || parseNumericId(peerId)
const canSendParentMessage = Boolean(canSend && normalizedParentUserId === context.currentUserId)
const normalizedName = name || getParentConversationName(normalizedParentUserId, peerId || '', null, context)
return {
id: conversationId,
name: '家长沟通',
description: '微信小程序 <-> 儿童设备',
name: normalizedName,
description: canSendParentMessage ? '微信小程序 <-> 儿童设备' : '其他家长和孩子的留言记录',
icon: PEER_META.parent.icon,
peerKind: 'parent',
source,
@@ -629,10 +652,10 @@ export async function getCharacter(options: {
childId,
childName,
peerId,
parentUserId: parentUserId || parseNumericId(peerId),
parentUserId: normalizedParentUserId,
deviceId,
channelLabel: channelLabel || '微信小程序',
canSend: canSend || true,
canSend: canSendParentMessage,
}
}