From d6b6b8f11f358dd9059516816d6f8d4f6bb4f693 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 2 Sep 2019 17:42:30 +0200 Subject: [PATCH] Store the pad to the drive when accepting ownership --- www/common/common-ui-elements.js | 20 ++++++++++++++++++++ www/common/sframe-common-outer.js | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index b37d71355..4f7373a7f 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -3068,6 +3068,7 @@ define([ }; var storePopupState = false; + var autoStoreModal = {}; UIElements.displayStorePadPopup = function (common, data) { if (storePopupState) { return; } storePopupState = true; @@ -3087,6 +3088,8 @@ define([ var initialHide = data && data.autoStore && data.autoStore === -1; var modal = UI.cornerPopup(text, actions, footer, {hidden: initialHide}); + autoStoreModal[priv.channel] = modal; + $(modal.popup).find('.cp-corner-footer a').click(function (e) { e.preventDefault(); common.openURL('/settings/'); @@ -3094,6 +3097,7 @@ define([ $(hide).click(function () { UIElements.displayCrowdfunding(common); + delete autoStoreModal[priv.channel]; modal.delete(); }); var waitingForStoringCb = false; @@ -3109,6 +3113,7 @@ define([ } return void UI.warn(Messages.autostore_error); } + delete autoStoreModal[priv.channel]; modal.delete(); UIElements.displayCrowdfunding(common); UI.log(Messages.autostore_saved); @@ -3350,6 +3355,21 @@ define([ // Send notification to the sender answer(true); + var data = JSON.parse(JSON.stringify(msg.content)); + data.metadata = res; + + // Add the pad to your drive + sframeChan.query('Q_ACCEPT_OWNERSHIP', data, function (err, res) { + if (err || (res && res.error)) { + return void console.error(err | res.error); + } + UI.log(Messages.saved); + if (autoStoreModal[data.channel]) { + autoStoreModal[data.channel].delete(); + delete autoStoreModal[data.channel]; + } + }); + // Remove yourself from the pending owners sframeChan.query('Q_SET_PAD_METADATA', { channel: msg.content.channel, diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index cc568553a..a8a00cd0b 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -476,6 +476,21 @@ define([ }); }); + sframeChan.on('Q_ACCEPT_OWNERSHIP', function (data, cb) { + var data = { + password: data.password, + href: data.href, + channel: data.channel, + title: data.title, + owners: data.metadata.owners, + expire: data.metadata.expire, + forceSave: true + }; + Cryptpad.setPadTitle(data, function (err) { + cb({error: err}); + }); + }); + sframeChan.on('Q_IMPORT_MEDIATAG', function (obj, cb) { var key = obj.key; var channel = obj.channel;