Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / shared / chat / generate-permalink.js
blob0d49b5a3fc270833c983fa4e9bac294e08346426
1 'use strict';
3 const moment = require('moment');
4 const urlJoin = require('url-join');
5 const clientEnv = require('gitter-client-env');
7 /*
8 * Generates absolute URL representing permanent link to a chat item
10 * troupeUri - URL segment identifying room (usually community-name/room-name)
11 * id - message id
12 * sent - date when the message was sent, accepted formats: JavaScript Date, moment
13 * isArchive - if true, generated link will point to room archive,
14 * otherwise link points to normal chat
16 module.exports = (troupeUri, id, sent = null, isArchive = false) => {
17 const basePath = clientEnv['basePath'];
18 if (isArchive) {
19 const urlDate = moment(sent).format('YYYY/MM/DD');
20 return urlJoin(basePath, troupeUri, 'archives', urlDate, `?at=${id}`);
22 return urlJoin(basePath, troupeUri, `?at=${id}`);