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 52a059aeaf83578e9db4b57e8a809d277e89d5eb..90a060da31220fed756a95db8d1d0e6fd901b22b 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 0b1cb4c1df940cd04224e6f72b2c4768ef85b204..6c0c1c50890a014cba2e113c12522523fea4de1e 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 022945f2b7fc7c202bea63471e12ace80cf65055..4ab1402d7487153251d3dbf47db443fbaa5be79b 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 c05541b8938266c7bf75b59ca1e7fa6abdbab1e2..e54953d0ab05d009c8d95006413c972ed9337c95 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 18ae3acf4c216e947ebef7db9505fbae9278f412..33ee9007443e7033dcfbc80e9607ddecaf5e294b 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}){