未读角标增加

This commit is contained in:
zhangzheng
2026-03-12 12:46:22 +08:00
parent cccd5f8cec
commit 873ce3d940
3 changed files with 29 additions and 7 deletions

View File

@@ -367,11 +367,12 @@ class CallStateManager {
};
// 初始化 RenderStreaming 实例后
this.renderstreaming.onMessage = (data) => {
console.log('收到聊天消息:', data);
console.log('收到聊天:', data);
if (data.type === 'chat-message') {
// 处理聊天消息
// 添加到消息列表并更新UI
store.addMessage(data.message);
// 处理聊天
// 添加到列表并更新UI
this.handleChatMessage(data.message);
} else if (data.type === 'on-message') {
}
@@ -447,7 +448,7 @@ class CallStateManager {
}
// 更新远端媒体状态 (由 WebSocket 消息触发)
// 更新远端媒体状态 (由 WebSocket 触发)
updateRemoteMedia(mediaState) {
this.state.session.remoteUser.mediaState = {
...this.state.session.remoteUser.mediaState,
@@ -456,13 +457,14 @@ class CallStateManager {
this.notify({ type: 'REMOTE_MEDIA_CHANGE', mediaState });
}
// 添加消息
// 添加
addMessage(message) {
this.state.messages.push(message);
// 如果侧边栏关闭且不是自己发的,增加未读
if (!this.state.isSidebarOpen && !message.isSelf) {
this.state.unreadCount++;
this.notify({ type: 'SIDEBAR_TOGGLE', unreadCount: this.state.unreadCount });
}
this.notify({ type: 'NEW_MESSAGE', message, unreadCount: this.state.unreadCount });
@@ -810,6 +812,18 @@ class CallStateManager {
}
}
// 处理接收到的聊天
handleChatMessage(data) {
console.log('处理聊天:', data);
store.addMessage(data);
const isImage = data.message && data.message.startsWith('data:image/');
const messageType = isImage ? 'file' : 'text';
// 显示通知
showNotification(`${senderName}: ${data.message.substring(0, 20)}${data.message.length > 20 ? '...' : ''}`);
}
// 发送媒体状态到服务器
emitMediaStateChange() {
const payload = {