群邀请消息获取

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

@@ -2,7 +2,6 @@
<view class="sent--text">
<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" />
<!-- <button class="button" size="mini" :disabled="disabled" @click="demo">{{focusState ? '失焦': '聚焦'}}</button> -->
</view>
</template>
@@ -19,10 +18,6 @@
targetId: {
type: String,
default: ''
},
inputTxt: {
type: String,
default: ''
}
},
computed: {
@@ -33,7 +28,7 @@
return this.$store.getters.sender
}
},
created() {
mounted() {
RongIMLib.getTextMessageDraft(this.conversationType, this.targetId, ({
draft
}) => {
@@ -46,25 +41,20 @@
},
data() {
return {
focusState: false,
focusState: false,
inputTxt: ''
}
},
methods: {
// 发送文本消息
sent() {
if (!this.disabled) {
RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId)
im.sentText(this.conversationType, this.targetId, this.inputTxt, this.sender, () => {
if (!this.disabled) {
im.sentText(this.conversationType, this.targetId, this.inputTxt, this.sender, () => {
RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId)
this.$emit('success')
this.inputTxt = ''
this.inputTxt = ''
})
}
},
demo() {
console.log(this.focusState)
this.focusState = !this.focusState
},
focus() {
this.$emit('focus')
},

View File

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

View File

@@ -1,13 +1,21 @@
<template>
<view class="msg--text">
<view class="name" v-if="isGroup && isRemote">{{ contact(message.senderUserId).name }}</view>
<view>
<text class="im--text" :class="isRemote ? 'left': 'right'">{{ content }}</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 @longpress="backMessage" :class="['text', isRemote ? 'left': 'right']">{{ content }}</view>
</view>
</view>
</template>
<script>
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
export default {
name: 'showText',
props: {
@@ -21,37 +29,77 @@
type: Boolean,
default: false
}
},
computed: {
isRemote() {
return this.message.messageDirection == 2
},
content() {
return this.message.content.content
},
contact() {
return function(targetId) {
return this.$store.getters.contactInfo(targetId)
}
}
},
computed: {
isRemote() {
return this.message.messageDirection == 2
},
content() {
return this.message.content.content
},
contact() {
return function(targetId) {
return this.$store.getters.contactInfo(targetId)
}
}
},
methods: {
// 撤回消息测试
backMessage() {
console.log('撤回消息');
const pushContent = '推送内容'
RongIMLib.recallMessage(this.message.messageId, pushContent,
({
code,
message
}) => {
console.error(code);
// 撤回消息成功
if (code === 0) {
console.error(message);
}
}
)
}
}
}
</script>
<style scoped lang="scss">
.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 {
font-size: 24rpx;
color: $text-gray-m;
}
.im--text {
max-width: 508rpx;
.text {
box-sizing: border-box;
max-width: 502rpx;
padding: 20rpx;
line-height: 46rpx;
font-size: 32rpx;
color: $text-color;
display: inline-block;
word-break: break-all;
&.left {

View File

@@ -77,7 +77,6 @@
this.targetId = e.targetId
// 获取群成员数量
getGroupBase(this.targetId).then(res => {
console.log(res);
uni.setNavigationBarTitle({
title: res.name + `(${res.members})`
})
@@ -90,6 +89,11 @@
this.getNewMessage()
}
})
uni.$on('onReceiptRequested', (msg) => {
if (msg.targetId == this.targetId) {
console.log('群聊消息是否已读', msg);
}
})
// 清理聊天记录
uni.$once('cleanGroupMessage', this.getMessageList)
},
@@ -138,14 +142,32 @@
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) {
if (this.latestMessage) {
// 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
.sentTime)
// // 发送消息已读状态给对方
// RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
// 更新badge提醒数量
im.setNotifyBadge()
}
@@ -175,7 +197,7 @@
justify-content: flex-end;
.cell {
padding: 10rpx 30rpx;
padding: 10rpx 20rpx;
.time {
text-align: center;
@@ -183,9 +205,9 @@
color: #666;
}
.cell-item {
.cell-item {
display: flex;
width: 690rpx;
width: 710rpx;
justify-content: flex-start;
&.left {
@@ -203,20 +225,6 @@
.msg {
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;
.cell {
padding: 10rpx 30rpx;
padding: 10rpx 20rpx;
.time {
text-align: center;
@@ -183,7 +183,7 @@
.cell-item {
display: flex;
width: 690rpx;
width: 710rpx;
justify-content: flex-start;
&.left {
@@ -200,19 +200,6 @@
.msg {
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;
// }
// }
}
}