群聊的基础页面

This commit is contained in:
2022-02-10 10:22:43 +08:00
parent 699c178bd7
commit e2243bcc99
22 changed files with 940 additions and 421 deletions

View File

@@ -51,7 +51,7 @@ const setNotifyBadge = () => {
*/
const connect = (token, userInfo, callback) => {
RongIMLib.connect(token, res => {
callback(res)
callback(res)
// 更新个人信息
store.dispatch('setSenderInfo', userInfo)
// 设置未读消息数量
@@ -61,7 +61,7 @@ const connect = (token, userInfo, callback) => {
uni.getStorage({
key: FK,
success: () => {
success: () => {
const model = uni.model.friendModel
model.find((err, results) => {
results.map(item => {
@@ -193,7 +193,7 @@ const addListeners = () => {
}
// 维护消息列表,检查是否需要通知声音,设置新消息提醒的数量
const newMessage = (msg) => {
const newMessage = (msg) => {
RongIMLib.getConversationNotificationStatus(msg.conversationType, msg.targetId, ({
code,
status
@@ -204,10 +204,12 @@ const newMessage = (msg) => {
}
}
});
setNotifyBadge()
uni.$emit('onReceiveMessage', msg);
setNotifyBadge()
if (msg.conversationType === RongIMLib.ConversationType.PRIVATE) {
uni.$emit('onReceivePrivateMessage', msg);
} else {
uni.$emit('onReceiveGroupMessage', msg);
}
}
// 播放状态

View File

@@ -1,4 +1,5 @@
import store from '@/store/index.js'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
const getMessageList = (conversationType, targetId, timeStamp, count, isForward, callback) => {
@@ -47,24 +48,24 @@ const getMessageList = (conversationType, targetId, timeStamp, count, isForward,
* @param {string} content 消息内容
* @param {function} callback 回调函数
*/
const sentText = (conversationType, targetId, content, callback) => {
console.log('发送');
const sentText = (conversationType, targetId, content, user, callback) => {
const msg = {
conversationType: conversationType,
targetId: String(targetId),
content: {
objectName: 'RC:TxtMsg',
content: content,
user: store.getters.sender
userInfo: user
}
}
}
RongIMLib.sendMessage(msg, ({
code,
messageId
}) => {
if (code === 0) {
callback(messageId)
} else {
} else {
uni.showToast({
icon: 'none',
title: '发送失败'
@@ -81,14 +82,15 @@ const sentText = (conversationType, targetId, content, callback) => {
* @param {integer} time 录音时长
* @param {function} callback 录音时长
*/
const sentVoice = (conversationType, targetId, voiceUrl, time, callback) => {
const sentVoice = (conversationType, targetId, voiceUrl, time, user, callback) => {
const msg = {
conversationType: conversationType,
targetId: String(targetId),
content: {
objectName: 'RC:HQVCMsg',
local: 'file:///' + plus.io.convertLocalFileSystemURL(voiceUrl),
duration: time
duration: time,
userInfo: user
}
}
RongIMLib.sendMediaMessage(msg, {
@@ -107,13 +109,14 @@ const sentVoice = (conversationType, targetId, voiceUrl, time, callback) => {
})
}
const sentImage = (conversationType, targetId, imageUrl, callback) => {
const sentImage = (conversationType, targetId, imageUrl, user, callback) => {
const msg = {
conversationType: conversationType,
targetId: String(targetId),
content: {
objectName: 'RC:ImgMsg',
local: 'file:///' + plus.io.convertLocalFileSystemURL(imageUrl)
local: 'file:///' + plus.io.convertLocalFileSystemURL(imageUrl),
userInfo: user
}
}
RongIMLib.sendMediaMessage(msg, {

View File

@@ -0,0 +1,27 @@
[{
"latestMessage": {
"content": "你好,这是 725 条消息条消息条消息条消息条消息条消息条消息条消息条消息0.47447800 1644388415",
"objectName": "RC:TxtMsg",
"userInfo": {
"userId": "10051",
"name": "Jason.Chen",
"extra": "",
"portraitUrl": ""
}
},
"objectName": "RC:TxtMsg",
"receivedTime": 1644388414889,
"sentTime": 1644388415510,
"draft": "",
"conversationType": 3,
"receivedStatus": 0,
"conversationTitle": "",
"sentStatus": 30,
"mentionedCount": 0,
"latestMessageId": 98,
"isTop": false,
"senderUserId": "10005",
"unreadMessageCount": 3,
"hasUnreadMentioned": false,
"targetId": "TG001"
}]