群解散时,无论在群组中的哪个页面,都退回到会话列表页面

This commit is contained in:
2022-02-23 14:13:38 +08:00
parent 8b10fd95fe
commit 1407d677de
21 changed files with 197 additions and 136 deletions

View File

@@ -7,7 +7,7 @@
export default {
onLaunch: function() {
im.initIm('lmxuhwaglu76d')
return
//#ifdef APP-PLUS
// 获取系统版本号
getVersions({

View File

@@ -70,7 +70,9 @@
clearMessages() {
RongIMLib.deleteMessages(RongIMLib.ConversationType.SYSTEM, this.message.sourceUserId)
this.$emit('success')
uni.$emit('onContactNotification')
uni.$emit('onNewContactConversation', message)
uni.$emit('onNewContactFriends', message)
uni.$emit('onNewContactPendings', message)
}
}
}

View File

@@ -83,7 +83,6 @@
mounted() {
this.initGroupInfo()
getGroupUsers(this.targetId, this.count).then(res => {
console.log("res..",res)
this.users = res
res.map(item => {
this.$store.dispatch('updateContact', item)

View File

@@ -6,8 +6,10 @@
</view>
<view class="content">
<view class="header">
<view class="name">{{ contact(item.targetId).name }} <text v-if="item.conversationType === 3"
class='qun'>[]</text></view>
<view class="name">
{{ contact(item.targetId).name }}
<text v-if="item.conversationType === 3" class='group'>[]</text>
</view>
<view class="time">{{ item.sentTime|timeCustomCN }}</view>
</view>
<message-preview class="preview" :msg="item.latestMessage" :draft="item.draft"
@@ -80,10 +82,8 @@
.name {
font-size: $title-size + 2;
color: #454545;
display: flex;
align-items: center;
.qun {
.group {
color: $main-color;
font-size: $title-size-m - 4;
margin-left: 4px;

View File

@@ -75,11 +75,6 @@
}
})
},
created() {
console.log(this.message.messageId)
},
methods: {
// 播放语音消息
startPlay() {

View File

@@ -57,7 +57,10 @@
onLoad() {
this.getFriendList()
this.checkNewFriendPending()
uni.$on('onContactNotification', this.checkNewFriendPending)
uni.$on('onNewContactFriends', this.checkNewFriendPending)
},
onUnload() {
uni.$off('onNewContactFriends')
},
methods: {
getFriendList() {

View File

@@ -113,7 +113,6 @@
onLoad(e) {
this.targetId = e.targetId
getFriendInfo(e.targetId).then(res => {
console.log(res, "获取朋友的信息")
this.userInfo = res
// 获取到用户信息之后,去检查一下要不要更新
this.$store.dispatch('updateContact', res)
@@ -148,7 +147,7 @@
})
},
toPrivate() {
uni.redirectTo({
uni.navigateTo({
url: '/pages/im/private/chat?targetId=' + this.targetId
});
},
@@ -228,8 +227,9 @@
})
},
singleCall(e) {
uni.redirectTo({
url: '/pages/im/private/call?targetId=' + this.targetId + '&mediaType=' + e.type + '&isCall=true'
uni.navigateTo({
url: '/pages/im/private/call?targetId=' + this.targetId + '&mediaType=' + e.type +
'&isCall=true'
})
}
}

View File

@@ -35,7 +35,10 @@
},
onLoad() {
this.getPendingList()
uni.$on('onContactNotification', this.getPendingList)
uni.$on('onNewContactPendings', this.getPendingList)
},
onUnload() {
uni.$off('onNewContactPendings')
},
methods: {
getPendingList() {

View File

@@ -16,8 +16,12 @@
createGroupAnnouncement,
getGroupAnnouncement
} from '@/apis/interfaces/im.js'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default {
mixins: [
onGroupDismiss
],
data() {
return {
targetId: '',

View File

@@ -35,8 +35,12 @@
deleteGroupAnnouncement,
topGroupAnnouncement
} from '@/apis/interfaces/im.js'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default {
mixins: [
onGroupDismiss
],
data() {
return {
targetId: '',

View File

@@ -20,8 +20,12 @@
joinGroupPre,
joinGroup
} from '@/apis/interfaces/im.js'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default {
mixins: [
onGroupDismiss
],
data() {
return {
targetId: '',

View File

@@ -21,8 +21,12 @@
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
],
components: {
sentMessageBar,
showMessageCell
@@ -59,11 +63,9 @@
})
// 获取历史消息列表
this.getMessageList()
// 监听收到本群的消息,追加消息
uni.$on('onReceiveMessage', (msg) => {
if (msg.targetId == this.targetId) {
// 监听消息
uni.$on('onReceiveMessage_' + this.targetId, (message) => {
this.getNewMessage()
}
})
uni.$on('onReceiptRequest', (msg) => {
if (msg.targetId == this.targetId) {
@@ -101,6 +103,7 @@
})
},
onUnload() {
uni.$off('onReceiveMessage_' + this.targetId)
uni.$off('onRecallMessage')
uni.$off('onReceiptRequest')
uni.$off('onReceiptResponse')
@@ -164,7 +167,7 @@
},
onHide() {
// console.log(JSON.stringify(this.$refs))
this.$refs.voice.stopPlay()
// this.$refs.voice.stopPlay()
}
}
</script>

View File

@@ -65,11 +65,15 @@
} from '@/apis/interfaces/uploading'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import groupUserList from '../components/groupUserList'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default {
components: {
groupUserList
},
mixins: [
onGroupDismiss
],
data() {
return {
targetId: '',
@@ -133,7 +137,6 @@
return item.key == res.join_type
})[0].name
}).catch(err => {
console.log('getGroupInfo ERR', err);
uni.showToast({
icon: 'none',
title: '群不存在'

View File

@@ -8,8 +8,9 @@
<u-index-list :index-list="indexs" inactiveColor="#666" activeColor="#34CE98">
<u-checkbox-group v-if="friends.length > 0" v-model="checkboxValue" placement="column">
<u-index-item v-for="(item, fkey) in friends" :key="fkey">
<u-index-anchor :text="indexs[fkey]" v-if="indexs[fkey]" bgColor="#f9f9f9f" height="20" size="12"
color="#666" style="border:none !important;padding: 10rpx 30rpx;background-color: #f9f9f9 !important;" />
<u-index-anchor :text="indexs[fkey]" v-if="indexs[fkey]" bgColor="#f9f9f9f" height="20"
size="12" color="#666"
style="border:none !important;padding: 10rpx 30rpx;background-color: #f9f9f9 !important;" />
<view v-for="(friendItem, index) in item" :key="index" class="friend-flex"
@click="addContact(friendItem.targetId)">
<u-checkbox :name="friendItem.targetId" shape="circle" activeColor="#34ce98"
@@ -44,10 +45,13 @@
getGroupUsers
} from '@/apis/interfaces/im';
import utils from '@/utils/index.js'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
export default {
mixins: [
onGroupDismiss
],
data() {
return {
searchTxt: '',

View File

@@ -34,9 +34,12 @@
} from "@/apis/interfaces/im.js"
import im from '@/utils/im/message.js'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default {
mixins: [
onGroupDismiss
],
data() {
return {
targetId: '',
@@ -153,6 +156,7 @@
}
}
.no-lists {
padding-top: $padding * 5;
display: flex;

View File

@@ -4,7 +4,12 @@
<script>
import groupUserList from '../components/groupUserList'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default {
mixins: [
onGroupDismiss
],
components: {
groupUserList
},

View File

@@ -57,24 +57,28 @@
// 好友申请数量
this.checkNewFriendPending()
// 监听新的好友申请
uni.$on('onContactNotification', () => {
this.checkNewFriendPending()
})
uni.$on('onNewContactConversation', this.checkNewFriendPending)
},
onShow() {
if (this.$store.state.token !== '') {
this.getConversationList()
}
uni.$on('onConnectionStatusChange', (status) => {
this.connection = status
})
// 监听新消息
uni.$on('onReceiveMessage', (msg) => {
this.getConversationList()
})
// 监听网络状态变化
uni.$on('onConnectionStatusChange', (status) => {
this.connection = status
if (status == 0) {
this.getConversationList()
}
})
},
onHide() {
// 页面隐藏的时候,不监听了,性能可能会好一点
uni.$off('onReceiveMessage')
uni.$off('onConnectionStatusChange')
},
methods: {
checkNewFriendPending() {

View File

@@ -150,7 +150,7 @@
} else {
IMLib.insertIncomingMessage(1, targetId, targetId, sentStatus, messageContent, sentTime)
}
uni.$emit('onReceiveMessage', {
uni.$emit('onReceiveMessage_' + this.targetId, {
targetId: this.targetId
})
},

View File

@@ -60,6 +60,10 @@
})
// 获取消息列表
this.getMessageList()
// 监听新消息
uni.$on('onReceiveMessage_' + this.targetId, (message) => {
this.getNewMessage()
})
// 监听消息已读状态
uni.$on('onReadReceiptReceived', (data) => {
if (data.targetId == this.targetId) {
@@ -72,12 +76,6 @@
})
}
})
// 监听收到新消息,判断是否是当前会话,更新会话内容
uni.$on('onReceiveMessage', (msg) => {
if (msg.targetId == this.targetId) {
this.getNewMessage()
}
})
uni.$on('onRecallMessage', (res) => {
if (res.targetId == this.targetId) {
this.messages = this.messages.map(item => {
@@ -91,6 +89,7 @@
})
},
onUnload() {
uni.$off('onReceiveMessage_' + this.targetId)
uni.$off('onRecallMessage')
uni.$off('onReadReceiptReceived')
},

View File

@@ -20,35 +20,14 @@ const onReceiveMessage = (message) => {
}
})
im.setNotifyBadge()
// 发布全局事件,有新消息,刷新会话列表
uni.$emit('onReceiveMessage', message)
// 这个是为了更新消息列表页的
uni.$emit('onReceiveMessage_' + message.targetId, message)
}
// 允许通知的消息类型,触发更新消息列表操作,提示音
const notifyMsgTypes = [
IMLib.ObjectName.Text,
IMLib.ObjectName.File,
IMLib.ObjectName.Image,
IMLib.ObjectName.GIF,
IMLib.ObjectName.Location,
IMLib.ObjectName.Voice,
IMLib.ObjectName.HQVoice,
IMLib.ObjectName.Sight,
IMLib.ObjectName.Text,
IMLib.ObjectName.Text,
IMLib.ObjectName.Text
]
const imLibListeners = () => {
// 添加连接状态监听函数
IMLib.addConnectionStatusListener((res) => {
console.error('连接状态监听', res.data.status)
uni.$emit('onConnectionStatusChange', res.data.status)
})
// 添加消息监听函数
IMLib.addReceiveMessageListener((res) => {
const message = res.data.message
console.error('[收到消息]', message)
if (utils.inArray(message.objectName, notifyMsgTypes)) {
// 检测联系人信息,不存在的时候,从服务端获取
const checkContactExists = (message) => {
if (!store.getters.contactIsExist(message.targetId)) {
getUserInfo(message.targetId).then(res => {
store.dispatch('initContact', res)
@@ -63,16 +42,43 @@ const imLibListeners = () => {
console.error('getUserInfo ERR', err)
})
}
}
// 允许通知的消息类型,触发更新消息列表操作,提示音
const notifyMsgTypes = [
IMLib.ObjectName.Text,
IMLib.ObjectName.File,
IMLib.ObjectName.Image,
IMLib.ObjectName.GIF,
IMLib.ObjectName.Location,
IMLib.ObjectName.Voice,
IMLib.ObjectName.HQVoice,
IMLib.ObjectName.Sight
]
const imLibListeners = () => {
// 添加连接状态监听函数
IMLib.addConnectionStatusListener((res) => {
console.error('连接状态监听', res.data.status)
uni.$emit('onConnectionStatusChange', res.data.status)
})
// 添加消息监听函数
IMLib.addReceiveMessageListener((res) => {
const message = res.data.message
console.error('[收到消息]', message)
checkContactExists(message)
if (utils.inArray(message.objectName, notifyMsgTypes)) {
onReceiveMessage(message)
} else if (message.objectName === IMLib.ObjectName.ProfileNotification) {
// 更新会话信息
// 更新联系人信息
store.dispatch('updateContact', JSON.parse(message.content.data))
// 调用完更新之后,删除这条消息
IMLib.deleteMessagesByIds([message.messageId])
} else if (message.objectName === IMLib.ObjectName.ContactNotification) {
console.error('触发一个新好友的通知事件', message);
// 触发一个新好友的通知事件
uni.$emit('onContactNotification', message)
// 触发一个新好友的通知事件,【会话列表,通讯录,新朋友】页面
uni.$emit('onNewContactConversation', message)
uni.$emit('onNewContactFriends', message)
uni.$emit('onNewContactPendings', message)
} else if (message.objectName === IMLib.ObjectName.GroupNotification) {
// 解散群
if (message.content.operation === 'Dismiss') {
@@ -80,8 +86,11 @@ const imLibListeners = () => {
false)
// 解散了就删了吧
IMLib.removeConversation(message.conversationType, message.targetId)
uni.$emit('onGroupDismiss', message.targetId)
// 发布群解散的消息
uni.$emit('onGroupDismiss')
uni.$emit('onGroupDismiss_' + message.targetId)
}
// 触发刷新会话列表
uni.$emit('onReceiveMessage', message)
}
})

View File

@@ -0,0 +1,16 @@
// 监听群解散的消息,直接跳转到会话列表页面
const onGroupDismiss = {
onLoad(e) {
uni.$once('onGroupDismiss_' + e.targetId, () => {
uni.showToast({
icon: 'none',
title: '当前群已解散'
})
uni.switchTab({
url: '/pages/im/index'
})
})
}
}
export default onGroupDismiss