From 89f39862b2ffad8337a20f0627b70ab12e7012fa Mon Sep 17 00:00:00 2001 From: linju Date: Wed, 13 Nov 2024 16:59:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=A0=8F=E6=B6=88=E6=81=AF=E5=8C=BA=E5=88=86=E7=BE=A4=E8=81=8A?= =?UTF-8?q?=E5=92=8C=E7=A7=81=E8=81=8A=E4=BC=9A=E8=AF=9D=E5=B9=B6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=BE=A4=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk/init/msgEvent.js | 3 +- uniCloud/cloudfunctions/uni-im-co/msg.js | 40 ++++++++++++++++-------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/sdk/init/msgEvent.js b/sdk/init/msgEvent.js index 84abdc5..81e67b8 100644 --- a/sdk/init/msgEvent.js +++ b/sdk/init/msgEvent.js @@ -126,8 +126,9 @@ msgEvent.onMsg(async res=>{ if (canCreateNotification) { if (!$state.ext.appIsActive) { easyWebNotification.create({ - "title": payload.title + ":" + payload.content, + "title": payload.title, "option": { + "body": payload.content, conversation_id, "icon": payload.avatar_file ? payload.avatar_file.url : 'https://web-assets.dcloud.net.cn/unidoc/zh/uni.png' diff --git a/uniCloud/cloudfunctions/uni-im-co/msg.js b/uniCloud/cloudfunctions/uni-im-co/msg.js index fd363b1..222e807 100644 --- a/uniCloud/cloudfunctions/uni-im-co/msg.js +++ b/uniCloud/cloudfunctions/uni-im-co/msg.js @@ -187,7 +187,7 @@ async function sendMsg(params) { // 创建新会话或者更新已有会话。 // 拿到消息接收者的 isMute 状态(仅私聊有效) - let {isMute} = await _createOrUpdateConversation.call(this, conversation_id, msgData, params.chat_source) + let {isMute,groupInfo} = await _createOrUpdateConversation.call(this, conversation_id, msgData, params.chat_source) // console.log({ // ...msgData, // conversation_id @@ -244,7 +244,7 @@ async function sendMsg(params) { } // 处理产生的推送 - let res = await _processPush.call(this, {msgData,isMute,appId}) + let res = await _processPush.call(this, {msgData,isMute,appId,groupInfo}) if (!res.data) { res.data = {} @@ -415,6 +415,19 @@ function _getLastMsgNote({ async function _createOrUpdateConversation(conversation_id, msgData, chat_source) { // 设置会话 最后一条消息 的描述 let last_msg_note = _getLastMsgNote(msgData) + // 查询群信息 + let groupInfo; + if (msgData.group_id) { + const res = await db.collection('uni-im-group') + .doc(msgData.group_id) + .field({ + type: true, + name: true + }) + .get() + groupInfo = res.data[0] + } + // 查询当前用户的此会话 const { @@ -542,13 +555,6 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source if (msgData.group_id) { senderConversation.leave = false senderConversation.has_unread_group_notification = null - // 拿到group_type - let {data:[groupInfo]} = await db.collection('uni-im-group') - .doc(msgData.group_id) - .field({ - type: true - }) - .get() senderConversation.group_type = groupInfo?.type // 群聊只为当前用户创建会话 await dbUniImConversation.add(senderConversation) @@ -631,7 +637,8 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source // 返回消息接收者的isMute状态(仅私聊有效) return { - isMute + isMute, + groupInfo } } @@ -715,7 +722,7 @@ async function _checkForReplyMsg(msgData) { // console.log(987,aboutMsg,msgData.call_uid); } -async function _processPush({ msgData, isMute, appId }) { +async function _processPush({ msgData, isMute, appId,groupInfo }) { // 处理超长文本,push 发送不了的问题 _checkForLongMsg(msgData) @@ -723,8 +730,15 @@ async function _processPush({ msgData, isMute, appId }) { await _checkForReplyMsg(msgData) const { nickname, avatar_file } = msgData - const title = msgData.type == 'system'? '系统消息' : nickname.slice(0, 20) - const content = msgData.type == 'text'? msgData.body : '[多媒体]' + let title + let content + if(msgData.group_id){ + title = groupInfo.name + content = nickname.slice(0, 20) + ':' + (msgData.type == 'text'? msgData.body : '[多媒体]') + }else{ + title = msgData.type == 'system'? '系统消息' : nickname.slice(0, 20) + content = msgData.type == 'text'? msgData.body : '[多媒体]' + } // 定义推送参数 const pushParam = { payload: { -- GitLab