From d293ba4d44596d4e7a7eac89acad0c31b8671695 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 6 Jul 2017 09:43:55 +0200 Subject: [PATCH] add support for invite hashes --- www/common/common-hash.js | 18 +++++++++++++++++- www/common/cryptpad-common.js | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/www/common/common-hash.js b/www/common/common-hash.js index c4f452dc7..888c0a338 100644 --- a/www/common/common-hash.js +++ b/www/common/common-hash.js @@ -54,7 +54,7 @@ Version 1 if (!hash) { return; } var parsed = {}; var hashArr = fixDuplicateSlashes(hash).split('/'); - if (['media', 'file', 'user'].indexOf(type) === -1) { + if (['media', 'file', 'user', 'invite'].indexOf(type) === -1) { parsed.type = 'pad'; if (hash.slice(0,1) !== '/' && hash.length >= 56) { // Old hash @@ -93,6 +93,16 @@ Version 1 } return parsed; } + if (['invite'].indexOf(type) !== -1) { + parsed.type = 'invite'; + if (hashArr[1] && hashArr[1] === '1') { + parsed.version = 1; + parsed.channel = hashArr[2]; + parsed.pubkey = hashArr[3].replace(/-/g, '/'); + return parsed; + } + return parsed; + } return; }; var parsePadUrl = Hash.parsePadUrl = function (href) { @@ -320,5 +330,11 @@ Version 1 return hash; }; + Hash.createInviteUrl = function (curvePublic, channel) { + channel = channel || Hash.createChannelId(); + return window.location.origin + '/invite/#/1/' + channel + + '/' + curvePublic.replace(/\//g, '-') + '/'; + }; + return Hash; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index d3f081ef3..8b17db3d7 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -107,6 +107,7 @@ define([ common.findWeaker = Hash.findWeaker; common.findStronger = Hash.findStronger; common.serializeHash = Hash.serializeHash; + common.createInviteUrl = Hash.createInviteUrl; // Userlist common.createUserList = UserList.create;