From f9e737c9d340fe73bcb7b48e4209392689c254b9 Mon Sep 17 00:00:00 2001 From: linju Date: Tue, 12 Nov 2024 14:47:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E5=BD=93conversation=5Fgr?= =?UTF-8?q?ade=E9=85=8D=E7=BD=AE=E7=9A=84=E5=80=BC=E4=B8=8D=E7=AC=A6?= =?UTF-8?q?=E5=90=88=E9=A2=84=E6=9C=9F=E5=88=99=E6=8A=9B=E5=87=BA=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uniCloud/cloudfunctions/uni-im-co/msg.js | 62 +++++++++++++----------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/uniCloud/cloudfunctions/uni-im-co/msg.js b/uniCloud/cloudfunctions/uni-im-co/msg.js index 9a461c2..fd363b1 100644 --- a/uniCloud/cloudfunctions/uni-im-co/msg.js +++ b/uniCloud/cloudfunctions/uni-im-co/msg.js @@ -288,8 +288,38 @@ async function _checkConversationGrade({ to_uid, group_id, }) { + if(!conversation_grade){ + return true + } + /** 读取配置的对话等级,校验是否有权发送消息 + * 0 - 任何人可以发起会话 + * 100 - 客服 or 好友或者群成员 + * 200 - 必须是好友或者群成员 + * 300 - 仅限:系统管理员参与的、群成员与群管理员,发起私聊 + **/ + switch (conversation_grade) { + case 100: + // 客服 or 好友或者群成员 + try { + await chatToCustomerService() + } catch (error) { + console.error(error) + await chatToFriendOrGroupMember() + } + break; + case 200: + // 必须是好友或者群成员 + await chatToFriendOrGroupMember() + break; + case 300: + // 放到创建会话时处理 + break; + default: + throw new Error('未知的对话等级,配置conversation_grade的值不正确') + break; + } // 客服模式下,如果配置的客服 id。则只能向客服发起会话 - let chatToCustomerService = async () => { + async function chatToCustomerService (){ const customer_service_uids = uniImConfig.config('customer_service_uids') || [] if (typeof customer_service_uids == 'string') { customer_service_uids = [customer_service_uids] @@ -301,9 +331,9 @@ async function _checkConversationGrade({ } return true } - + // 只能是好友关系,或者群成员才能发送 - let chatToFriendOrGroupMember = async () => { + async function chatToFriendOrGroupMember(){ if (group_id) { let { data: [has] @@ -332,32 +362,6 @@ async function _checkConversationGrade({ } return true } - - /** 读取配置的对话等级,校验是否有权发送消息 - * 0 - 任何人可以发起会话 - * 100 - 客服 or 好友或者群成员 - * 200 - 必须是好友或者群成员 - **/ - switch (conversation_grade) { - case 0: - // 任何人可以发起会话,不校验 - break; - case 100: - // 客服 or 好友或者群成员 - try { - await chatToCustomerService() - } catch (error) { - console.error(error) - await chatToFriendOrGroupMember() - } - break; - case 200: - // 必须是好友或者群成员 - await chatToFriendOrGroupMember() - break; - default: - break; - } } function _getLastMsgNote({ -- GitLab