同步聊天修复到根目录pages/utils(与副本工程结构一致)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
const app = getApp();
|
||||
import { formatDate } from '../../static/lib/utils';
|
||||
const { jianquanxian } = require('../../utils/imAuth/jianquanxian');
|
||||
import { enrichGroupConversation, isOrderGroupConversation } from '../../utils/group-chat.js';
|
||||
import { enrichGroupConversation, isOrderGroupConversation, sortConversations, recordConversationOpen } from '../../utils/group-chat.js';
|
||||
import { loadGroupMetaCache } from '../../utils/im-user.js';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -24,10 +25,33 @@ Page({
|
||||
this.calculateScrollHeight();
|
||||
const muted = wx.getStorageSync('notificationMuted') || false;
|
||||
this.setData({ notificationMuted: muted });
|
||||
loadGroupMetaCache(app);
|
||||
this._onGlobalConvUpdated = (result) => {
|
||||
const content = result?.content || result;
|
||||
if (content && content.conversations) {
|
||||
this.renderConversations(content);
|
||||
}
|
||||
};
|
||||
app.on('conversationsUpdated', this._onGlobalConvUpdated);
|
||||
app.on('unreadCountChanged', this._onGlobalConvUpdated);
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
if (this._onGlobalConvUpdated) {
|
||||
app.off('conversationsUpdated', this._onGlobalConvUpdated);
|
||||
app.off('unreadCountChanged', this._onGlobalConvUpdated);
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!this.checkLoginStatus()) return;
|
||||
loadGroupMetaCache(app);
|
||||
if (app.globalData.messageManager?.unreadTotal != null) {
|
||||
app.emitEvent('tabBarBadgeChanged', {
|
||||
badgeText: app.globalData.messageManager.unreadTotal > 0
|
||||
? String(app.globalData.messageManager.unreadTotal) : ''
|
||||
});
|
||||
}
|
||||
this.checkPermissionAndAutoConnect();
|
||||
},
|
||||
|
||||
@@ -194,11 +218,14 @@ Page({
|
||||
const meta = groupMeta[item.groupId];
|
||||
if (meta) {
|
||||
if (!item.data) item.data = {};
|
||||
if (meta.name) item.data.name = meta.name;
|
||||
if (meta.avatar) item.data.avatar = meta.avatar;
|
||||
if (meta.orderDesc) item.data.orderDesc = meta.orderDesc;
|
||||
if (meta.orderId) item.data.orderId = meta.orderId;
|
||||
if (meta.orderZhuangtai != null) item.data.orderZhuangtai = meta.orderZhuangtai;
|
||||
Object.assign(item.data, meta);
|
||||
}
|
||||
if (item.data && item.data.dashouGoEasyId) {
|
||||
if (!app.globalData.groupInfoMap) app.globalData.groupInfoMap = {};
|
||||
app.globalData.groupInfoMap[item.groupId] = {
|
||||
...app.globalData.groupInfoMap[item.groupId],
|
||||
...item.data,
|
||||
};
|
||||
}
|
||||
enrichGroupConversation(item, myGoEasyId, defaultAvatar, ossBase);
|
||||
} else if (item.data && item.data.avatar) {
|
||||
@@ -213,24 +240,23 @@ Page({
|
||||
}
|
||||
});
|
||||
|
||||
list.sort((a, b) => {
|
||||
if (a.top && !b.top) return -1;
|
||||
if (!a.top && b.top) return 1;
|
||||
if (a.unread > 0 && b.unread <= 0) return -1;
|
||||
if (a.unread <= 0 && b.unread > 0) return 1;
|
||||
return (b.lastMessage.timestamp || 0) - (a.lastMessage.timestamp || 0);
|
||||
});
|
||||
const openTimes = wx.getStorageSync('conversationOpenTimes') || {};
|
||||
sortConversations(list, openTimes);
|
||||
|
||||
const unreadTotal = content.unreadTotal !== undefined ? content.unreadTotal : list.reduce((sum, c) => sum + (c.unread || 0), 0);
|
||||
if (app.globalData.messageManager) {
|
||||
app.globalData.messageManager.unreadTotal = unreadTotal;
|
||||
}
|
||||
if (app && app.emitEvent) {
|
||||
app.emitEvent('tabBarBadgeChanged', { badgeText: unreadTotal > 0 ? String(unreadTotal) : '' });
|
||||
app.emitEvent('unreadCountChanged', { unreadTotal });
|
||||
}
|
||||
|
||||
this.setData({ allConversations: list, displayCount: 4 }, () => {
|
||||
this.applyFilter();
|
||||
});
|
||||
|
||||
const unreadTotal = content.unreadTotal !== undefined ? content.unreadTotal : list.reduce((sum, c) => sum + (c.unread || 0), 0);
|
||||
if (app && app.emitEvent) {
|
||||
app.emitEvent('tabBarBadgeChanged', { badgeText: unreadTotal > 0 ? String(unreadTotal) : '' });
|
||||
}
|
||||
|
||||
// ✅ 每次渲染会话后,无条件重新订阅所有群组,确保订阅关系始终有效
|
||||
// 群组订阅(不重复断开连接)
|
||||
this.subscribeGroupsIfNeeded(list);
|
||||
},
|
||||
|
||||
@@ -316,6 +342,7 @@ Page({
|
||||
chat(e) {
|
||||
const conversation = e.currentTarget.dataset.conversation;
|
||||
if (!conversation) return;
|
||||
recordConversationOpen(conversation);
|
||||
|
||||
if (conversation.type === 'private') {
|
||||
const param = {
|
||||
|
||||
Reference in New Issue
Block a user