From 3dba1e8f15265cea212227bcae56fcb39d5cc09a Mon Sep 17 00:00:00 2001 From: linju Date: Wed, 13 Nov 2024 17:55:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E9=93=BE=EF=BC=8C=E5=85=BC=E5=AE=B9=20Nodejs?= =?UTF-8?q?12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloudfunctions/uni-im-co/conversation.js | 4 ++-- uniCloud/cloudfunctions/uni-im-co/msg.js | 4 ++-- uniCloud/cloudfunctions/uni-im-co/push.js | 2 +- uniCloud/database/uni-id-users.schema.ext.js | 16 ++++++++-------- .../database/uni-im-group-member.schema.ext.js | 3 ++- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/uniCloud/cloudfunctions/uni-im-co/conversation.js b/uniCloud/cloudfunctions/uni-im-co/conversation.js index ff11cb5..6a9af90 100644 --- a/uniCloud/cloudfunctions/uni-im-co/conversation.js +++ b/uniCloud/cloudfunctions/uni-im-co/conversation.js @@ -59,10 +59,10 @@ async function getConversationList({ matchObj.group_type = type.group_type } }else{ - action[type]?.() + action[type] && action[type]() } - // console.error('action========',type,'group_type:'+matchObj?.group_type); + // console.error('action========',type,'group_type:'+matchObj.group_type); } // 如果指定了会话id,则只查询指定的会话 diff --git a/uniCloud/cloudfunctions/uni-im-co/msg.js b/uniCloud/cloudfunctions/uni-im-co/msg.js index 222e807..de9d75c 100644 --- a/uniCloud/cloudfunctions/uni-im-co/msg.js +++ b/uniCloud/cloudfunctions/uni-im-co/msg.js @@ -276,7 +276,7 @@ async function _beforeSendMsgActions(params) { // 如果是扩展的消息类型,由扩展模块执行前置操作 const { msgTypes } = require('uni-im-ext') let msgType = await msgTypes.get(params.type) - if (msgType?.beforeSendMsg) { + if (msgType && msgType.beforeSendMsg) { await msgType.beforeSendMsg(params, this.current_uid) console.error('############----->beforeSendMsg', params) return @@ -555,7 +555,7 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source if (msgData.group_id) { senderConversation.leave = false senderConversation.has_unread_group_notification = null - senderConversation.group_type = groupInfo?.type + senderConversation.group_type = groupInfo.type // 群聊只为当前用户创建会话 await dbUniImConversation.add(senderConversation) } else { diff --git a/uniCloud/cloudfunctions/uni-im-co/push.js b/uniCloud/cloudfunctions/uni-im-co/push.js index f29f11d..e562d6a 100644 --- a/uniCloud/cloudfunctions/uni-im-co/push.js +++ b/uniCloud/cloudfunctions/uni-im-co/push.js @@ -105,7 +105,7 @@ async function sendPushMsg(param, appId) { // console.log('pushParam.channel', pushParam.channel) // 解决没有购买个推vip套餐,设置推送策略为3无效的问题 - if (pushParam?.settings?.strategy === 3) { + if (pushParam.settings && pushParam.settings.strategy === 3) { delete pushParam.title delete pushParam.content } diff --git a/uniCloud/database/uni-id-users.schema.ext.js b/uniCloud/database/uni-id-users.schema.ext.js index 7a4cac7..b2e9238 100644 --- a/uniCloud/database/uni-id-users.schema.ext.js +++ b/uniCloud/database/uni-id-users.schema.ext.js @@ -14,16 +14,16 @@ module.exports = { } async function afterReadAction({ - field, + field = '', result, userInfo: currentUserInfo, primaryCollection } = {}, asSecondaryCollection = false) { - const { data } = result + const {data} = result if (!Array.isArray(data)) { data = [data] } - if(!data?.length) return + if(data.length === 0) return const isAdmin = currentUserInfo.role.includes('uni-im-admin') || currentUserInfo.role.includes('admin') || currentUserInfo.role.includes('staff') // 处理当前表被作为联查时的副表的情况 let userInfos = data @@ -60,16 +60,16 @@ async function afterReadAction({ } userInfos.forEach(item => { - const real_name = item?.realname_auth?.real_name + const real_name = item.realname_auth ? item.realname_auth.real_name : '' // 如果real_name以uni-im-encrypt:开头 - if (real_name?.startsWith('uni-im-encrypt:')) { + if (real_name.startsWith('uni-im-encrypt:')) { // console.error('解密real_name',real_name,item._id) item.realname_auth.real_name = decrypt(real_name) // console.error('解密后real_name',item.realname_auth.real_name) } }) - if (field?.includes("nickname")) { + if (field.includes("nickname")) { //uni-im 处理查询nickname,但值为空的情况 // 记录没有nickname的用户id const user_ids = userInfos.filter(item => !item.nickname).map(item => item._id) @@ -97,11 +97,11 @@ async function afterReadAction({ userInfos.forEach(item => { if (!item.nickname) { - const userInfo = usersInfo[item._id] + const userInfo = usersInfo[item._id] || {} // 管理员可以看到不打码的 if (isAdmin) { console.log('userInfo',userInfo,'item',item) - item.nickname = userInfo?.username || userInfo?.email || userInfo?.mobile + item.nickname = userInfo.username || userInfo.email || userInfo.mobile }else{ item.nickname = hideUsernameStr(userInfo.username) || hideEmailStr(userInfo.email) || hideMobileStr(userInfo.mobile) diff --git a/uniCloud/database/uni-im-group-member.schema.ext.js b/uniCloud/database/uni-im-group-member.schema.ext.js index 9420064..6498870 100644 --- a/uniCloud/database/uni-im-group-member.schema.ext.js +++ b/uniCloud/database/uni-im-group-member.schema.ext.js @@ -87,7 +87,8 @@ module.exports = { member_count:db.command.inc(1) }) await uniImCo.sendMsg(msgData,user_id) - if(triggerContext.groupInfo?.type === "dcloud-plugin"){ + const {type} = triggerContext.groupInfo || {} + if(type === "dcloud-plugin"){ // 刷新记录在im系统中的 插件订单信息 try{ console.error('加入了dcloud-plugin',triggerContext.groupInfo) -- GitLab