diff --git a/sdk/init/msgEvent.js b/sdk/init/msgEvent.js index 84abdc57dcbbb8c3705cec99b79fa563a6fd9eeb..81e67b8c8111fca4f7010f8073d2603d551b5267 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 fd363b1245a796ce8846e247c56e7aca7e11fb89..222e80794167a78d9f1c6f1fa1833d26cb964827 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: {