上传小程序修改合入
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { getCurrentUserId } from './auth'
|
||||
import { request } from './api'
|
||||
import { resolveActiveBinding } from './binding'
|
||||
import { getChild } from './child'
|
||||
import { loadCurrentChildBindingContext } from './binding'
|
||||
|
||||
export type ConversationSource = 'im' | 'ai'
|
||||
export type PeerKind = 'child' | 'parent' | 'ai'
|
||||
@@ -38,6 +37,11 @@ export interface ChatMessage {
|
||||
content: string
|
||||
time: string
|
||||
conversationId: number
|
||||
contentType?: number
|
||||
mediaUrl?: string | null
|
||||
mediaDurationMs?: number | null
|
||||
mediaMimeType?: string | null
|
||||
mediaTranscriptText?: string | null
|
||||
senderType?: string
|
||||
senderId?: string
|
||||
receiverType?: string
|
||||
@@ -240,21 +244,12 @@ function getConversationRank(conversation: ChatConversation): number {
|
||||
}
|
||||
|
||||
async function getBindingContext(): Promise<BindingContext> {
|
||||
const binding = await resolveActiveBinding()
|
||||
let childName = String(binding?.child_name || '').trim()
|
||||
|
||||
if (!childName && binding?.child_id) {
|
||||
try {
|
||||
const child = await getChild(binding.child_id)
|
||||
childName = String(child?.child_name || '').trim()
|
||||
} catch (error) {
|
||||
console.error('[chat] load child name failed:', error)
|
||||
}
|
||||
}
|
||||
const context = await loadCurrentChildBindingContext()
|
||||
const childName = String(context.currentChild?.child_name || context.currentBinding?.child_name || '').trim()
|
||||
|
||||
return {
|
||||
deviceId: binding?.device_id || '',
|
||||
childId: binding?.child_id || null,
|
||||
deviceId: context.currentBinding?.device_id || '',
|
||||
childId: context.currentChild?.child_id || null,
|
||||
childName,
|
||||
currentUserId: getCurrentUserId(),
|
||||
}
|
||||
@@ -265,7 +260,7 @@ async function getDeviceMessages(context?: BindingContext): Promise<DeviceAiMess
|
||||
if (!deviceId) return []
|
||||
|
||||
try {
|
||||
const response = await request<DeviceAiMessageListResponse>(`/devices/${deviceId}/messages?limit=100`)
|
||||
const response = await request<DeviceAiMessageListResponse>(`/banban/devices/${deviceId}/messages?limit=100`)
|
||||
return response.items || []
|
||||
} catch (error: any) {
|
||||
if (error?.status === 404) return []
|
||||
@@ -278,7 +273,7 @@ async function getChildConversations(context?: BindingContext): Promise<ChildCon
|
||||
if (!childId) return []
|
||||
|
||||
try {
|
||||
const response = await request<ChildConversationListResponse>(`/children/${childId}/conversations?limit=100`)
|
||||
const response = await request<ChildConversationListResponse>(`/banban/children/${childId}/conversations?limit=100`)
|
||||
return response.items || []
|
||||
} catch (error: any) {
|
||||
if (error?.status === 404) return []
|
||||
@@ -294,7 +289,7 @@ async function getChildConversationMessages(
|
||||
if (!childId || conversationId <= 0) return []
|
||||
|
||||
const response = await request<ChildConversationMessageListResponse>(
|
||||
`/children/${childId}/conversations/${conversationId}/messages?limit=100`
|
||||
`/banban/children/${childId}/conversations/${conversationId}/messages?limit=100`
|
||||
)
|
||||
return response.items || []
|
||||
}
|
||||
@@ -437,6 +432,11 @@ export async function getMessages(
|
||||
content: item.content || '暂无内容',
|
||||
time: formatDetailTime(item.created_at),
|
||||
conversationId: item.conversation_id,
|
||||
contentType: 1,
|
||||
mediaUrl: null,
|
||||
mediaDurationMs: null,
|
||||
mediaMimeType: null,
|
||||
mediaTranscriptText: null,
|
||||
senderType: item.is_user ? 'device' : 'ai',
|
||||
senderId: item.is_user ? context.deviceId : item.role_key,
|
||||
receiverType: item.is_user ? 'ai' : 'device',
|
||||
@@ -462,6 +462,11 @@ export async function getMessages(
|
||||
content: formatImPreview(item),
|
||||
time: formatDetailTime(item.created_at),
|
||||
conversationId: item.conversation_id,
|
||||
contentType: item.content_type,
|
||||
mediaUrl: item.media_file_key || null,
|
||||
mediaDurationMs: item.media_duration_ms || null,
|
||||
mediaMimeType: item.media_mime_type || null,
|
||||
mediaTranscriptText: item.media_transcript_text || null,
|
||||
senderType: item.sender_type,
|
||||
senderId: item.sender_id,
|
||||
receiverType: item.receiver_type,
|
||||
@@ -580,7 +585,7 @@ export async function sendParentMessage(childId: number, content: string): Promi
|
||||
throw new Error('请输入消息内容')
|
||||
}
|
||||
|
||||
return request<ConversationMessageCreateResponse>(`/children/${childId}/messages`, {
|
||||
return request<ConversationMessageCreateResponse>(`/banban/children/${childId}/messages`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
content_type: 1,
|
||||
|
||||
Reference in New Issue
Block a user