38 lines
778 B
TypeScript
38 lines
778 B
TypeScript
import {
|
|
MESSAGE_TYPE_LOAD_MORE,
|
|
MESSAGE_TYPE_LOAD_NEXT_CHUNK,
|
|
MESSAGE_TYPE_LOAD_PREVIOUS_CHUNK
|
|
} from '../../../constants/messageTypeLoad';
|
|
import RocketChat from '../../../lib/rocketchat';
|
|
|
|
interface IGetMoreMessages {
|
|
rid: string;
|
|
t?: string;
|
|
tmid?: string;
|
|
loaderItem: {
|
|
t: string;
|
|
ts: Date;
|
|
};
|
|
}
|
|
|
|
const getMoreMessages = ({ rid, t, tmid, loaderItem }: IGetMoreMessages) => {
|
|
if ([MESSAGE_TYPE_LOAD_MORE, MESSAGE_TYPE_LOAD_PREVIOUS_CHUNK].includes(loaderItem.t)) {
|
|
return RocketChat.loadMessagesForRoom({
|
|
rid,
|
|
t,
|
|
latest: loaderItem.ts,
|
|
loaderItem
|
|
});
|
|
}
|
|
|
|
if (loaderItem.t === MESSAGE_TYPE_LOAD_NEXT_CHUNK) {
|
|
return RocketChat.loadNextMessages({
|
|
rid,
|
|
tmid,
|
|
ts: loaderItem.ts,
|
|
loaderItem
|
|
});
|
|
}
|
|
};
|
|
export default getMoreMessages;
|