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

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

上级 f5fc925f
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<view v-if="call_list.length" class="showCallMe" @click="showCallMe">@回复我({{call_list.length}})</view> <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-im-group-notification ref="group-notification"></uni-im-group-notification>
</uni-popup> </uni-popup>
...@@ -161,7 +161,12 @@ ...@@ -161,7 +161,12 @@
data() { data() {
return { return {
val: 0, val: 0,
conversation: {}, conversation: {
has_unread_group_notification: false,
group_info: {
notification: false
}
},
scrollIntoView: "", scrollIntoView: "",
scrollTop: 0, scrollTop: 0,
scrollTracker: new ScrollTracker(), scrollTracker: new ScrollTracker(),
...@@ -177,20 +182,23 @@ ...@@ -177,20 +182,23 @@
'conversation.call_list'(call_list) { 'conversation.call_list'(call_list) {
this.call_list = call_list this.call_list = call_list
}, },
'conversation.unreadGroupNotification': { 'conversation.has_unread_group_notification': {
handler(unreadGroupNotification) { 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 当前用户。否则弹框提示 // 判断列表中是否已经渲染了此群公告,是则 call 当前用户。否则弹框提示
let groupNotificationMsg = [...this.visibleMsgList].reverse().find(msg => msg.action === let groupNotificationMsg = [...this.visibleMsgList].reverse().find(msg => msg.action ===
'update-group-info-notification') 'update-group-info-notification')
console.log('groupNotificationMsg', groupNotificationMsg); // console.log('groupNotificationMsg', groupNotificationMsg,this.visibleMsgList);
if (groupNotificationMsg) { if (groupNotificationMsg) {
this.conversation.call_list.push(groupNotificationMsg._id) this.conversation.call_list.push(groupNotificationMsg._id)
this.closeGroupNotification()
} else { } else {
this.$refs["group-notification-popup"].open() this.$refs["group-notification-popup"].open()
this.$nextTick(() => { this.$nextTick(() => {
this.$refs["group-notification"].notification = unreadGroupNotification this.$refs["group-notification"].notification = group_notification
}) })
} }
} }
...@@ -562,14 +570,28 @@ ...@@ -562,14 +570,28 @@
// 如果是显示群公告,则设置未读的群公告内容为 false // 如果是显示群公告,则设置未读的群公告内容为 false
if (this.visibleMsgList[index].action === "update-group-info-notification") { if (this.visibleMsgList[index].action === "update-group-info-notification") {
this.conversation.unreadGroupNotification = false this.closeGroupNotification()
} }
}, },
closeGroupNotification(e) { closeGroupNotification() {
if (e.show === false) { // console.log('######关闭群公告',this.conversationId)
this.conversation.unreadGroupNotification = false
} 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) { isChecked(msg) {
return this.checkedMsgList.some(i => i._id === msg._id) return this.checkedMsgList.some(i => i._id === msg._id)
......
...@@ -360,7 +360,7 @@ export default class Message { ...@@ -360,7 +360,7 @@ export default class Message {
//重新拉取 群成员 //重新拉取 群成员
await uniIm.group.loadMember(_currentConversation.group_id) await uniIm.group.loadMember(_currentConversation.group_id)
// 获取群公告 // 获取群公告
_currentConversation.unreadGroupNotification = _currentConversation.group_info.notification _currentConversation.has_unread_group_notification = !!_currentConversation.group_info.notification
}else{ }else{
// 将新成员加入到群成员列表 // 将新成员加入到群成员列表
for (let i = 0; i < new_member_list.length; i++) { for (let i = 0; i < new_member_list.length; i++) {
...@@ -390,7 +390,7 @@ export default class Message { ...@@ -390,7 +390,7 @@ export default class Message {
const {notification} = data.body.updateData const {notification} = data.body.updateData
if(data.action === "update-group-info-notification"){ if(data.action === "update-group-info-notification"){
console.log('收到群公告'); console.log('收到群公告');
_currentConversation.unreadGroupNotification = notification _currentConversation.has_unread_group_notification = true
} }
}else if(data.action === "set-group-admin"){ }else if(data.action === "set-group-admin"){
const {user_id,addRole,delRole} = data.body const {user_id,addRole,delRole} = data.body
......
...@@ -57,7 +57,7 @@ module.exports = { ...@@ -57,7 +57,7 @@ module.exports = {
}, },
async beforeUpdate({where,updateData,userInfo}){ 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=>{ Object.keys(updateData).forEach(field=>{
if(!canUpdateField.includes(field)){ if(!canUpdateField.includes(field)){
throw new Error('uni-im-conversation.schema.ext.js beforeUpdate:限制只能更新的字段:'+canUpdateField.join('')) throw new Error('uni-im-conversation.schema.ext.js beforeUpdate:限制只能更新的字段:'+canUpdateField.join(''))
...@@ -76,7 +76,6 @@ module.exports = { ...@@ -76,7 +76,6 @@ module.exports = {
}).update({ }).update({
is_read:true is_read:true
}) })
// console.log('uni-im-conversation beforeUpdate res:',res); // console.log('uni-im-conversation beforeUpdate res:',res);
} }
}, },
......
...@@ -86,6 +86,11 @@ ...@@ -86,6 +86,11 @@
"bsonType": "bool", "bsonType": "bool",
"description": "是否免打扰(右键设置会话消息免打扰)", "description": "是否免打扰(右键设置会话消息免打扰)",
"defaultValue": false "defaultValue": false
},
"has_unread_group_notification":{
"bsonType": "bool",
"description": "是否有未读的群通知",
"defaultValue": false
} }
} }
} }
\ No newline at end of file
...@@ -26,6 +26,11 @@ module.exports = { ...@@ -26,6 +26,11 @@ module.exports = {
if(field == 'notification'){ if(field == 'notification'){
// 如果是群公告,增加一个公告的创建时间 // 如果是群公告,增加一个公告的创建时间
updateData[field].create_time = Date.now() 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}){ async afterUpdate({where,updateData,clientInfo,userInfo}){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册