2022-03-03 20:25:03 +00:00
|
|
|
import { SubscriptionType, TAnyMessageModel } from '../../../definitions';
|
2022-03-02 14:18:01 +00:00
|
|
|
import loadMessagesForRoom from '../../../lib/methods/loadMessagesForRoom';
|
|
|
|
import loadNextMessages from '../../../lib/methods/loadNextMessages';
|
2022-03-03 20:25:03 +00:00
|
|
|
import { MessageTypeLoad } from '../../../constants/messageTypeLoad';
|
2022-03-02 14:18:01 +00:00
|
|
|
|
|
|
|
const getMoreMessages = ({
|
|
|
|
rid,
|
|
|
|
t,
|
|
|
|
tmid,
|
|
|
|
loaderItem
|
|
|
|
}: {
|
|
|
|
rid: string;
|
|
|
|
t: SubscriptionType;
|
|
|
|
tmid?: string;
|
|
|
|
loaderItem: TAnyMessageModel;
|
|
|
|
}): Promise<void> => {
|
2022-03-03 20:25:03 +00:00
|
|
|
if ([MessageTypeLoad.MORE, MessageTypeLoad.PREVIOUS_CHUNK].includes(loaderItem.t as MessageTypeLoad)) {
|
2022-03-02 14:18:01 +00:00
|
|
|
return loadMessagesForRoom({
|
|
|
|
rid,
|
|
|
|
t: t as any,
|
|
|
|
latest: loaderItem.ts as Date,
|
|
|
|
loaderItem
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-03 20:25:03 +00:00
|
|
|
if (loaderItem.t === MessageTypeLoad.NEXT_CHUNK) {
|
2022-03-02 14:18:01 +00:00
|
|
|
return loadNextMessages({
|
|
|
|
rid,
|
|
|
|
tmid,
|
|
|
|
ts: loaderItem.ts as Date,
|
|
|
|
loaderItem
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return Promise.resolve();
|
|
|
|
};
|
|
|
|
export default getMoreMessages;
|