提交 89f39862 编写于 作者: DCloud_JSON's avatar DCloud_JSON

更新 通知栏消息区分群聊和私聊会话并显示群名称

上级 657d7ffe
...@@ -126,8 +126,9 @@ msgEvent.onMsg(async res=>{ ...@@ -126,8 +126,9 @@ msgEvent.onMsg(async res=>{
if (canCreateNotification) { if (canCreateNotification) {
if (!$state.ext.appIsActive) { if (!$state.ext.appIsActive) {
easyWebNotification.create({ easyWebNotification.create({
"title": payload.title + "" + payload.content, "title": payload.title,
"option": { "option": {
"body": payload.content,
conversation_id, conversation_id,
"icon": payload.avatar_file ? payload.avatar_file.url : "icon": payload.avatar_file ? payload.avatar_file.url :
'https://web-assets.dcloud.net.cn/unidoc/zh/uni.png' 'https://web-assets.dcloud.net.cn/unidoc/zh/uni.png'
......
...@@ -187,7 +187,7 @@ async function sendMsg(params) { ...@@ -187,7 +187,7 @@ async function sendMsg(params) {
// 创建新会话或者更新已有会话。 // 创建新会话或者更新已有会话。
// 拿到消息接收者的 isMute 状态(仅私聊有效) // 拿到消息接收者的 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({ // console.log({
// ...msgData, // ...msgData,
// conversation_id // conversation_id
...@@ -244,7 +244,7 @@ async function sendMsg(params) { ...@@ -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) { if (!res.data) {
res.data = {} res.data = {}
...@@ -415,6 +415,19 @@ function _getLastMsgNote({ ...@@ -415,6 +415,19 @@ function _getLastMsgNote({
async function _createOrUpdateConversation(conversation_id, msgData, chat_source) { async function _createOrUpdateConversation(conversation_id, msgData, chat_source) {
// 设置会话 最后一条消息 的描述 // 设置会话 最后一条消息 的描述
let last_msg_note = _getLastMsgNote(msgData) 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 { const {
...@@ -542,13 +555,6 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source ...@@ -542,13 +555,6 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source
if (msgData.group_id) { if (msgData.group_id) {
senderConversation.leave = false senderConversation.leave = false
senderConversation.has_unread_group_notification = null 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 senderConversation.group_type = groupInfo?.type
// 群聊只为当前用户创建会话 // 群聊只为当前用户创建会话
await dbUniImConversation.add(senderConversation) await dbUniImConversation.add(senderConversation)
...@@ -631,7 +637,8 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source ...@@ -631,7 +637,8 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source
// 返回消息接收者的isMute状态(仅私聊有效) // 返回消息接收者的isMute状态(仅私聊有效)
return { return {
isMute isMute,
groupInfo
} }
} }
...@@ -715,7 +722,7 @@ async function _checkForReplyMsg(msgData) { ...@@ -715,7 +722,7 @@ async function _checkForReplyMsg(msgData) {
// console.log(987,aboutMsg,msgData.call_uid); // console.log(987,aboutMsg,msgData.call_uid);
} }
async function _processPush({ msgData, isMute, appId }) { async function _processPush({ msgData, isMute, appId,groupInfo }) {
// 处理超长文本,push 发送不了的问题 // 处理超长文本,push 发送不了的问题
_checkForLongMsg(msgData) _checkForLongMsg(msgData)
...@@ -723,8 +730,15 @@ async function _processPush({ msgData, isMute, appId }) { ...@@ -723,8 +730,15 @@ async function _processPush({ msgData, isMute, appId }) {
await _checkForReplyMsg(msgData) await _checkForReplyMsg(msgData)
const { nickname, avatar_file } = msgData const { nickname, avatar_file } = msgData
const title = msgData.type == 'system'? '系统消息' : nickname.slice(0, 20) let title
const content = msgData.type == 'text'? msgData.body : '[多媒体]' 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 = { const pushParam = {
payload: { payload: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册