From a5bd5a898c41f207ab851ef3b1618ac67ba23a8c Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 23 Feb 2022 16:06:41 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=B5=84=E6=96=99=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=9A=84=E4=BA=8B=E4=BB=B6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/im/components/groupUserList.vue | 6 ++---- pages/im/group/chat.vue | 28 +++++++++++++++------------ utils/im/listeners.js | 18 ++++++++++++++++- utils/im/onGroupDismiss.js | 20 +++++++++++++++++++ 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/pages/im/components/groupUserList.vue b/pages/im/components/groupUserList.vue index 3f95dfe..5283b15 100644 --- a/pages/im/components/groupUserList.vue +++ b/pages/im/components/groupUserList.vue @@ -62,10 +62,9 @@ actionMap: [], actionTitle: '', currentUser: {}, - avatarSize: 45, + avatarSize: 40, labelSize: 14, iconSize: 14 - } }, computed: { @@ -76,7 +75,7 @@ } }, created() { - this.avatarSize = utils.rpx2px(90) + this.avatarSize = utils.rpx2px(84) this.labelSize = utils.rpx2px(24) this.iconSize = utils.rpx2px(26) }, @@ -277,7 +276,6 @@ border-radius: 0 8rpx 0 0; position: relative; width: 84rpx; - height: 84rpx; overflow: hidden; .admin { diff --git a/pages/im/group/chat.vue b/pages/im/group/chat.vue index 1fb05ce..b75f21a 100644 --- a/pages/im/group/chat.vue +++ b/pages/im/group/chat.vue @@ -21,11 +21,11 @@ import sentMessageBar from '../components/sentMessageBar' import showMessageCell from '../components/showMessageCell' import utils from '@/utils/index.js' - import onGroupDismiss from '@/utils/im/onGroupDismiss.js' - - export default { - mixins: [ - onGroupDismiss + import onGroupDismiss from '@/utils/im/onGroupDismiss.js' + + export default { + mixins: [ + onGroupDismiss ], components: { sentMessageBar, @@ -55,12 +55,7 @@ }, onLoad(e) { this.targetId = e.targetId - // 获取群成员数量 - getGroupBase(this.targetId).then(res => { - uni.setNavigationBarTitle({ - title: res.name + `(${res.members})` - }) - }) + this.initGroupInfo() // 获取历史消息列表 this.getMessageList() // 监听新消息 @@ -103,7 +98,8 @@ }) }, onUnload() { - uni.$off('onReceiveMessage_' + this.targetId) + uni.$off('onReceiveMessage_' + this.targetId) + uni.$off('onUpdateProfile_' + this.targetId) uni.$off('onRecallMessage') uni.$off('onReceiptRequest') uni.$off('onReceiptResponse') @@ -114,6 +110,14 @@ }) }, methods: { + initGroupInfo() { + // 获取群信息,成员数量,设置标题 + getGroupBase(this.targetId).then(res => { + uni.setNavigationBarTitle({ + title: res.name + `(${res.members})` + }) + }) + }, onScroll(e) { this.$refs.messageBar.onHidePopus() }, diff --git a/utils/im/listeners.js b/utils/im/listeners.js index 63e59e6..f9ded27 100644 --- a/utils/im/listeners.js +++ b/utils/im/listeners.js @@ -30,6 +30,7 @@ const onReceiveMessage = (message) => { const checkContactExists = (message) => { if (!store.getters.contactIsExist(message.targetId)) { getUserInfo(message.targetId).then(res => { + console.log('targetId', res); store.dispatch('initContact', res) }).catch(err => { console.error('getUserInfo ERR', err) @@ -37,6 +38,7 @@ const checkContactExists = (message) => { } if (!store.getters.contactIsExist(message.senderUserId)) { getUserInfo(message.senderUserId).then(res => { + console.log('senderUserId', message.senderUserId, res); store.dispatch('initContact', res) }).catch(err => { console.error('getUserInfo ERR', err) @@ -69,7 +71,8 @@ const imLibListeners = () => { checkContactExists(message) if (utils.inArray(message.objectName, notifyMsgTypes)) { onReceiveMessage(message) - } else if (message.objectName === IMLib.ObjectName.ProfileNotification) { + } else if (message.objectName === IMLib.ObjectName.ProfileNotification) { + uni.$emit('onUpdateProfile_' + message.targetId) // 更新联系人信息 store.dispatch('updateContact', JSON.parse(message.content.data)) // 调用完更新之后,删除这条消息 @@ -89,6 +92,19 @@ const imLibListeners = () => { // 发布群解散的消息 uni.$emit('onGroupDismiss') uni.$emit('onGroupDismiss_' + message.targetId) + } else if (message.content.operation === 'REMOVE') { + // 要判断是否当前用户,然后把当前用户踢出到主页去, 删除聊天记录,会话列表 + if (message.content.extra == store.getters.sender.userId) { + IMLib.cleanHistoryMessages(message.conversationType, message.targetId, message.sentTime, + false) + // 解散了就删了吧 + IMLib.removeConversation(message.conversationType, message.targetId) + // 为了更新群列表 + uni.$emit('onGroupDismiss') + uni.$emit('onGroupRemoveYou_' + message.targetId) + } + uni.$emit('onReceiveMessage_' + message.targetId, message) + // 这个是为了更新消息列表页的 } // 触发刷新会话列表 uni.$emit('onReceiveMessage', message) diff --git a/utils/im/onGroupDismiss.js b/utils/im/onGroupDismiss.js index 4b6b607..1f76c40 100644 --- a/utils/im/onGroupDismiss.js +++ b/utils/im/onGroupDismiss.js @@ -1,6 +1,13 @@ // 监听群解散的消息,直接跳转到会话列表页面 const onGroupDismiss = { + data() { + return { + currentTargetId: '' + } + }, onLoad(e) { + this.currentTargetId = e.targetId + uni.$once('onGroupDismiss_' + e.targetId, () => { uni.showToast({ icon: 'none', @@ -10,6 +17,19 @@ const onGroupDismiss = { url: '/pages/im/index' }) }) + uni.$once('onGroupRemoveYou_' + e.targetId, () => { + uni.showToast({ + icon: 'none', + title: '您已被移出群聊' + }) + uni.switchTab({ + url: '/pages/im/index' + }) + }) + }, + onUnload() { + uni.$off('onGroupDismiss_' + this.currentTargetId) + uni.$off('onGroupRemoveYou_' + this.currentTargetId) } } From 20317cc1df9d141f4634a37369a8bd35fcb9af50 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 23 Feb 2022 16:29:06 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E7=BE=A4=E5=85=AC=E5=91=8A=E7=9A=84?= =?UTF-8?q?=E7=BE=A4=E5=86=85=E6=8F=90=E9=86=92=EF=BC=8C=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/im/components/showMessageCell.vue | 24 +++++++++++++++++++++++- pages/im/group/announceCreate.vue | 4 ++-- pages/im/group/announcement.vue | 4 ++-- utils/im/listeners.js | 3 ++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/pages/im/components/showMessageCell.vue b/pages/im/components/showMessageCell.vue index ec41398..f01d07d 100644 --- a/pages/im/components/showMessageCell.vue +++ b/pages/im/components/showMessageCell.vue @@ -1,6 +1,10 @@