mirror of
https://gitee.com/lijingbo-2021/open-anylink-web.git
synced 2025-12-30 11:02:25 +00:00
代码健壮性
This commit is contained in:
@@ -133,10 +133,10 @@ export const messageStore = defineStore('anyim-message', () => {
|
||||
msgRecordsList.value[sessionId] = {}
|
||||
}
|
||||
|
||||
// seq为undefined或者seq没有被缓存,才能add这条消息
|
||||
if (item.seq === undefined || !(item.seq in msgUniqueSeq.value)) {
|
||||
// seq没有或者seq没有被缓存,才能add这条消息
|
||||
if (!item.seq || !(item.seq in msgUniqueSeq.value)) {
|
||||
msgRecordsList.value[sessionId][item.msgId] = item
|
||||
if (item.seq !== undefined) {
|
||||
if (item.seq) {
|
||||
// seq不为空则添加至缓存
|
||||
msgUniqueSeq.value[item.seq] = item.msgId
|
||||
}
|
||||
@@ -155,7 +155,7 @@ export const messageStore = defineStore('anyim-message', () => {
|
||||
*/
|
||||
const removeMsgRecord = (sessionId, msgId) => {
|
||||
const msg = msgRecordsList.value[sessionId][msgId]
|
||||
if (msg === undefined) return
|
||||
if (!msg) return
|
||||
if (msg.seq in msgUniqueSeq.value) delete msgUniqueSeq.value[msg.seq]
|
||||
if (msgId in msgRecordsList.value[sessionId]) delete msgRecordsList.value[sessionId][msgId]
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ const msgIdSortArray = computed(() => {
|
||||
|
||||
// 缓存的消息列表是否为空,注意和hasNoMoreMsg的区别,前者为空可以再拉取
|
||||
const noMsgRecords = computed(() => {
|
||||
return msgIdSortArray.value.length === 0
|
||||
return msgIdSortArray.value?.length === 0
|
||||
})
|
||||
// 当前session的第一条消息ID
|
||||
const firstMsgId = computed(() => {
|
||||
@@ -111,8 +111,8 @@ const firstMsgId = computed(() => {
|
||||
// 当前session的最后一条消息ID
|
||||
const lastMsgId = computed(() => {
|
||||
if (!noMsgRecords.value) {
|
||||
const len = msgIdSortArray.value.length
|
||||
return msgIdSortArray.value[len - 1]
|
||||
const len = msgIdSortArray.value?.length
|
||||
return len ? msgIdSortArray.value[len - 1] : 0
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user