|
|
@ -9,7 +9,7 @@ import type {
|
|
|
|
import _uniqBy from 'lodash/uniqBy';
|
|
|
|
import _uniqBy from 'lodash/uniqBy';
|
|
|
|
import _orderBy from 'lodash/orderBy';
|
|
|
|
import _orderBy from 'lodash/orderBy';
|
|
|
|
import _last from 'lodash/last';
|
|
|
|
import _last from 'lodash/last';
|
|
|
|
import { isValidStr } from '../../utils/string-helper';
|
|
|
|
import { isLocalMessageId, isValidStr } from '../../utils/string-helper';
|
|
|
|
import type { InboxItem } from '../../model/inbox';
|
|
|
|
import type { InboxItem } from '../../model/inbox';
|
|
|
|
|
|
|
|
|
|
|
|
export interface ChatConverseState extends ChatConverseInfo {
|
|
|
|
export interface ChatConverseState extends ChatConverseInfo {
|
|
|
@ -85,6 +85,7 @@ const chatSlice = createSlice({
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NOTICE: 按照该规则能确保本地消息一直在最后,因为l大于任何ObjectId
|
|
|
|
const newMessages = _orderBy(
|
|
|
|
const newMessages = _orderBy(
|
|
|
|
_uniqBy([...state.converses[converseId].messages, ...messages], '_id'),
|
|
|
|
_uniqBy([...state.converses[converseId].messages, ...messages], '_id'),
|
|
|
|
'_id',
|
|
|
|
'_id',
|
|
|
@ -93,10 +94,16 @@ const chatSlice = createSlice({
|
|
|
|
|
|
|
|
|
|
|
|
state.converses[converseId].messages = newMessages;
|
|
|
|
state.converses[converseId].messages = newMessages;
|
|
|
|
|
|
|
|
|
|
|
|
if (state.currentConverseId !== converseId) {
|
|
|
|
const lastMessageId = _last(
|
|
|
|
const lastMessageId = _last(newMessages)?._id;
|
|
|
|
newMessages.filter((m) => !isLocalMessageId(m._id))
|
|
|
|
if (isValidStr(lastMessageId)) {
|
|
|
|
)?._id;
|
|
|
|
state.lastMessageMap[converseId] = lastMessageId;
|
|
|
|
|
|
|
|
|
|
|
|
if (isValidStr(lastMessageId)) {
|
|
|
|
|
|
|
|
state.lastMessageMap[converseId] = lastMessageId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.currentConverseId === converseId) {
|
|
|
|
|
|
|
|
// 如果是当前会话,则立即已读
|
|
|
|
|
|
|
|
state.ack[converseId] = lastMessageId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|