From 2122a0b07933884f08a748c4560a223ca127f477 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 14 Feb 2022 17:59:01 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E7=BE=A4=E6=88=90=E5=91=98=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/im/group/info.vue | 56 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/pages/im/group/info.vue b/pages/im/group/info.vue index 2ca4871..9da3ed2 100644 --- a/pages/im/group/info.vue +++ b/pages/im/group/info.vue @@ -2,8 +2,10 @@ - - + + + {{ item.name }} @@ -57,6 +59,10 @@ + + + @@ -90,7 +96,24 @@ qrContent: 'JOINGROUP|', joinType: '', joinTypeMap: [], - showActions: false + showActions: false, + showUserAction: false, + userActionMap: [{ + key: 0, + name: '移除成员', + disabled: false + }, { + key: 1, + name: '设置管理', + disabled: true + }, + { + key: 2, + name: '转移群主', + disabled: true + } + ], + currentUser: {} } }, onLoad(e) { @@ -132,6 +155,7 @@ return item.key == res.join_type })[0].name }).catch(err => { + console.log('getGroupInfo ERR', err); uni.showToast({ icon: 'none', title: '群不存在' @@ -268,7 +292,7 @@ item.disabled = false } return item - }) + }) this.initData() this.joinType = e.name this.showActions = false @@ -332,6 +356,30 @@ } } }) + }, + showUserActionSheet(item) { + this.currentUser = item + // 只有管理员以上才会弹窗 + if (this.group.is_admin) { + if (this.group.is_owner) { + this.userActionMap.map((item) => { + item.disabled = false + return item + }) + } + this.showUserAction = true + } + }, + hideUserAction() { + this.currentUser = {} + this.showUserAction = false + }, + handleUserAction(e) { + uni.showToast({ + icon: 'none', + title: e.name + }) + console.log(e); } } } From a831b65a5fd8da4f929a8607a4964befd9c25942 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 15 Feb 2022 10:14:52 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=88=90=E5=91=98=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E5=9F=BA=E7=A1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/interfaces/im.js | 65 +++++- pages/im/group/info.vue | 79 ++++++- pages/setting/setting.vue | 422 +++++++++++++++++++------------------- 3 files changed, 344 insertions(+), 222 deletions(-) diff --git a/apis/interfaces/im.js b/apis/interfaces/im.js index 2eb828a..ac954f5 100644 --- a/apis/interfaces/im.js +++ b/apis/interfaces/im.js @@ -117,9 +117,10 @@ const getGroupBase = (groupId) => { }) } -const getGroupUsers = (groupId) => { +const getGroupUsers = (groupId, limit) => { + limit = limit || 0 return request({ - url: 'im/groups/' + groupId + '/users' + url: 'im/groups/' + groupId + '/users?limit=' + limit }) } @@ -210,6 +211,59 @@ const dismissGroup = (groupId) => { }) } +/** + * 移除群成员 + */ +const removeGroupUser = (groupId, userId) => { + return request({ + method: 'DELETE', + url: 'im/groups/' + groupId + '/users/' + userId + }) +} + +/** + * 邀请群成员 + */ +const inviteGroupUser = (groupId, userIds) => { + return request({ + method: 'POST', + url: 'im/groups/' + groupId + '/invite', + data: { + userIds + } + }) +} + +/** + * 设置群管理 + */ +const setGroupAdmin = (groupId, userId) => { + return request({ + method: 'POST', + url: 'im/groups/' + groupId + '/admin/' + userId + }) +} + +/** + * 移除群管理 + */ +const removeGroupAdmin = (groupId, userId) => { + return request({ + method: 'DELETE', + url: 'im/groups/' + groupId + '/admin/' + userId + }) +} + +/** + * 转移群主 + */ +const transferGroupOwner = (groupId, userId) => { + return request({ + method: 'DELETE', + url: 'im/groups/' + groupId + '/owner/' + userId + }) +} + export { getImToken, deleteFriend, @@ -235,5 +289,10 @@ export { joinGroupPre, joinGroup, quitGroup, - dismissGroup + dismissGroup, + inviteGroupUser, + removeGroupUser, + setGroupAdmin, + removeGroupAdmin, + transferGroupOwner } diff --git a/pages/im/group/info.vue b/pages/im/group/info.vue index 9da3ed2..cfe3242 100644 --- a/pages/im/group/info.vue +++ b/pages/im/group/info.vue @@ -2,7 +2,8 @@ - @@ -71,7 +72,12 @@ getGroupInfo, updateGroup, quitGroup, - dismissGroup + removeGroupUser, + setGroupAdmin, + removeGroupAdmin, + dismissGroup, + transferGroupOwner, + getGroupUsers } from '@/apis/interfaces/im.js' import { uploads @@ -133,18 +139,23 @@ } }) this.initData() + this.initUsers() uni.$on('groupAnnouncementCreated', this.initData) }, onUnload() { uni.$off('groupAnnouncementCreated') }, methods: { + initUsers() { + getGroupUsers(this.targetId, 14).then(res => { + this.users = res + }) + }, initData() { getGroupInfo(this.targetId).then(res => { this.group = res.group this.groupName = res.group.name this.announcement = res.announcement - this.users = res.users this.members = res.members this.loaded = true this.joinTypeMap = res.join_type_map.map(item => { @@ -191,7 +202,10 @@ } }, inviteUser() { - + uni.showToast({ + icon: 'none', + title: '开发中' + }) }, loadMore() { uni.navigateTo({ @@ -375,11 +389,54 @@ this.showUserAction = false }, handleUserAction(e) { - uni.showToast({ - icon: 'none', - title: e.name - }) - console.log(e); + switch (e.key) { + case 0: + removeGroupUser(this.targetId, this.currentUser.targetId).then(res => { + uni.showToast({ + icon: 'none', + title: '成员移除成功' + }) + }).catch(err => { + uni.showToast({ + icon: 'none', + title: err.message + }) + }).finally(() => { + this.initUsers() + }) + break; + case 1: + setGroupAdmin(this.targetId, this.currentUser.targetId).then(res => { + uni.showToast({ + icon: 'none', + title: '设置管理成功' + }) + }).catch(err => { + uni.showToast({ + icon: 'none', + title: err.message + }) + }).finally(() => { + this.initUsers() + }) + break; + case 2: + transferGroupOwner(this.targetId, this.currentUser.targetId).then(res => { + uni.showToast({ + icon: 'none', + title: '群主转让成功' + }) + }).catch(err => { + uni.showToast({ + icon: 'none', + title: err.message + }) + }).finally(() => { + this.initUsers() + this.initData() + }) + break; + } } } } @@ -415,6 +472,10 @@ justify-content: center; align-items: center; + &.active { + background-color: $window-color; + } + .name { color: $text-gray-m; width: 126rpx; diff --git a/pages/setting/setting.vue b/pages/setting/setting.vue index 124931b..fa6f7f5 100644 --- a/pages/setting/setting.vue +++ b/pages/setting/setting.vue @@ -1,211 +1,213 @@ - - - - - From 53e800738bd22d25e40a2c79afb644ded41cdec7 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 15 Feb 2022 11:04:05 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=B0=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E8=8E=B7=E5=8F=96=E6=A8=A1=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=89=8D=E6=98=AF=E5=88=B7=E6=96=B0=E6=95=B4=E4=BD=93?= =?UTF-8?q?=E5=88=97=E8=A1=A8=EF=BC=8C=E6=9B=B4=E6=94=B9=E4=B8=BAconcat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/im/group/chat.nvue | 18 +++++++++++++++--- pages/im/private/chat.nvue | 37 ++++++++++++++++++++++++++++--------- utils/im/message.js | 2 +- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/pages/im/group/chat.nvue b/pages/im/group/chat.nvue index 74bac82..a54b351 100644 --- a/pages/im/group/chat.nvue +++ b/pages/im/group/chat.nvue @@ -16,7 +16,7 @@ - + @@ -59,7 +59,7 @@ this.getMessageList() uni.$on('onReceiveMessage', (msg) => { if (msg.targetId == this.targetId) { - this.getMessageList() + this.getNewMessage() } }) uni.$once('cleanGroupMessage', this.getMessageList) @@ -87,6 +87,18 @@ url: '/pages/im/friends/info?targetId=' + item.senderUserId }) } + }, + getNewMessage() { + im.getMessageList( + this.conversationType, + this.targetId, + new Date().getTime(), + 10, + false, + (messages) => { + this.messages = this.messages.concat(messages) + this.scrollBottom() + }) }, // 获取消息列表 getMessageList() { @@ -94,7 +106,7 @@ this.conversationType, this.targetId, new Date().getTime(), - 20, + 100, true, (messages) => { this.messages = messages.reverse() diff --git a/pages/im/private/chat.nvue b/pages/im/private/chat.nvue index 57e407c..c1ec122 100644 --- a/pages/im/private/chat.nvue +++ b/pages/im/private/chat.nvue @@ -6,8 +6,9 @@ {{ customCN(item.sentTime) }} - - + + @@ -23,7 +24,7 @@ - + @@ -70,30 +71,48 @@ // 监听消息已读状态 uni.$on('onReadReceiptReceived', (data) => { if (data.targetId == this.targetId) { - this.getMessageList() + this.messages = this.messages.map((item) => { + if (item.messageDirection == 1 && item.sentStatus == 30 && item.receivedTime < + data.messageTime + 1000) { + item.sentStatus = 50 + } + return item + }) } }) // 监听收到新消息,判断是否是当前会话,更新会话内容 uni.$on('onReceiveMessage', (msg) => { if (msg.targetId == this.targetId) { - this.getMessageList() + this.getNewMessage() } }) }, - onBackPress() { - uni.$off('onReceiveMessage') + onUnload() { + uni.$off('onReadReceiptReceived') }, methods: { customCN(val) { return timeCustomCN(val) }, + getNewMessage() { + im.getMessageList( + this.conversationType, + this.targetId, + new Date().getTime(), + 10, + false, + (messages) => { + this.messages = this.messages.concat(messages) + this.scrollBottom() + }) + }, // 获取消息列表 getMessageList() { im.getMessageList( this.conversationType, this.targetId, new Date().getTime(), - 10, + 100, true, (messages) => { this.messages = messages.reverse() @@ -110,7 +129,7 @@ // 滚动到底部 scrollBottom(type) { // 清理当前会话,未读消息数量 - RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100) + RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime()) // 发送消息已读状态给对方 RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime()) // 更新badge提醒数量 diff --git a/utils/im/message.js b/utils/im/message.js index 15dc586..53e51d1 100644 --- a/utils/im/message.js +++ b/utils/im/message.js @@ -22,7 +22,7 @@ const getMessageList = (conversationType, targetId, timeStamp, count, isForward, conversationType, targetId, objectNames, - timeStamp + 1000, + timeStamp, count, isForward, ({ From ad58731a78b49edadbf6150c4549ed95bbf33e87 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 15 Feb 2022 11:55:48 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/interfaces/im.js | 2 +- pages.json | 33 ++++++++++++++++++++------------- pages/im/group/info.vue | 13 ++++++++----- pages/im/group/invite.vue | 21 +++++++++++++++++++++ 4 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 pages/im/group/invite.vue diff --git a/apis/interfaces/im.js b/apis/interfaces/im.js index ac954f5..deb8b1c 100644 --- a/apis/interfaces/im.js +++ b/apis/interfaces/im.js @@ -196,7 +196,7 @@ const joinGroup = (groupId, message) => { const quitGroup = (groupId) => { return request({ - method: 'POST', + method: 'DELETE', url: 'im/groups/' + groupId + '/quit' }) } diff --git a/pages.json b/pages.json index d662e57..61a9c6a 100644 --- a/pages.json +++ b/pages.json @@ -52,8 +52,8 @@ "path": "pages/record/foods", "name": "RecordFoods", "style": { - "navigationBarTitleText": "", - "navigationStyle": "custom" + "navigationBarTitleText": "", + "navigationStyle": "custom" } }, { @@ -467,33 +467,40 @@ } } } - }, - { - "path": "pages/im/group/apply", - "name": "imGroupApply", - "style": { - "navigationBarTitleText": "申请加群" - } + }, + { + "path": "pages/im/group/apply", + "name": "imGroupApply", + "style": { + "navigationBarTitleText": "申请加群" + } }, { "path": "pages/im/group/info", "name": "imGroupInfo", "style": { - "navigationBarTitleText": "群信息" + "navigationBarTitleText": "群信息" + } + }, + { + "path": "pages/im/group/invite", + "name": "imGroupInvite", + "style": { + "navigationBarTitleText": "邀请好友" } }, { "path": "pages/im/group/users", "name": "imGroupUsers", "style": { - "navigationBarTitleText": "群成员" + "navigationBarTitleText": "群成员" } }, { "path": "pages/im/group/announcement", "name": "imGroupAnnouncement", "style": { - "navigationBarTitleText": "群公告", + "navigationBarTitleText": "群公告", "app-plus": { "titleNView": { "type": "default", @@ -511,7 +518,7 @@ "path": "pages/im/group/announceCreate", "name": "imGroupAnnouncementCreate", "style": { - "navigationBarTitleText": "发布群公告" + "navigationBarTitleText": "发布群公告" } }, { diff --git a/pages/im/group/info.vue b/pages/im/group/info.vue index cfe3242..f716b78 100644 --- a/pages/im/group/info.vue +++ b/pages/im/group/info.vue @@ -202,9 +202,8 @@ } }, inviteUser() { - uni.showToast({ - icon: 'none', - title: '开发中' + uni.navigateTo({ + url: '/pages/im/group/invite?targetId=' + this.targetId }) }, loadMore() { @@ -247,7 +246,6 @@ }, // 修改群头像 onGroupAvatar() { - console.log('onGroupAvatar'); uni.chooseImage({ count: 1, sourceType: ['album'], @@ -362,10 +360,15 @@ uni.showToast({ icon: 'none', title: '退出群聊成功' - }) + }) + // 移除指定的会话 + RongIMLib.removeConversation(this.conversationType, this.targetId) + uni.switchTab({ url: '/pages/im/index' }) + }).catch(err => { + console.log(err); }) } } diff --git a/pages/im/group/invite.vue b/pages/im/group/invite.vue new file mode 100644 index 0000000..fa5fb59 --- /dev/null +++ b/pages/im/group/invite.vue @@ -0,0 +1,21 @@ + + + + + From f9dfd6b08dc36d18bc08c6e819938a4261f28c38 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 16 Feb 2022 11:19:53 +0800 Subject: [PATCH 5/7] =?UTF-8?q?IM=E7=99=BB=E5=BD=95=E5=AE=8C=E5=96=84?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=AD=A5=E5=A5=BD=E5=8F=8B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E5=90=8C=E6=AD=A5=E7=BE=A4?= =?UTF-8?q?=E7=BB=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/auth/auth.vue | 10 ++++++++++ public/userAuth.js | 4 +++- store/modules/im.js | 2 +- utils/im/index.js | 23 +++++++++++++---------- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/pages/auth/auth.vue b/pages/auth/auth.vue index 05f59cf..ec3b273 100644 --- a/pages/auth/auth.vue +++ b/pages/auth/auth.vue @@ -39,6 +39,11 @@ smsAuth } from "@/apis/interfaces/auth"; import userAuth from "@/public/userAuth"; + import { + getImToken + } from '@/apis/interfaces/im.js' + import im from '@/utils/im/index.js' + export default { data() { return { @@ -59,6 +64,11 @@ "setToken", res.token_type + " " + res.access_token ); + // 在这里,登录成功,链接IM服务 + getImToken().then(res => { + console.log('在这获取IM-TOKEN', res); + im.connect(res.token, res.userInfo, () => {}) + }) this.$Router.back(); }).catch((err) => { uni.showToast({ diff --git a/public/userAuth.js b/public/userAuth.js index 0257a3a..faf4df5 100644 --- a/public/userAuth.js +++ b/public/userAuth.js @@ -105,9 +105,11 @@ class userAuth { openid: authResult.authResult.openid }).then(res => { uni.closeAuthView() - store.commit('setToken', res.token_type + ' ' + res.access_token) + store.commit('setToken', res.token_type + ' ' + res + .access_token) // 在这里,登录成功,链接IM服务 getImToken().then(res => { + console.log('在这获取IM-TOKEN', res); im.connect(res.token, res.userInfo) }) resolve() diff --git a/store/modules/im.js b/store/modules/im.js index 7d482b6..8077e66 100644 --- a/store/modules/im.js +++ b/store/modules/im.js @@ -34,7 +34,7 @@ export default { } }, mutations: { - updateContactInfo(state, contactInfo) { + updateContactInfo(state, contactInfo) { Vue.set(state.contacts, contactInfo.targetId, contactInfo) }, setSenderInfo(state, contactInfo) { diff --git a/utils/im/index.js b/utils/im/index.js index 4c22b53..7fdf5dc 100644 --- a/utils/im/index.js +++ b/utils/im/index.js @@ -6,7 +6,8 @@ import listeners from './listeners.js' import { getFriends, getUserInfo, - getImToken + getImToken, + getMyGroups } from '@/apis/interfaces/im.js' const initIm = (KEY) => { @@ -58,7 +59,7 @@ const connect = (token, userInfo, callback) => { // 设置未读消息数量 setNotifyBadge() // 首次运行获取好友列表 - const FK = 'IFT_' + userInfo.targetId + const FK = 'ZHK_' + userInfo.targetId uni.getStorage({ key: FK, @@ -70,12 +71,14 @@ const connect = (token, userInfo, callback) => { }) }) }, - fail: () => { - // 程序是首次运行,初始化加载好友信息 - getFriends().then(res => { - res.map(item => { - store.dispatch('initContact', item) - }) + fail: () => { + // 程序是首次运行,初始化加载好友和群组信息 + Promise.all([getFriends(), getMyGroups()]).then(result => { + result.map(contacts => { + contacts.map(item => { + store.dispatch('initContact', item) + }) + }) uni.setStorageSync(FK, userInfo.targetId) }) } @@ -206,8 +209,8 @@ const newMessage = (msg) => { status }) => { if (code === 0) { - if (status) { - uni.vibrateLong() + if (status) { + uni.vibrateLong() triTone() } } From a88875ed55f046748e2d23bbe907a31d615de98e Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 16 Feb 2022 12:00:42 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=B3=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/im/group/chat.nvue | 87 ++++++++++++++++++++------------------ pages/im/private/chat.nvue | 54 +++++++++++++---------- 2 files changed, 77 insertions(+), 64 deletions(-) diff --git a/pages/im/group/chat.nvue b/pages/im/group/chat.nvue index a54b351..dd23435 100644 --- a/pages/im/group/chat.nvue +++ b/pages/im/group/chat.nvue @@ -3,7 +3,8 @@ - + @@ -43,12 +44,17 @@ data() { return { targetId: '', - conversationType: 3, + conversationType: RongIMLib.ConversationType.GROUP, messages: [], groupInfo: { name: '' } } + }, + computed: { + latestMessage() { + return this.messages[this.messages.length - 1] + } }, onLoad(e) { this.targetId = e.targetId @@ -61,51 +67,47 @@ if (msg.targetId == this.targetId) { this.getNewMessage() } - }) - uni.$once('cleanGroupMessage', this.getMessageList) - }, - onBackPress() { - uni.$off('onReceiveMessage') - console.log('Off onReceiveMessage'); + }) + uni.$once('cleanGroupMessage', this.getMessageList) }, onNavigationBarButtonTap() { uni.navigateTo({ url: '/pages/im/group/info?targetId=' + this.targetId }) }, - methods: { - toUser(item) { - if (item.senderUserId == '__system__') { - return - } - if (item.messageDirection == 1) { - uni.navigateTo({ - url: '/pages/im/friends/mine?targetId=' + item.senderUserId - }) - } else{ - uni.navigateTo({ - url: '/pages/im/friends/info?targetId=' + item.senderUserId - }) - } - }, - getNewMessage() { - im.getMessageList( - this.conversationType, - this.targetId, - new Date().getTime(), - 10, - false, - (messages) => { - this.messages = this.messages.concat(messages) - this.scrollBottom() - }) + methods: { + toUser(item) { + if (item.senderUserId == '__system__') { + return + } + if (item.messageDirection == 1) { + uni.navigateTo({ + url: '/pages/im/friends/mine?targetId=' + item.senderUserId + }) + } else { + uni.navigateTo({ + url: '/pages/im/friends/info?targetId=' + item.senderUserId + }) + } + }, + getNewMessage() { + im.getMessageList( + this.conversationType, + this.targetId, + this.latestMessage.sentTime, + 1, + false, + (messages) => { + this.messages = this.messages.concat(messages) + this.scrollBottom() + }) }, // 获取消息列表 getMessageList() { im.getMessageList( this.conversationType, this.targetId, - new Date().getTime(), + 0, 100, true, (messages) => { @@ -115,12 +117,15 @@ }, // 滚动到底部 scrollBottom(type) { - // 清理当前会话,未读消息数量 - RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100) - // 发送消息已读状态给对方 - RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime()) - // 更新badge提醒数量 - im.setNotifyBadge() + if (this.latestMessage) { + // 清理当前会话,未读消息数量 + RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage + .sentTime) + // // 发送消息已读状态给对方 + // RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime) + // 更新badge提醒数量 + im.setNotifyBadge() + } setTimeout(() => { let el = this.$refs.chatBottom diff --git a/pages/im/private/chat.nvue b/pages/im/private/chat.nvue index c1ec122..1fb5400 100644 --- a/pages/im/private/chat.nvue +++ b/pages/im/private/chat.nvue @@ -42,6 +42,12 @@ const ChatList = uni.requireNativePlugin('dom') export default { + components: { + sentMessageBar, + showVoice, + showImage, + showText + }, data() { return { targetId: '', @@ -54,11 +60,10 @@ } } }, - components: { - sentMessageBar, - showVoice, - showImage, - showText + computed: { + latestMessage() { + return this.messages[this.messages.length - 1] + } }, onLoad(e) { this.targetId = e.targetId @@ -94,24 +99,24 @@ customCN(val) { return timeCustomCN(val) }, - getNewMessage() { - im.getMessageList( - this.conversationType, - this.targetId, - new Date().getTime(), - 10, - false, - (messages) => { - this.messages = this.messages.concat(messages) - this.scrollBottom() - }) + getNewMessage() { + im.getMessageList( + this.conversationType, + this.targetId, + this.latestMessage.sentTime, + 1, + false, + (messages) => { + this.messages = this.messages.concat(messages) + this.scrollBottom() + }) }, // 获取消息列表 getMessageList() { im.getMessageList( this.conversationType, this.targetId, - new Date().getTime(), + 0, 100, true, (messages) => { @@ -128,12 +133,15 @@ }, // 滚动到底部 scrollBottom(type) { - // 清理当前会话,未读消息数量 - RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime()) - // 发送消息已读状态给对方 - RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime()) - // 更新badge提醒数量 - im.setNotifyBadge() + if (this.latestMessage) { + // 清理当前会话,未读消息数量 + RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage + .sentTime) + // // 发送消息已读状态给对方 + RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime) + // 更新badge提醒数量 + im.setNotifyBadge() + } setTimeout(() => { let el = this.$refs.chatBottom ChatList.scrollToElement(el, { From 5ad72092deea348f7052ca72dadac145915a2884 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 16 Feb 2022 12:06:17 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E6=97=A0=E6=B3=95=E6=89=BE?= =?UTF-8?q?=E5=88=B0sentTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/im/group/chat.nvue | 8 +++++++- pages/im/private/chat.nvue | 12 +++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pages/im/group/chat.nvue b/pages/im/group/chat.nvue index dd23435..151eec2 100644 --- a/pages/im/group/chat.nvue +++ b/pages/im/group/chat.nvue @@ -53,7 +53,13 @@ }, computed: { latestMessage() { - return this.messages[this.messages.length - 1] + if (this.messages.length > 1) { + return this.messages[this.messages.length - 1] + } else { + return { + sentTime: 0 + } + } } }, onLoad(e) { diff --git a/pages/im/private/chat.nvue b/pages/im/private/chat.nvue index 1fb5400..02dfc0f 100644 --- a/pages/im/private/chat.nvue +++ b/pages/im/private/chat.nvue @@ -61,8 +61,14 @@ } }, computed: { - latestMessage() { - return this.messages[this.messages.length - 1] + latestMessage() { + if (this.messages.length > 1) { + return this.messages[this.messages.length - 1] + } else { + return { + sentTime: 0 + } + } } }, onLoad(e) { @@ -103,7 +109,7 @@ im.getMessageList( this.conversationType, this.targetId, - this.latestMessage.sentTime, + this.latestMessage.sentTime || 0, 1, false, (messages) => {