Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-im
提交
9876e87e
U
uni-im
项目概览
DCloud
/
uni-im
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-im
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9876e87e
编写于
4月 25, 2024
作者:
DCloud_JSON
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新 统一用conversation.getCached获取本地会话
上级
fe02bc90
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
54 addition
and
51 deletion
+54
-51
components/uni-im-msg/popup-control.vue
components/uni-im-msg/popup-control.vue
+1
-1
components/uni-im-msg/uni-im-msg.vue
components/uni-im-msg/uni-im-msg.vue
+6
-3
sdk/ext/MsgManager.class.js
sdk/ext/MsgManager.class.js
+1
-1
sdk/init/getCloudMsg.js
sdk/init/getCloudMsg.js
+44
-44
sdk/methods/conversation/index.js
sdk/methods/conversation/index.js
+2
-2
未找到文件。
components/uni-im-msg/popup-control.vue
浏览文件 @
9876e87e
...
@@ -286,7 +286,7 @@
...
@@ -286,7 +286,7 @@
let
isGroupAdmin
=
false
let
isGroupAdmin
=
false
if
(
group_id
){
if
(
group_id
){
let
conversation
=
uniIm
.
conversation
.
dataList
.
find
(
i
=>
i
.
id
==
conversation_id
)
let
conversation
=
uniIm
.
conversation
.
getCached
(
conversation_id
)
isGroupAdmin
=
conversation
.
group_info
.
user_id
==
current_uid
isGroupAdmin
=
conversation
.
group_info
.
user_id
==
current_uid
}
}
// console.log('isGroupAdmin',isGroupAdmin);
// console.log('isGroupAdmin',isGroupAdmin);
...
...
components/uni-im-msg/uni-im-msg.vue
浏览文件 @
9876e87e
...
@@ -191,7 +191,7 @@
...
@@ -191,7 +191,7 @@
},
},
computed
:
{
computed
:
{
currentConversation
()
{
currentConversation
()
{
return
uniIm
.
conversation
.
dataList
.
find
(
conversation
=>
conversation
.
id
==
this
.
msg
.
conversation_id
)
return
uniIm
.
conversation
.
getCached
(
this
.
msg
.
conversation_id
)
},
},
friendlyTime
()
{
friendlyTime
()
{
let
time
=
this
.
msg
.
create_time
||
this
.
msg
.
client_create_time
let
time
=
this
.
msg
.
create_time
||
this
.
msg
.
client_create_time
...
@@ -222,8 +222,11 @@
...
@@ -222,8 +222,11 @@
}
}
},
},
isFromAdmin
()
{
isFromAdmin
()
{
const
conversation
=
uniIm
.
conversation
.
dataList
.
find
(
conversation
=>
conversation
.
id
==
this
.
msg
.
conversation_id
)
const
{
return
conversation
.
group_id
&&
conversation
.
group_member
[
this
.
msg
.
from_uid
]?.
role
?.
includes
(
'
admin
'
)
group_id
,
from_uid
}
=
this
.
msg
return
group_id
&&
this
.
currentConversation
.
group_member
[
from_uid
]?.
role
?.
includes
(
'
admin
'
)
},
},
mineId
()
{
mineId
()
{
return
uniCloud
.
getCurrentUserInfo
().
uid
return
uniCloud
.
getCurrentUserInfo
().
uid
...
...
sdk/ext/MsgManager.class.js
浏览文件 @
9876e87e
...
@@ -301,7 +301,7 @@ export default class Message {
...
@@ -301,7 +301,7 @@ export default class Message {
if
(
!
Array
.
isArray
(
datas
))
{
if
(
!
Array
.
isArray
(
datas
))
{
datas
=
[
datas
]
datas
=
[
datas
]
}
}
let
_currentConversation
=
$state
.
conversation
.
dataList
.
find
(
item
=>
item
.
id
==
this
.
conversation_id
)
let
_currentConversation
=
$state
.
conversation
.
getCached
(
this
.
conversation_id
)
// 隐藏的会话,收到消息后需要再次显示出来
// 隐藏的会话,收到消息后需要再次显示出来
if
(
_currentConversation
.
hidden
){
if
(
_currentConversation
.
hidden
){
_currentConversation
.
hidden
=
false
_currentConversation
.
hidden
=
false
...
...
sdk/init/getCloudMsg.js
浏览文件 @
9876e87e
import
$state
from
'
@/uni_modules/uni-im/sdk/state/index.js
'
;
import
$state
from
'
@/uni_modules/uni-im/sdk/state/index.js
'
;
const
uniImCo
=
uniCloud
.
importObject
(
"
uni-im-co
"
,
{
const
uniImCo
=
uniCloud
.
importObject
(
"
uni-im-co
"
,
{
customUI
:
false
customUI
:
false
})
})
const
dbJQL
=
uniCloud
.
databaseForJQL
();
const
dbJQL
=
uniCloud
.
databaseForJQL
();
// 获得云端数据,适用于:socket突然断开丢失,或者应用iOS切到后台拿不到透传等场景使用 获取丢失的数据
// 获得云端数据,适用于:socket突然断开丢失,或者应用iOS切到后台拿不到透传等场景使用 获取丢失的数据
let
getCloudMsgIng
=
false
let
getCloudMsgIng
=
false
...
@@ -41,14 +41,14 @@ function getCloudMsg({
...
@@ -41,14 +41,14 @@ function getCloudMsg({
async
function
getConversationList
()
{
async
function
getConversationList
()
{
// 根据本地会话的最大更新时间,查询云端数据
// 根据本地会话的最大更新时间,查询云端数据
let
maxConversation
=
([...
$state
.
conversation
.
dataList
].
sort
((
a
,
b
)
=>
b
.
update_time
-
a
.
update_time
))[
0
]
let
maxConversation
=
([...
$state
.
conversation
.
dataList
].
sort
((
a
,
b
)
=>
b
.
update_time
-
a
.
update_time
))[
0
]
console
.
log
(
'
maxConversation:
'
+
maxConversation
)
console
.
log
(
'
maxConversation:
'
+
maxConversation
)
if
(
!
maxConversation
)
{
if
(
!
maxConversation
)
{
getCloudMsgIng
=
false
getCloudMsgIng
=
false
return
return
}
}
let
minUpdateTime
=
maxConversation
.
update_time
let
minUpdateTime
=
maxConversation
.
update_time
console
.
log
(
'
minUpdateTime
'
,
minUpdateTime
);
console
.
log
(
'
minUpdateTime
'
,
minUpdateTime
);
let
{
data
:
conversationDatas
}
=
await
uniImCo
.
getConversationList
({
let
{
data
:
conversationDatas
}
=
await
uniImCo
.
getConversationList
({
...
@@ -59,7 +59,7 @@ function getCloudMsg({
...
@@ -59,7 +59,7 @@ function getCloudMsg({
conversationDatas
.
forEach
(
newConversationInfo
=>
{
conversationDatas
.
forEach
(
newConversationInfo
=>
{
// console.error('newConversationInfo',newConversationInfo)
// console.error('newConversationInfo',newConversationInfo)
// 判断是否已经存在
// 判断是否已经存在
let
conversation
=
$state
.
conversation
.
dataList
.
find
(
item
=>
item
.
id
===
newConversationInfo
.
id
)
let
conversation
=
$state
.
conversation
.
getCached
(
newConversationInfo
.
id
)
if
(
conversation
)
{
if
(
conversation
)
{
// 更新本地会话数据
// 更新本地会话数据
Object
.
assign
(
conversation
,
newConversationInfo
)
Object
.
assign
(
conversation
,
newConversationInfo
)
...
@@ -86,7 +86,7 @@ function getCloudMsg({
...
@@ -86,7 +86,7 @@ function getCloudMsg({
if
(
conversationDatas
.
length
===
30
)
{
if
(
conversationDatas
.
length
===
30
)
{
console
.
error
(
"
可能存在下一页数据
"
);
console
.
error
(
"
可能存在下一页数据
"
);
return
await
getConversationList
()
return
await
getConversationList
()
}
}
console
.
error
(
`更新会话:
${
conversationDatas
.
length
}
`
)
console
.
error
(
`更新会话:
${
conversationDatas
.
length
}
`
)
}
}
getCloudMsgIng
=
false
getCloudMsgIng
=
false
...
@@ -104,11 +104,11 @@ function getCloudMsg({
...
@@ -104,11 +104,11 @@ function getCloudMsg({
export
default
getCloudMsg
export
default
getCloudMsg
async
function
seaveMsgs
(
msgs
)
{
async
function
seaveMsgs
(
msgs
)
{
if
(
msgs
.
length
===
0
)
{
if
(
msgs
.
length
===
0
)
{
return
return
}
}
const
conversation
=
$state
.
conversation
.
dataList
.
find
(
item
=>
item
.
id
===
msgs
[
0
].
conversation_id
)
const
conversation
=
$state
.
conversation
.
getCached
(
msgs
[
0
].
conversation_id
)
msgs
.
sort
((
a
,
b
)
=>
a
.
update_time
-
b
.
update_time
)
msgs
.
sort
((
a
,
b
)
=>
a
.
update_time
-
b
.
update_time
)
msgs
.
forEach
(
async
msg
=>
{
msgs
.
forEach
(
async
msg
=>
{
// 判断是否出现重复
// 判断是否出现重复
...
@@ -137,38 +137,38 @@ async function seaveMsgs(msgs) {
...
@@ -137,38 +137,38 @@ async function seaveMsgs(msgs) {
}
}
}
}
})
})
}
}
async
function
getConversationMsgs
({
async
function
getConversationMsgs
({
limit
=
100
,
limit
=
100
,
conversation
,
conversation
,
minUpdateTime
=
0
minUpdateTime
=
0
}){
}){
// console.error('getConversationMsgs minUpdateTime',minUpdateTime);
// console.error('getConversationMsgs minUpdateTime',minUpdateTime);
// 按会话查
// 按会话查
const
conversation_id
=
conversation
.
id
const
conversation_id
=
conversation
.
id
let
res
=
await
dbJQL
.
collection
(
'
uni-im-msg
'
).
where
({
let
res
=
await
dbJQL
.
collection
(
'
uni-im-msg
'
).
where
({
conversation_id
,
conversation_id
,
"
update_time
"
:
dbJQL
.
command
.
gt
(
minUpdateTime
),
"
update_time
"
:
dbJQL
.
command
.
gt
(
minUpdateTime
),
})
})
.
orderBy
(
'
update_time
'
,
'
asc
'
)
.
orderBy
(
'
update_time
'
,
'
asc
'
)
.
limit
(
limit
)
.
limit
(
limit
)
.
get
()
.
get
()
console
.
log
(
'
查询到新msg数据
'
,
res
,
res
.
data
.
length
);
console
.
log
(
'
查询到新msg数据
'
,
res
,
res
.
data
.
length
);
seaveMsgs
(
res
.
data
)
seaveMsgs
(
res
.
data
)
// 递推查询
// 递推查询
if
(
res
.
data
.
length
===
limit
)
{
if
(
res
.
data
.
length
===
limit
)
{
arguments
[
0
].
minUpdateTime
=
res
.
data
[
limit
-
1
].
update_time
arguments
[
0
].
minUpdateTime
=
res
.
data
[
limit
-
1
].
update_time
await
getConversationMsgs
(
arguments
[
0
])
await
getConversationMsgs
(
arguments
[
0
])
}
}
}
}
// async function getMsgList({
// async function getMsgList({
// minUpdateTime = 0,
// minUpdateTime = 0,
// conversation_ids
// conversation_ids
// }) {
// }) {
// const limit = 1000
// const limit = 1000
// console.log('minUpdateTime', minUpdateTime);
// console.log('minUpdateTime', minUpdateTime);
// console.log('conversation_ids', conversation_ids);
// console.log('conversation_ids', conversation_ids);
// let res = await uniImCo.getMsgList({
// let res = await uniImCo.getMsgList({
// conversation_ids,
// conversation_ids,
...
@@ -194,7 +194,7 @@ async function getConversationMsgs({
...
@@ -194,7 +194,7 @@ async function getConversationMsgs({
// }
// }
// if (res.data.length === limit) {
// if (res.data.length === limit) {
// minUpdateTime = res.data[limit - 1].update_time
// minUpdateTime = res.data[limit - 1].update_time
// let res2 = await getMsgList(arguments[0])
// let res2 = await getMsgList(arguments[0])
// res.data = res.data.concat(res2.data)
// res.data = res.data.concat(res2.data)
// return res
// return res
...
...
sdk/methods/conversation/index.js
浏览文件 @
9876e87e
...
@@ -199,7 +199,7 @@ export default {
...
@@ -199,7 +199,7 @@ export default {
return
datas
.
reduce
((
resList
,
item
,
index
)
=>
{
return
datas
.
reduce
((
resList
,
item
,
index
)
=>
{
// console.log('resList',resList);
// console.log('resList',resList);
// 判断是否存在,再新增。
// 判断是否存在,再新增。
let
conversation_item
=
$state
.
conversation
.
dataList
.
find
(
conversation
=>
conversation
.
id
==
item
.
id
)
let
conversation_item
=
$state
.
conversation
.
getCached
(
item
.
id
)
if
(
conversation_item
)
{
if
(
conversation_item
)
{
// 此会话已经存在,返回给add方法调用者,不重复插到$state.conversation.dataList
// 此会话已经存在,返回给add方法调用者,不重复插到$state.conversation.dataList
resList
.
push
(
conversation_item
)
resList
.
push
(
conversation_item
)
...
@@ -216,7 +216,7 @@ export default {
...
@@ -216,7 +216,7 @@ export default {
$state
.
conversation
.
dataList
.
push
(
conversation
)
$state
.
conversation
.
dataList
.
push
(
conversation
)
// 拿到响应式的conversation对象
// 拿到响应式的conversation对象
const
_conversation
=
$state
.
conversation
.
dataList
.
find
(
i
=>
i
.
id
===
conversation
.
id
)
const
_conversation
=
$state
.
conversation
.
getCached
(
conversation
.
id
)
// 设置字段为响应式
// 设置字段为响应式
let
activeProperty
=
_conversation
.
activeProperty
()
let
activeProperty
=
_conversation
.
activeProperty
()
Object
.
keys
(
activeProperty
).
forEach
(
key
=>
{
Object
.
keys
(
activeProperty
).
forEach
(
key
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录