fix(chat): 订单详情进群统一走 connectToGroupChat,groupId=订单号,修复历史消息与身份
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -155,29 +155,29 @@ class ConnectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 从会话列表查找真实群组ID
|
||||
let realGroupId = null;
|
||||
// 3. 从会话列表查找群组;找不到则用订单号作为 groupId(首聊场景)
|
||||
const orderIdStr = String(orderId);
|
||||
let realGroupId = orderIdStr;
|
||||
try {
|
||||
const result = await new Promise((resolve, reject) => {
|
||||
wx.goEasy.im.latestConversations({
|
||||
onSuccess: (res) => {
|
||||
const conversations = res.content?.conversations || [];
|
||||
const found = conversations.find(c => c.type === 'group' && c.data && c.data.orderId === orderId);
|
||||
resolve(found ? found.groupId : null);
|
||||
const found = conversations.find((c) => {
|
||||
if (c.type !== 'group') return false;
|
||||
if (c.groupId === orderIdStr) return true;
|
||||
const data = c.data || {};
|
||||
return String(data.orderId || '') === orderIdStr;
|
||||
});
|
||||
resolve(found ? found.groupId : orderIdStr);
|
||||
},
|
||||
onFailed: reject
|
||||
onFailed: reject,
|
||||
});
|
||||
});
|
||||
realGroupId = result;
|
||||
realGroupId = result || orderIdStr;
|
||||
} catch (err) {
|
||||
console.error('获取会话列表失败:', err);
|
||||
wx.showToast({ title: '获取群聊信息失败', icon: 'none' });
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (!realGroupId) {
|
||||
wx.showToast({ title: '暂未创建群聊', icon: 'none' });
|
||||
return;
|
||||
console.warn('获取会话列表失败,使用订单号作为群ID', err);
|
||||
realGroupId = orderIdStr;
|
||||
}
|
||||
|
||||
// 4. 🔥 关键:主动订阅群组并等待成功,确保发送消息时订阅已完成
|
||||
@@ -202,10 +202,13 @@ class ConnectionManager {
|
||||
// 5. 跳转群聊页(参数与消息列表完全一致)
|
||||
const param = {
|
||||
groupId: realGroupId,
|
||||
orderId: orderId,
|
||||
orderId: orderIdStr,
|
||||
groupName: groupName || '订单群聊',
|
||||
groupAvatar: groupAvatar || '',
|
||||
isCross: isCross || 0
|
||||
isCross: isCross || 0,
|
||||
currentUserId: userId,
|
||||
currentUserName: app.globalData.currentUser?.name || `用户${uid}`,
|
||||
currentUserAvatar: avatar,
|
||||
};
|
||||
const path = '/pages/group-chat/group-chat?data=' + encodeURIComponent(JSON.stringify(param));
|
||||
wx.navigateTo({ url: path });
|
||||
|
||||
Reference in New Issue
Block a user