bigbluebutton-Github/bigbluebutton-html5/imports/api/group-chat-msg/server/methods/fetchMessagePerPage.js

23 lines
841 B
JavaScript
Raw Normal View History

2021-03-10 04:52:20 +08:00
import { Meteor } from 'meteor/meteor';
import GroupChat from '/imports/api/group-chat';
import { GroupChatMsg } from '/imports/api/group-chat-msg';
import Users from '/imports/api/users';
import { extractCredentials } from '/imports/api/common/server/helpers';
const CHAT_CONFIG = Meteor.settings.public.chat;
const ITENS_PER_PAGE = CHAT_CONFIG.itemsPerPage;
export default function fetchMessagePerPage(chatId, page) {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
const User = Users.findOne({ userId: requesterUserId, meetingId });
const messages = GroupChatMsg.find({ chatId, meetingId, timestamp: { $lt: User.authTokenValidatedTime } },
{
sort: { timestamp: 1 },
skip: page > 0 ? ((page - 1) * ITENS_PER_PAGE) : 0,
limit: ITENS_PER_PAGE,
})
.fetch();
return messages;
}