From e4020ba8d4e9c8427f8e7dd3454f68cee4de711a Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 21 Aug 2017 14:41:56 +0200 Subject: [PATCH] Fix pad creation in pad2 --- www/common/cryptpad-common.js | 10 ++++++---- www/common/sframe-common-title.js | 2 +- www/pad2/outer.js | 10 +++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 0d41543d9..2066c739a 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1803,13 +1803,15 @@ define([ return $userAdmin; }; - common.getShareHashes = function (cb) { + common.getShareHashes = function (secret, cb) { + if (!window.location.hash) { + var hashes = common.getHashes(secret.channel, secret); + return void cb(null, hashes); + } common.getRecentPads(function (err, recent) { var parsed = parsePadUrl(window.location.href); if (!parsed.type || !parsed.hashData) { return void cb('E_INVALID_HREF'); } - var secret = common.getSecrets(parsed.type, parsed.hash); - var channel = common.base64ToHex(parsed.hashData.channel); - var hashes = common.getHashes(channel, secret); + var hashes = common.getHashes(secret.channel, secret); var options = []; // If we have a stronger version in drive, add it and add a redirect button diff --git a/www/common/sframe-common-title.js b/www/common/sframe-common-title.js index fd632f296..20f5052ea 100644 --- a/www/common/sframe-common-title.js +++ b/www/common/sframe-common-title.js @@ -6,7 +6,7 @@ define(['jquery'], function ($) { exp.defaultTitle = Common.getDefaultTitle(); - exp.title = document.title; // TOOD slides + exp.title = document.title; cfg = cfg || {}; diff --git a/www/pad2/outer.js b/www/pad2/outer.js index bd47490f3..6755ef20d 100644 --- a/www/pad2/outer.js +++ b/www/pad2/outer.js @@ -22,6 +22,7 @@ define([ console.log('xxx'); var sframeChan; var hashes; + var secret; nThen(function (waitFor) { $(waitFor()); }).nThen(function (waitFor) { @@ -31,12 +32,15 @@ define([ })); Cryptpad.ready(waitFor()); }).nThen(function (waitFor) { - Cryptpad.getShareHashes(waitFor(function (err, h) { hashes = h; })); + secret = Cryptpad.getSecrets(); + if (!secret.channel) { + // New pad: create a new random channel id + secret.channel = Cryptpad.createChannelId(); + } + Cryptpad.getShareHashes(secret, waitFor(function (err, h) { hashes = h; })); }).nThen(function (waitFor) { - var secret = Cryptpad.getSecrets(); var readOnly = secret.keys && !secret.keys.editKeyStr; if (!secret.keys) { secret.keys = secret.key; } - var parsed = Cryptpad.parsePadUrl(window.location.href); parsed.type = parsed.type.replace('pad2', 'pad'); if (!parsed.type) { throw new Error(); }