From f883fb7e04191da5b1610f2a28eede81d1ce6c3c Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 12 Dec 2018 13:48:28 +0100 Subject: [PATCH] Preserve chat and cursor channel when importing a template --- www/common/common-ui-elements.js | 8 +++++++- www/common/cryptpad-common.js | 10 ++++++++-- www/common/sframe-common-outer.js | 8 +++++--- www/common/sframe-common.js | 5 +++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 391efc60d..714d40a84 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -1916,7 +1916,13 @@ define([ onSelect: function (data) { if (data.type === type && first) { UI.addLoadingScreen({hideTips: true}); - sframeChan.query('Q_TEMPLATE_USE', data.href, function () { + var chatChan = common.getPadChat(); + var cursorChan = common.getCursorChannel(); + sframeChan.query('Q_TEMPLATE_USE', { + href: data.href, + chat: chatChan, + cursor: cursorChan + }, function () { first = false; UI.removeLoadingScreen(); Feedback.send('TEMPLATE_USED'); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 44bf9cdd3..0e2b7c62a 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -493,9 +493,10 @@ define([ }); }; - common.useTemplate = function (href, Crypt, cb, optsPut) { + common.useTemplate = function (data, Crypt, cb, optsPut) { // opts is used to overrides options for chainpad-netflux in cryptput // it allows us to add owners and expiration time if it is a new file + var href = data.href; var parsed = Hash.parsePadUrl(href); var parsed2 = Hash.parsePadUrl(window.location.href); @@ -531,8 +532,13 @@ define([ } if (typeof(meta) === "object") { meta.defaultTitle = meta.title || meta.defaultTitle; - delete meta.users; meta.title = ""; + delete meta.users; + delete meta.chat2; + delete meta.chat; + delete meta.cursor; + if (data.chat) { meta.chat2 = data.chat; } + if (data.cursor) { meta.cursor = data.cursor; } } val = JSON.stringify(parsed); } catch (e) { diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index b2536acdd..1a528435b 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -647,8 +647,8 @@ define([ initFilePicker(data); }); - sframeChan.on('Q_TEMPLATE_USE', function (href, cb) { - Cryptpad.useTemplate(href, Cryptget, cb); + sframeChan.on('Q_TEMPLATE_USE', function (data, cb) { + Cryptpad.useTemplate(data, Cryptget, cb); }); sframeChan.on('Q_TEMPLATE_EXIST', function (type, cb) { Cryptpad.listTemplates(type, function (err, templates) { @@ -953,7 +953,9 @@ define([ // we need to have the owners and expiration time in the first line on the // server var cryptputCfg = $.extend(true, {}, rtConfig, {password: password}); - Cryptpad.useTemplate(data.template, Cryptget, function () { + Cryptpad.useTemplate({ + href: data.template + }, Cryptget, function () { startRealtime(); cb(); }, cryptputCfg); diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 3c5d47c52..da2e4caa6 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -168,12 +168,15 @@ define([ // Chat var padChatChannel; + // common-ui-elements needs to be able to get the chat channel to put it in metadata when + // importing a template funcs.getPadChat = function () { return padChatChannel; }; funcs.openPadChat = function (saveChanges) { var md = JSON.parse(JSON.stringify(ctx.metadataMgr.getMetadata())); //if (md.chat) { delete md.chat; } // Old channel without signing key + // NOTE: "chat2" is also used in cryptpad-common's "useTemplate" var channel = md.chat2 || Hash.createChannelId(); if (!md.chat2) { md.chat2 = channel; @@ -187,6 +190,8 @@ define([ }; var cursorChannel; + // common-ui-elements needs to be able to get the cursor channel to put it in metadata when + // importing a template funcs.getCursorChannel = function () { return cursorChannel; };