From d6e6c02d96a3e2c0c2bcf0c95366206995a167de Mon Sep 17 00:00:00 2001 From: DCloud_JSON Date: Thu, 5 Sep 2024 20:18:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20uni-im-msg-reader=20?= =?UTF-8?q?=E4=B8=BA=201.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uni-im-msg-reader/changelog.md | 4 + .../uni-im-msg-reader/uni-im-msg-reader.vue | 433 +++++++++--------- uni_modules/uni-im-msg-reader/extension.js | 42 +- uni_modules/uni-im-msg-reader/package.json | 18 +- .../pages/reader-list/reader-list.vue | 38 ++ .../common/uni-im-ext-msg-reader/package.json | 2 +- 6 files changed, 313 insertions(+), 224 deletions(-) create mode 100644 uni_modules/uni-im-msg-reader/pages/reader-list/reader-list.vue diff --git a/uni_modules/uni-im-msg-reader/changelog.md b/uni_modules/uni-im-msg-reader/changelog.md index 39f6535..9d15e81 100644 --- a/uni_modules/uni-im-msg-reader/changelog.md +++ b/uni_modules/uni-im-msg-reader/changelog.md @@ -1,2 +1,6 @@ ## 1.0.0(2024-05-06) 第一版 +## 1.0.1(2024-06-21) +更新:在移动端点击未读详情时,以独立页面展示 +## 1.0.2(2024-11-06) +更新:兼容 uni-im 3.4.x \ No newline at end of file diff --git a/uni_modules/uni-im-msg-reader/components/uni-im-msg-reader/uni-im-msg-reader.vue b/uni_modules/uni-im-msg-reader/components/uni-im-msg-reader/uni-im-msg-reader.vue index a3437ec..d3397ff 100644 --- a/uni_modules/uni-im-msg-reader/components/uni-im-msg-reader/uni-im-msg-reader.vue +++ b/uni_modules/uni-im-msg-reader/components/uni-im-msg-reader/uni-im-msg-reader.vue @@ -1,84 +1,90 @@ - \ No newline at end of file diff --git a/uni_modules/uni-im-msg-reader/extension.js b/uni_modules/uni-im-msg-reader/extension.js index 05bc76d..d201681 100644 --- a/uni_modules/uni-im-msg-reader/extension.js +++ b/uni_modules/uni-im-msg-reader/extension.js @@ -1,6 +1,27 @@ import uniIm from '@/uni_modules/uni-im/sdk/index.js' - +import UniImMsgReader from '@/uni_modules/uni-im-msg-reader/components/uni-im-msg-reader/uni-im-msg-reader.vue' function install() { + + // 配置在什么情况下启用已读功能 + uniIm.extensions.installExt('msg-extra', (msg, currentUser) => { + // 仅限“我”发送的消息 + if (msg.from_uid !== uniIm.currentUser._id) return + // 仅限内部用户 + if (!uniIm.currentUser.role.includes('staff')) return + // 排除特殊消息 + if (msg.type == 'system' || msg.is_revoke) return + // 仅限私聊会话 + let conversation = uniIm.conversation.find(msg.conversation_id) + if (!conversation?.friend_uid) return + return { + component: UniImMsgReader, + props: { + msg + } + } + }) + + // 注册 read_msg 消息类型 uniIm.extensions.installExt('msg-type-register', () => { return { @@ -18,38 +39,39 @@ function install() { from_uid, create_time, } = msgData - const msg = conversation.msgList.find(msg => msg._id === msgId) + // debugger + const msg = conversation.msg.find(msgId) if (msg) { let reader = { user_id: from_uid, create_time } msg.reader_list ? msg.reader_list.push(reader) : msg.reader_list = [reader] - conversation.msgManager.localMsg.update(msg.unique_id, msg) } }, } }) // 监听每条消息的显示状态,报送 read_msg 消息 - uniIm.extensions.installExt('msg-appear', (msg, currentUser) => { + uniIm.extensions.installExt('msg-appear', msg => { + const currentUid = uniIm.currentUser._id // 特殊消息不用处理 if (msg.type === 'system' || msg.is_revoke) return // 如果是我发送的消息则不处理 - if (msg.from_uid == currentUser.user_id) return + if (msg.from_uid == currentUid) return // 如果我已经在已读列表里则不再处理 - if (msg.reader_list?.some(u => u.user_id == currentUser.user_id)) return + if (msg.reader_list?.some(u => u.user_id == currentUid)) return // 如果是群聊消息且没有 @我,则不用处理 - let conversation = uniIm.conversation.getCached(msg.conversation_id) - if (conversation.group_id && !msg.call_uid?.includes(currentUser.user_id)) return + let conversation = uniIm.conversation.find(msg.conversation_id) + if (conversation.group_id && !msg.call_uid?.includes(currentUid)) return // 把自己记入已读列表 msg.reader_list = msg.reader_list || [] msg.reader_list.push({ - user_id: currentUser.user_id, + user_id: currentUid, create_time: Date.now() }) @@ -64,7 +86,7 @@ function install() { } }).catch(e => { // 提交失败,把自己从已读列表里去掉 - msg.reader_list = msg.reader_list.filter(u => u.user_id !== currentUser.user_id) + msg.reader_list = msg.reader_list.filter(u => u.user_id !== currentUid) }) }) } diff --git a/uni_modules/uni-im-msg-reader/package.json b/uni_modules/uni-im-msg-reader/package.json index 10219f9..3b9ad03 100644 --- a/uni_modules/uni-im-msg-reader/package.json +++ b/uni_modules/uni-im-msg-reader/package.json @@ -1,14 +1,14 @@ { "id": "uni-im-msg-reader", "displayName": "uni-im-msg-reader", - "version": "1.0.0", + "version": "1.0.2", "description": "uni-im的消息已读未读状态展示插件", "keywords": [ "uni-im-msg-reader" ], "repository": "", "engines": { - "HBuilderX": "^4.14" + "HBuilderX": "^4.29" }, "dcloudext": { "type": "component-vue", @@ -25,7 +25,7 @@ }, "declaration": { "ads": "无", - "data": "插件不采集任何数据", + "data": "无", "permissions": "无" }, "npmurl": "" @@ -46,17 +46,17 @@ }, "App": { "app-vue": "y", - "app-nvue": "y", + "app-nvue": "n", "app-uvue": "n" }, "H5-mobile": { - "Safari": "n", - "Android Browser": "n", - "微信浏览器(Android)": "n", - "QQ浏览器(Android)": "n" + "Safari": "y", + "Android Browser": "y", + "微信浏览器(Android)": "y", + "QQ浏览器(Android)": "y" }, "H5-pc": { - "Chrome": "n", + "Chrome": "y", "IE": "n", "Edge": "n", "Firefox": "n", diff --git a/uni_modules/uni-im-msg-reader/pages/reader-list/reader-list.vue b/uni_modules/uni-im-msg-reader/pages/reader-list/reader-list.vue new file mode 100644 index 0000000..866c189 --- /dev/null +++ b/uni_modules/uni-im-msg-reader/pages/reader-list/reader-list.vue @@ -0,0 +1,38 @@ + + + + + diff --git a/uni_modules/uni-im-msg-reader/uniCloud/cloudfunctions/common/uni-im-ext-msg-reader/package.json b/uni_modules/uni-im-msg-reader/uniCloud/cloudfunctions/common/uni-im-ext-msg-reader/package.json index 8fb18f5..74a9ba1 100644 --- a/uni_modules/uni-im-msg-reader/uniCloud/cloudfunctions/common/uni-im-ext-msg-reader/package.json +++ b/uni_modules/uni-im-msg-reader/uniCloud/cloudfunctions/common/uni-im-ext-msg-reader/package.json @@ -1,6 +1,6 @@ { "name": "uni-im-ext-msg-reader", - "version": "1.0.0", + "version": "1.0.2", "description": "", "main": "index.js", "keywords": [], -- GitLab