fix: createMessage 补 userId 字段 + 使用 senderType/contentType
This commit is contained in:
@@ -694,6 +694,18 @@ const loadMessages = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getCurrentUserId = () => {
|
||||||
|
try {
|
||||||
|
const token = uni.getStorageSync('access_token')
|
||||||
|
if (!token) return ''
|
||||||
|
const payload = token.split('.')[1]
|
||||||
|
const decoded = JSON.parse(decodeURIComponent(Array.from(atob(payload), c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join('')))
|
||||||
|
return decoded.sub || ''
|
||||||
|
} catch (e) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 历史剧本兼容:基于 plotJson 初始化首条 AI 剧本消息
|
* 历史剧本兼容:基于 plotJson 初始化首条 AI 剧本消息
|
||||||
* 触发条件:loadMessages 返回空列表,且 currentResult.plotJson.fullContent 存在
|
* 触发条件:loadMessages 返回空列表,且 currentResult.plotJson.fullContent 存在
|
||||||
@@ -703,11 +715,13 @@ const initializeFirstAIMessage = async () => {
|
|||||||
if (!content) return
|
if (!content) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const userId = getCurrentUserId()
|
||||||
// 先保存用户心愿消息(theme)
|
// 先保存用户心愿消息(theme)
|
||||||
const theme = currentResult.value?.theme || currentResult.value?.title || ''
|
const theme = currentResult.value?.theme || currentResult.value?.title || ''
|
||||||
if (theme) {
|
if (theme) {
|
||||||
await createMessage({
|
await createMessage({
|
||||||
conversationId: conversationId.value,
|
conversationId: conversationId.value,
|
||||||
|
userId,
|
||||||
content: theme,
|
content: theme,
|
||||||
senderType: 'user',
|
senderType: 'user',
|
||||||
contentType: 'chat'
|
contentType: 'chat'
|
||||||
@@ -717,6 +731,7 @@ const initializeFirstAIMessage = async () => {
|
|||||||
// 再保存 AI 剧本消息
|
// 再保存 AI 剧本消息
|
||||||
await createMessage({
|
await createMessage({
|
||||||
conversationId: conversationId.value,
|
conversationId: conversationId.value,
|
||||||
|
userId,
|
||||||
content,
|
content,
|
||||||
senderType: 'assistant',
|
senderType: 'assistant',
|
||||||
contentType: 'script',
|
contentType: 'script',
|
||||||
@@ -796,6 +811,7 @@ const sendChat = async () => {
|
|||||||
|
|
||||||
const userMessageRes = await createMessage({
|
const userMessageRes = await createMessage({
|
||||||
conversationId: conversationId.value,
|
conversationId: conversationId.value,
|
||||||
|
userId: getCurrentUserId(),
|
||||||
content,
|
content,
|
||||||
senderType: 'user',
|
senderType: 'user',
|
||||||
contentType: 'chat'
|
contentType: 'chat'
|
||||||
@@ -847,6 +863,7 @@ const rewriteMessage = (msg) => {
|
|||||||
const sendRewrite = async (targetMessageId, content) => {
|
const sendRewrite = async (targetMessageId, content) => {
|
||||||
const userMessageRes = await createMessage({
|
const userMessageRes = await createMessage({
|
||||||
conversationId: conversationId.value,
|
conversationId: conversationId.value,
|
||||||
|
userId: getCurrentUserId(),
|
||||||
content,
|
content,
|
||||||
senderType: 'user',
|
senderType: 'user',
|
||||||
contentType: 'chat'
|
contentType: 'chat'
|
||||||
|
|||||||
Reference in New Issue
Block a user