2 const fixMongoIdQueryParam = require('../../../web/fix-mongo-id-query-param');
3 const unreadItemService = require('gitter-web-unread-items');
5 /* How many chats to send back */
6 const INITIAL_CHAT_COUNT = 50;
8 const getPermalinkMessageId = request => fixMongoIdQueryParam(request.query.at);
10 /* which messages and how many of them should be fetched */
11 const getChatSnapshotOptions = async (userId, troupeId, req) => {
12 // It's ok if there's no user (logged out), unreadItems will be 0
13 const unreadItems = await unreadItemService.getUnreadItemsForUser(userId, troupeId);
16 unreadItems.chat.length > INITIAL_CHAT_COUNT
17 ? unreadItems.chat.length + 20
22 aroundId: getPermalinkMessageId(req),
23 // inline-threads-for-mobile-embedded
24 includeThreads: false // the server side page rendering is never used for native mobile clients
28 module.exports = getChatSnapshotOptions;