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