提交 beae4161 编写于 作者: DCloud_JSON's avatar DCloud_JSON

修复 当群公告被刷屏,导致后打开会话的用户看不到的问题

上级 f5fc925f
......@@ -53,7 +53,7 @@
<view v-if="call_list.length" class="showCallMe" @click="showCallMe">@回复我({{call_list.length}})</view>
<uni-popup @change="closeGroupNotification" ref="group-notification-popup" type="center" class="group-notification-popup">
<uni-popup @change="$event.show?'':closeGroupNotification()" ref="group-notification-popup" type="center" class="group-notification-popup">
<uni-im-group-notification ref="group-notification"></uni-im-group-notification>
</uni-popup>
......@@ -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)
......
......@@ -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
......
......@@ -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);
}
},
......
......@@ -86,6 +86,11 @@
"bsonType": "bool",
"description": "是否免打扰(右键设置会话消息免打扰)",
"defaultValue": false
},
"has_unread_group_notification":{
"bsonType": "bool",
"description": "是否有未读的群通知",
"defaultValue": false
}
}
}
\ No newline at end of file
......@@ -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}){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册