群邀请消息获取

This commit is contained in:
2022-02-22 14:59:53 +08:00
parent d812ac2862
commit 66092967cb
9 changed files with 163 additions and 126 deletions

View File

@@ -7,8 +7,7 @@
"moment": "^2.29.1", "moment": "^2.29.1",
"uni-read-pages": "^1.0.5", "uni-read-pages": "^1.0.5",
"uni-simple-router": "^2.0.7", "uni-simple-router": "^2.0.7",
"uview-ui": "^2.0.19", "uview-ui": "^2.0.27"
"vuex": "^3.6.2"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"

View File

@@ -2,7 +2,6 @@
<view class="sent--text"> <view class="sent--text">
<input class="input" type="text" :auto-blur="true" @focus="focus" @blur="blur" :focus="focusState" <input class="input" type="text" :auto-blur="true" @focus="focus" @blur="blur" :focus="focusState"
v-model="inputTxt" confirm-type="send" @confirm="sent" cursor-spacing="10" /> v-model="inputTxt" confirm-type="send" @confirm="sent" cursor-spacing="10" />
<!-- <button class="button" size="mini" :disabled="disabled" @click="demo">{{focusState ? '失焦': '聚焦'}}</button> -->
</view> </view>
</template> </template>
@@ -19,10 +18,6 @@
targetId: { targetId: {
type: String, type: String,
default: '' default: ''
},
inputTxt: {
type: String,
default: ''
} }
}, },
computed: { computed: {
@@ -33,7 +28,7 @@
return this.$store.getters.sender return this.$store.getters.sender
} }
}, },
created() { mounted() {
RongIMLib.getTextMessageDraft(this.conversationType, this.targetId, ({ RongIMLib.getTextMessageDraft(this.conversationType, this.targetId, ({
draft draft
}) => { }) => {
@@ -47,24 +42,19 @@
data() { data() {
return { return {
focusState: false, focusState: false,
inputTxt: ''
} }
}, },
methods: { methods: {
// 发送文本消息
sent() { sent() {
if (!this.disabled) { if (!this.disabled) {
RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId)
im.sentText(this.conversationType, this.targetId, this.inputTxt, this.sender, () => { im.sentText(this.conversationType, this.targetId, this.inputTxt, this.sender, () => {
RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId)
this.$emit('success') this.$emit('success')
this.inputTxt = '' this.inputTxt = ''
}) })
} }
}, },
demo() {
console.log(this.focusState)
this.focusState = !this.focusState
},
focus() { focus() {
this.$emit('focus') this.$emit('focus')
}, },

View File

@@ -1,8 +0,0 @@
<template>
</template>
<script>
</script>
<style>
</style>

View File

@@ -1,13 +1,21 @@
<template> <template>
<view class="msg--text"> <view class="msg--text">
<view class="state" v-if="!isGroup && !isRemote">
<!-- 已发送 -->
<u-icon name="checkbox-mark" class="sent" :color="message.sentStatus >= 30 ? '#34CE98' : '#999999' " />
<!-- 已阅读 -->
<u-icon name="checkbox-mark" class="receive" :color="message.sentStatus >= 50 ? '#34CE98' : '#999999' " />
</view>
<view class="">
<view class="name" v-if="isGroup && isRemote">{{ contact(message.senderUserId).name }}</view> <view class="name" v-if="isGroup && isRemote">{{ contact(message.senderUserId).name }}</view>
<view> <view @longpress="backMessage" :class="['text', isRemote ? 'left': 'right']">{{ content }}</view>
<text class="im--text" :class="isRemote ? 'left': 'right'">{{ content }}</text>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
export default { export default {
name: 'showText', name: 'showText',
props: { props: {
@@ -35,23 +43,63 @@
} }
} }
}, },
methods: {
// 撤回消息测试
backMessage() {
console.log('撤回消息');
const pushContent = '推送内容'
RongIMLib.recallMessage(this.message.messageId, pushContent,
({
code,
message
}) => {
console.error(code);
// 撤回消息成功
if (code === 0) {
console.error(message);
}
}
)
}
}
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.msg--text { .msg--text {
display: flex;
align-items: flex-end;
.state {
padding: 10rpx;
border-radius: 30rpx;
width: 40rpx;
background-color: #ddd;
display: flex;
margin-right: 10rpx;
.sent {
z-index: 2;
}
.receive {
z-index: 1;
margin-left: -20rpx;
}
}
.name { .name {
font-size: 24rpx; font-size: 24rpx;
color: $text-gray-m; color: $text-gray-m;
} }
.im--text { .text {
max-width: 508rpx; box-sizing: border-box;
max-width: 502rpx;
padding: 20rpx; padding: 20rpx;
line-height: 46rpx; line-height: 46rpx;
font-size: 32rpx; font-size: 32rpx;
color: $text-color; color: $text-color;
display: inline-block;
word-break: break-all; word-break: break-all;
&.left { &.left {

View File

@@ -77,7 +77,6 @@
this.targetId = e.targetId this.targetId = e.targetId
// 获取群成员数量 // 获取群成员数量
getGroupBase(this.targetId).then(res => { getGroupBase(this.targetId).then(res => {
console.log(res);
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title: res.name + `(${res.members})` title: res.name + `(${res.members})`
}) })
@@ -90,6 +89,11 @@
this.getNewMessage() this.getNewMessage()
} }
}) })
uni.$on('onReceiptRequested', (msg) => {
if (msg.targetId == this.targetId) {
console.log('群聊消息是否已读', msg);
}
})
// 清理聊天记录 // 清理聊天记录
uni.$once('cleanGroupMessage', this.getMessageList) uni.$once('cleanGroupMessage', this.getMessageList)
}, },
@@ -138,14 +142,32 @@
this.scrollBottom() this.scrollBottom()
}) })
}, },
// 发送已读回执
sendReadReceiptResponse(messages) {
const msgs = messages.map((item) => {
if (item.receivedStatus == 0) {
return {
conversationType: 3,
targetId: this.targetId,
messageId: item.messageId,
messageDirection: item.messageDirection,
objectName: item.objectName
}
}
}).filter(Boolean)
if (msgs.length) {
console.error('发送群聊已读回执', msgs);
RongIMLib.sendReadReceiptResponse(3, this.targetId, msgs, (res) => {
console.error('发送群聊已读回执成功', res);
})
}
},
// 滚动到底部 // 滚动到底部
scrollBottom(type) { scrollBottom(type) {
if (this.latestMessage) { if (this.latestMessage) {
// 清理当前会话,未读消息数量 // 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
.sentTime) .sentTime)
// // 发送消息已读状态给对方
// RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
// 更新badge提醒数量 // 更新badge提醒数量
im.setNotifyBadge() im.setNotifyBadge()
} }
@@ -175,7 +197,7 @@
justify-content: flex-end; justify-content: flex-end;
.cell { .cell {
padding: 10rpx 30rpx; padding: 10rpx 20rpx;
.time { .time {
text-align: center; text-align: center;
@@ -185,7 +207,7 @@
.cell-item { .cell-item {
display: flex; display: flex;
width: 690rpx; width: 710rpx;
justify-content: flex-start; justify-content: flex-start;
&.left { &.left {
@@ -203,20 +225,6 @@
.msg { .msg {
margin: 0 20rpx; margin: 0 20rpx;
.state {
padding-top: 10rpx;
.state-text {
font-size: $title-size-m - 2;
color: rgba($color: $main-color, $alpha: 0.3)
}
.state-text-active {
font-size: $title-size-m - 2;
color: #cecece;
}
}
} }
} }

View File

@@ -172,7 +172,7 @@
justify-content: flex-end; justify-content: flex-end;
.cell { .cell {
padding: 10rpx 30rpx; padding: 10rpx 20rpx;
.time { .time {
text-align: center; text-align: center;
@@ -183,7 +183,7 @@
.cell-item { .cell-item {
display: flex; display: flex;
width: 690rpx; width: 710rpx;
justify-content: flex-start; justify-content: flex-start;
&.left { &.left {
@@ -200,19 +200,6 @@
.msg { .msg {
margin: 0 20rpx; margin: 0 20rpx;
// .state {
// padding-top: 10rpx;
// .state-text {
// font-size: $title-size-m - 2;
// color: rgba($color: $main-color, $alpha: 0.3)
// }
// .state-text-active {
// font-size: $title-size-m - 2;
// color: #cecece;
// }
// }
} }
} }

View File

@@ -41,7 +41,7 @@ const notifyMsgTypes = [
const imLibListeners = () => { const imLibListeners = () => {
// 添加连接状态监听函数 // 添加连接状态监听函数
IMLib.addConnectionStatusListener((res) => { IMLib.addConnectionStatusListener((res) => {
console.log('连接状态监听', res.data.status) console.error('连接状态监听', res.data.status)
uni.$emit('onConnectionStatusChange', res.data.status) uni.$emit('onConnectionStatusChange', res.data.status)
}) })
// 添加消息监听函数 // 添加消息监听函数
@@ -85,13 +85,28 @@ const imLibListeners = () => {
uni.$emit('onReceiveMessage', message) uni.$emit('onReceiveMessage', message)
} }
}) })
// 监听私聊消息已读回执
// 监听消息回执
IMLib.addReadReceiptReceivedListener(({ IMLib.addReadReceiptReceivedListener(({
data data
}) => { }) => {
console.error("监听私聊消息已读回执: ", data);
uni.$emit('onReadReceiptReceived', data) uni.$emit('onReadReceiptReceived', data)
}) })
// 监听消息撤回操作
IMLib.addRecallMessageListener((res) => {
console.error("消息撤回: ", res);
})
// 监听需要群聊消息回执
IMLib.addReceiptRequestListener(({
data
}) => {
console.error('onReceiptRequested', data);
uni.$emit('onReceiptRequested', data)
})
// 群消息已读的回执
IMLib.addReceiptResponseListener((res) => {
console.error('addReceiptResponseListener', res);
})
} }
const callLibListeners = () => { const callLibListeners = () => {
@@ -100,7 +115,7 @@ const callLibListeners = () => {
CallLib.onCallReceived(({ CallLib.onCallReceived(({
data data
}) => { }) => {
console.log('onCallReceived'); console.error('onCallReceived');
uni.navigateTo({ uni.navigateTo({
url: '/pages/im/private/call?targetId=' + data.targetId + '&mediaType=' + url: '/pages/im/private/call?targetId=' + data.targetId + '&mediaType=' +
data.mediaType data.mediaType
@@ -112,27 +127,27 @@ const callLibListeners = () => {
}) })
// 外呼 // 外呼
CallLib.onCallOutgoing((res) => { CallLib.onCallOutgoing((res) => {
console.log('onCallOutgoing', res); console.error('onCallOutgoing', res);
uni.$emit('onCallOutgoing') uni.$emit('onCallOutgoing')
}) })
// 远端响铃 // 远端响铃
CallLib.onRemoteUserRinging((res) => { CallLib.onRemoteUserRinging((res) => {
console.log('onRemoteUserRinging', res); console.error('onRemoteUserRinging', res);
uni.$emit('onRemoteUserRinging') uni.$emit('onRemoteUserRinging')
}) })
// 远端加入 // 远端加入
CallLib.onRemoteUserJoined((res) => { CallLib.onRemoteUserJoined((res) => {
console.log('远端接听'); console.error('远端接听');
uni.$emit('onRemoteUserJoined') uni.$emit('onRemoteUserJoined')
}) })
// 断开链接 // 断开链接
CallLib.onCallDisconnected((res) => { CallLib.onCallDisconnected((res) => {
console.log('断开链接', res) console.error('断开链接', res)
uni.$emit('onCallDisconnected') uni.$emit('onCallDisconnected')
}) })
// 远端挂断 // 远端挂断
CallLib.onRemoteUserLeft((res) => { CallLib.onRemoteUserLeft((res) => {
console.log('远端离开', res) console.error('远端离开', res)
uni.$emit('onRemoteUserLeft') uni.$emit('onRemoteUserLeft')
}) })
} }

View File

@@ -60,18 +60,16 @@ const getPendingList = (callback, total) => {
// 群组申请列表,邀请列表 // 群组申请列表,邀请列表
const getGroupPendinglist = (targetId, callback) => { const getGroupPendinglist = (targetId, callback) => {
let total = 1000 const conversationType = RongIMLib.ConversationType.SYSTEM
RongIMLib.getConversationList([RongIMLib.ConversationType.SYSTEM], total, 0, (res) => { const objectNames = ['RC:ContactNtf']
if (res.code === 0) {
const pendings = res.conversations.filter((item) => {
return item.targetId == targetId &&
item.objectName == RongIMLib.ObjectName.ContactNotification &&
item.latestMessage.operation === 'GroupPending'
})
callback(pendings) RongIMLib.getHistoryMessagesByTimestamp(conversationType, targetId, objectNames, 0, 1000, true,
({
messages
}) => {
callback(messages)
} }
}) )
} }
/** /**
@@ -97,6 +95,11 @@ const sentText = (conversationType, targetId, content, user, callback) => {
messageId messageId
}) => { }) => {
if (code === 0) { if (code === 0) {
if (conversationType == 3) {
RongIMLib.sendReadReceiptRequest(messageId, (res) => {
console.log('发送回执请求', res);
})
}
callback(messageId) callback(messageId)
} else { } else {
console.log('发送失败', msg); console.log('发送失败', msg);

View File

@@ -2,27 +2,22 @@
# yarn lockfile v1 # yarn lockfile v1
"moment@^2.29.1": moment@^2.29.1:
"integrity" "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==" version "2.29.1"
"resolved" "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz" resolved "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz"
"version" "2.29.1" integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
"uni-read-pages@^1.0.5": uni-read-pages@^1.0.5:
"integrity" "sha512-GkrrZ0LX0vn9R5k6RKEi0Ez3Q3e2vUpjXQ8Z6/K/d28KudI9ajqgt8WEjQFlG5EPm1K6uTArN8LlqmZTEixDUA==" version "1.0.5"
"resolved" "https://registry.npmjs.org/uni-read-pages/-/uni-read-pages-1.0.5.tgz" resolved "https://registry.npmjs.org/uni-read-pages/-/uni-read-pages-1.0.5.tgz"
"version" "1.0.5" integrity sha512-GkrrZ0LX0vn9R5k6RKEi0Ez3Q3e2vUpjXQ8Z6/K/d28KudI9ajqgt8WEjQFlG5EPm1K6uTArN8LlqmZTEixDUA==
"uni-simple-router@^2.0.7": uni-simple-router@^2.0.7:
"integrity" "sha512-8FKv5dw7Eoonm0gkO8udprrxzin0fNUI0+AvIphFkFRH5ZmP5ZWJ2pvnWzb2NiiqQSECTSU5VSB7HhvOSwD5eA==" version "2.0.7"
"resolved" "https://registry.npmjs.org/uni-simple-router/-/uni-simple-router-2.0.7.tgz" resolved "https://registry.npmjs.org/uni-simple-router/-/uni-simple-router-2.0.7.tgz"
"version" "2.0.7" integrity sha512-8FKv5dw7Eoonm0gkO8udprrxzin0fNUI0+AvIphFkFRH5ZmP5ZWJ2pvnWzb2NiiqQSECTSU5VSB7HhvOSwD5eA==
"uview-ui@^2.0.19": uview-ui@^2.0.27:
"integrity" "sha512-ddZiaP7R9wsUxMzAuhuXgh5OswgCm2lKuulTqjnRXFr0uUWsgL1iBifU3GbOwpwP0LtTHKJOo9rYv1LP0WXmzA==" version "2.0.27"
"resolved" "https://registry.npmjs.org/uview-ui/-/uview-ui-2.0.19.tgz" resolved "https://registry.yarnpkg.com/uview-ui/-/uview-ui-2.0.27.tgz#1a7dde9c6246e851d768f3efd44b5fb26774a2e1"
"version" "2.0.19" integrity sha512-fl35rlguNPfXnwNoVv0w4zS1blFFxxSPuGR1+9SbpFGC33aiTBaoFWs/4Fppj0foS/kDCqSWcJiymNmQjPBD4g==
"vuex@^3.6.2":
"integrity" "sha512-ETW44IqCgBpVomy520DT5jf8n0zoCac+sxWnn+hMe/CzaSejb/eVw2YToiXYX+Ex/AuHHia28vWTq4goAexFbw=="
"resolved" "https://registry.npmjs.org/vuex/-/vuex-3.6.2.tgz"
"version" "3.6.2"