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

修复 被解散/踢出群的群成员收不到相关事件通知的问题

上级 dd9e2966
...@@ -548,41 +548,22 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source ...@@ -548,41 +548,22 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source
delete updateObj.unread_count delete updateObj.unread_count
} }
// 如果消息是:群解散 的触发动作通知,则更新会话表的leave字段为true
if (msgData.action === "group-dissolved") {
updateObj.leave = true
}
// 所有接收者的会话表更新 // 所有接收者的会话表更新
let res = await dbUniImConversation let res = await dbUniImConversation
.where({ .where({
id: conversation_id, id: conversation_id,
user_id: dbCmd.neq(msgData.from_uid) user_id: dbCmd.neq(msgData.from_uid),
leave: dbCmd.neq(true)
}) })
.update(updateObj) .update(updateObj)
// console.log(res); // console.log(res);
// 特殊用户的会话表更新 // 更新发送者的会话( 发送者的消息未读数不需要 +1 )
delete updateObj.unread_count delete updateObj.unread_count
let updateUids = []
if (msgData.action === 'group-exit') {
// 主动退群:更新发送者的会话
delete updateObj.last_msg_note
updateObj.leave = true
updateUids.push(msgData.from_uid)
} else if (msgData.action === 'group-expel') {
// 踢出群:更新被踢者的会话
delete updateObj.last_msg_note
updateObj.leave = true
updateUids.push(...msgData.body.user_id_list)
} else {
// 其它情况:更新发送者的会话
updateUids.push(msgData.from_uid)
}
res = await dbUniImConversation res = await dbUniImConversation
.where({ .where({
id: conversation_id, id: conversation_id,
user_id: dbCmd.in(updateUids) user_id: msgData.from_uid
}) })
.update(updateObj) .update(updateObj)
// console.log(res); // console.log(res);
...@@ -847,7 +828,6 @@ async function sendMsgToGroup({ ...@@ -847,7 +828,6 @@ async function sendMsgToGroup({
user_id: dbCmd.neq(pushParam.payload.data.from_uid) user_id: dbCmd.neq(pushParam.payload.data.from_uid)
} }
if (before_id) { if (before_id) {
getMemberwhere._id = dbCmd.gt(before_id) getMemberwhere._id = dbCmd.gt(before_id)
} }
...@@ -892,13 +872,44 @@ async function sendMsgToGroup({ ...@@ -892,13 +872,44 @@ async function sendMsgToGroup({
return sum return sum
}, []) }, [])
console.log('查到需要接收消息的设备数:', push_clientids.length); console.log('查到需要接收消息的设备数:', push_clientids.length);
// 消息接收者用户id
const receiverUids = member.map(user => user.user_id)
const msgData = pushParam.payload.data
// console.error('###########msgData.action', msgData.action);
// 更新:退群、解散群、被踢出群 相关的用户会话
if(receiverUids.length && ["group-exit","group-expel","group-dissolved"].includes(msgData.action)){
const updateUids = []
if (msgData.action == 'group-exit') {
// 主动退群时,仅退群用户所在“消息推送批次”时更新会话即可
if(receiverUids.includes(msgData.from_uid)){
updateUids.push(msgData.from_uid)
}
} else {
// 群解散、被踢出群时,所有“本批次”的用户会话都需要更新(注:分批 解散/退出群 的设计模式)
updateUids.push(...receiverUids)
// 解散群时,在第一批次时,增加更新操作者(群主)的会话
if(!before_id && msgData.action == 'group-dissolved'){
updateUids.push(msgData.from_uid)
}
}
if(updateUids.length){
let res = await dbUniImConversation
.where({
id: msgData.conversation_id,
user_id: dbCmd.in(updateUids)
})
.update({"leave":true})
// console.error('###########更新退群或者被踢出群的用户会话', res);
}
}
// WS 推送:群聊消息推送给相关用户 // WS 推送:群聊消息推送给相关用户
let msgData = pushParam.payload.data
if (!mute && !_isMuteMsg(msgData) && (await _isReadableMsg(msgData))) { if (!mute && !_isMuteMsg(msgData) && (await _isReadableMsg(msgData))) {
const { invokeExts } = require('uni-im-ext') const { invokeExts } = require('uni-im-ext')
await invokeExts('push-msg-notify', { await invokeExts('push-msg-notify', {
to_uids: member.map(user => user.user_id), to_uids: receiverUids,
msg: { msg: {
type: 'incr-conversation', type: 'incr-conversation',
conversation_id: msgData.conversation_id, conversation_id: msgData.conversation_id,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册