From beae4161ef74e82f73d6f8c8524114d3001c19b2 Mon Sep 17 00:00:00 2001 From: DCloud_JSON Date: Sat, 11 May 2024 15:39:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=BD=93=E7=BE=A4?= =?UTF-8?q?=E5=85=AC=E5=91=8A=E8=A2=AB=E5=88=B7=E5=B1=8F=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E5=90=8E=E6=89=93=E5=BC=80=E4=BC=9A=E8=AF=9D=E7=9A=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9C=8B=E4=B8=8D=E5=88=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-im-msg-list/uni-im-msg-list.vue | 46 ++++++++++++++----- sdk/ext/MsgManager.class.js | 4 +- .../uni-im-conversation.schema.ext.js | 3 +- .../database/uni-im-conversation.schema.json | 5 ++ uniCloud/database/uni-im-group.schema.ext.js | 5 ++ 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/components/uni-im-msg-list/uni-im-msg-list.vue b/components/uni-im-msg-list/uni-im-msg-list.vue index 52a059a..90a060d 100644 --- a/components/uni-im-msg-list/uni-im-msg-list.vue +++ b/components/uni-im-msg-list/uni-im-msg-list.vue @@ -53,7 +53,7 @@ @回复我({{call_list.length}}) - + @@ -161,7 +161,12 @@ data() { return { val: 0, - conversation: {}, + conversation: { + has_unread_group_notification: false, + group_info: { + notification: false + } + }, scrollIntoView: "", scrollTop: 0, scrollTracker: new ScrollTracker(), @@ -177,20 +182,23 @@ 'conversation.call_list'(call_list) { this.call_list = call_list }, - 'conversation.unreadGroupNotification': { - handler(unreadGroupNotification) { + 'conversation.has_unread_group_notification': { + async handler(hasUnreadGroupNotification) { + const group_notification = this.conversation?.group_info?.notification // 弹出群公告 - if (unreadGroupNotification && unreadGroupNotification.content) { + if (hasUnreadGroupNotification && group_notification && group_notification.content) { + await uniIm.utils.sleep(1000) // 判断列表中是否已经渲染了此群公告,是则 call 当前用户。否则弹框提示 let groupNotificationMsg = [...this.visibleMsgList].reverse().find(msg => msg.action === 'update-group-info-notification') - console.log('groupNotificationMsg', groupNotificationMsg); + // console.log('groupNotificationMsg', groupNotificationMsg,this.visibleMsgList); if (groupNotificationMsg) { this.conversation.call_list.push(groupNotificationMsg._id) + this.closeGroupNotification() } else { this.$refs["group-notification-popup"].open() this.$nextTick(() => { - this.$refs["group-notification"].notification = unreadGroupNotification + this.$refs["group-notification"].notification = group_notification }) } } @@ -562,14 +570,28 @@ // 如果是显示群公告,则设置未读的群公告内容为 false if (this.visibleMsgList[index].action === "update-group-info-notification") { - this.conversation.unreadGroupNotification = false + this.closeGroupNotification() } }, - closeGroupNotification(e) { - if (e.show === false) { - this.conversation.unreadGroupNotification = false - } + closeGroupNotification() { + // console.log('######关闭群公告',this.conversationId) + + const db = uniCloud.database(); + + db.collection('uni-im-conversation') + .where({ + id:this.conversationId, + user_id: uniCloud.getCurrentUserInfo().uid + }) + .update({ + has_unread_group_notification: false + }).then(res => { + this.conversation.has_unread_group_notification = false + // console.log('关闭群公告成功', res) + }).catch(err => { + console.error('关闭群公告失败', err) + }) }, isChecked(msg) { return this.checkedMsgList.some(i => i._id === msg._id) diff --git a/sdk/ext/MsgManager.class.js b/sdk/ext/MsgManager.class.js index 0b1cb4c..6c0c1c5 100644 --- a/sdk/ext/MsgManager.class.js +++ b/sdk/ext/MsgManager.class.js @@ -360,7 +360,7 @@ export default class Message { //重新拉取 群成员 await uniIm.group.loadMember(_currentConversation.group_id) // 获取群公告 - _currentConversation.unreadGroupNotification = _currentConversation.group_info.notification + _currentConversation.has_unread_group_notification = !!_currentConversation.group_info.notification }else{ // 将新成员加入到群成员列表 for (let i = 0; i < new_member_list.length; i++) { @@ -390,7 +390,7 @@ export default class Message { const {notification} = data.body.updateData if(data.action === "update-group-info-notification"){ console.log('收到群公告'); - _currentConversation.unreadGroupNotification = notification + _currentConversation.has_unread_group_notification = true } }else if(data.action === "set-group-admin"){ const {user_id,addRole,delRole} = data.body diff --git a/uniCloud/database/uni-im-conversation.schema.ext.js b/uniCloud/database/uni-im-conversation.schema.ext.js index 022945f..4ab1402 100644 --- a/uniCloud/database/uni-im-conversation.schema.ext.js +++ b/uniCloud/database/uni-im-conversation.schema.ext.js @@ -57,7 +57,7 @@ module.exports = { }, async beforeUpdate({where,updateData,userInfo}){ //只开放部分字段 - let canUpdateField = ["unread_count","pinned","hidden","mute"] + let canUpdateField = ["unread_count","pinned","hidden","mute","has_unread_group_notification"] Object.keys(updateData).forEach(field=>{ if(!canUpdateField.includes(field)){ throw new Error('uni-im-conversation.schema.ext.js beforeUpdate:限制只能更新的字段:'+canUpdateField.join(',')) @@ -76,7 +76,6 @@ module.exports = { }).update({ is_read:true }) - // console.log('uni-im-conversation beforeUpdate res:',res); } }, diff --git a/uniCloud/database/uni-im-conversation.schema.json b/uniCloud/database/uni-im-conversation.schema.json index c05541b..e54953d 100644 --- a/uniCloud/database/uni-im-conversation.schema.json +++ b/uniCloud/database/uni-im-conversation.schema.json @@ -86,6 +86,11 @@ "bsonType": "bool", "description": "是否免打扰(右键设置会话消息免打扰)", "defaultValue": false + }, + "has_unread_group_notification":{ + "bsonType": "bool", + "description": "是否有未读的群通知", + "defaultValue": false } } } \ No newline at end of file diff --git a/uniCloud/database/uni-im-group.schema.ext.js b/uniCloud/database/uni-im-group.schema.ext.js index 18ae3ac..33ee900 100644 --- a/uniCloud/database/uni-im-group.schema.ext.js +++ b/uniCloud/database/uni-im-group.schema.ext.js @@ -26,6 +26,11 @@ module.exports = { if(field == 'notification'){ // 如果是群公告,增加一个公告的创建时间 updateData[field].create_time = Date.now() + await db.collection('uni-im-conversation').where({ + group_id, + }).update({ + has_unread_group_notification: true + }) } }, async afterUpdate({where,updateData,clientInfo,userInfo}){ -- GitLab