2 const Promise = require('bluebird');
3 const vueRenderToString = require('../vue-ssr-renderer');
4 const restful = require('../../../services/restful');
5 const restSerializer = require('../../../serializers/rest-serializer');
6 const contextGenerator = require('../../../web/context-generator');
7 const generateUserThemeSnapshot = require('../../snapshots/user-theme-snapshot');
9 async function mixinHbsDataForVueLeftMenu(req, existingData) {
10 const user = req.user;
11 const userId = user && user.id;
13 const uriContext = req.uriContext;
14 const currentRoom = uriContext && uriContext.troupe;
18 serializedCurrentRoom,
23 ] = await Promise.all([
24 restSerializer.serializeObject(
26 new restSerializer.UserStrategy({ includeProviders: true })
28 restSerializer.serializeObject(currentRoom, new restSerializer.TroupeStrategy()),
29 restful.serializeGroupsForUserId(userId),
30 restful.serializeTroupesForUser(userId),
31 contextGenerator.generateTroupeContext(req),
32 generateUserThemeSnapshot(req)
35 const serializedRoomMap = {};
37 // the roomMap will contain the current room
38 if (serializedCurrentRoom) {
39 serializedRoomMap[serializedCurrentRoom.id] = serializedCurrentRoom;
42 serializedRooms.forEach(serializedRoom => {
43 serializedRoomMap[serializedRoom.id] = serializedRoom;
46 const isMobile = req.isPhone;
50 isLoggedIn: !!serializedUser,
52 darkTheme: userThemeSnapshot.theme === 'gitter-dark',
54 roomMap: serializedRoomMap,
55 displayedRoomId: serializedCurrentRoom && serializedCurrentRoom.id,
57 leftMenuPinnedState: !isMobile,
58 leftMenuExpandedState: false
61 const vueLeftMenuHtmlOutput = await vueRenderToString({
62 moduleToRender: 'left-menu',
66 const threadMessageFeedHtmlOutput = await vueRenderToString({
67 moduleToRender: 'thread-message-feed',
74 layout: 'chat-layout',
76 leftMenuHtml: vueLeftMenuHtmlOutput,
77 threadMessageFeedHtml: threadMessageFeedHtmlOutput,
81 ...(existingData.troupeContext || {}),
83 ...((existingData.troupeContext || {}).snapshots || {}),
84 allRooms: serializedRooms,
85 groups: serializedGroups
91 module.exports = mixinHbsDataForVueLeftMenu;