Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / shared / templates / get-header-view-options.js
blob089779a9b0fe7d11b4513543efc06245cf3d7276
1 'use strict';
3 const { getBackendForRoom } = require('gitter-web-shared/backend-utils');
5 function getHeaderLinkUrl(serializedTroupe) {
6 const backend = getBackendForRoom(serializedTroupe);
7 if (!backend) return;
9 switch (backend.type) {
10 case 'GL_GROUP':
11 case 'GL_PROJECT':
12 case 'GL_USER':
13 return 'https://gitlab.com/' + backend.linkPath;
14 case 'GH_REPO':
15 case 'GH_ORG':
16 case 'GH_USER':
17 return 'https://github.com/' + backend.linkPath;
20 return;
23 function isTroupeAdmin(serializedTroupe) {
24 return serializedTroupe.permissions && serializedTroupe.permissions.admin;
27 function getHeaderViewOptions(serializedTroupe) {
28 var group = serializedTroupe.group;
29 var groupUri = group && group.uri;
30 var groupPageUrl = groupUri && '/orgs/' + groupUri + '/rooms';
32 return {
33 url: serializedTroupe.url,
34 oneToOne: serializedTroupe.oneToOne,
35 troupeName: serializedTroupe.name,
36 favourite: serializedTroupe.favourite,
37 premium: serializedTroupe.premium,
38 isPrivate: !serializedTroupe.public,
39 troupeTopic: serializedTroupe.topic,
40 isAdmin: isTroupeAdmin(serializedTroupe),
41 avatarUrl: serializedTroupe.avatarUrl,
42 group: group,
43 groupPageUrl: groupPageUrl,
44 headerLink: getHeaderLinkUrl(serializedTroupe)
48 module.exports = getHeaderViewOptions;