diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index a8ea163b7..4e576d35a 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -203,25 +203,53 @@ define([ if (ed === edPublic) { me = true; } return ed; }).filter(function (x) { return x; }); - // Send the command - var send = function () { + NThen(function (waitFor) { + var msg = me ? + "Are you sure? You're going to give up on your rights, this can't be undone!" : + "Are you sure?"; // XXX + UI.confirm(msg, waitFor(function (yes) { + if (!yes) { + waitFor.abort(); + return; + } + })); + }).nThen(function (waitFor) { + // Send the command sframeChan.query('Q_SET_PAD_METADATA', { channel: channel, command: pending ? 'RM_PENDING_OWNERS' : 'RM_OWNERS', value: toRemove - }, function (err, res) { + }, waitFor(function (err, res) { err = err || (res && res.error); - if (err) { return void UI.warn('ERROR' + err); } // XXX - redrawAll(); + if (err) { + waitFor.abort(); + return void UI.warn('ERROR' + err); + } // XXX UI.log('DONE'); // XXX + })); + }).nThen(function (waitFor) { + sel.forEach(function (el) { + var friend = friends[$(el).attr('data-curve')]; + if (!friend) { return; } + common.mailbox.sendTo("RM_OWNER", { + channel: channel, + title: data.title, + pending: pending, + user: { + displayName: user.name, + avatar: user.avatar, + profile: user.profile, + notifications: user.notifications, + curvePublic: user.curvePublic, + edPublic: priv.edPublic + } + }, { + channel: friend.notifications, + curvePublic: friend.curvePublic + }, waitFor()); }); - }; - var msg = me ? - "Are you sure? You're going to give up on your rights, this can't be undone!" : - "Are you sure?"; // XXX - UI.confirm(msg, function (yes) { - if (!yes) { return; } - send(); + }).nThen(function () { + redrawAll(); }); }); $div.append(h('p', removeButton)); diff --git a/www/common/notifications.js b/www/common/notifications.js index b06e8e3fc..ef64c303a 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -252,6 +252,24 @@ define([ } }; + handlers['RM_OWNER'] = function (common, data) { + var content = data.content; + var msg = content.msg; + + // Display the notification + var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous; + var title = Util.fixHTML(msg.content.title); + Messages.owner_removed = '{0} has removed your ownership of {1}'; // XXX + Messages.owner_removedPending = '{0} has removed your pending ownership of {1}'; // XXX + var key = 'owner_removed' + (msg.content.pending ? 'Pending' : ''); + content.getFormatText = function () { + return Messages._getKey(key, [name, title]); + }; + if (!content.archived) { + content.dismissHandler = defaultDismiss(common, data); + } + }; + // NOTE: don't forget to fixHTML everything returned by "getFormatText" return { diff --git a/www/common/outer/mailbox-handlers.js b/www/common/outer/mailbox-handlers.js index bc2d0b9ff..aa65d6cfd 100644 --- a/www/common/outer/mailbox-handlers.js +++ b/www/common/outer/mailbox-handlers.js @@ -267,7 +267,6 @@ define([ handlers['ADD_OWNER'] = function (ctx, box, data, cb) { var msg = data.msg; var content = msg.content; -console.log(msg); if (msg.author !== content.user.curvePublic) { return void cb(true); } if (!content.href || !content.title || !content.channel) { @@ -278,7 +277,10 @@ console.log(msg); var channel = content.channel; if (addOwners[channel]) { return void cb(true); } - addOwners[channel] = true; + addOwners[channel] = { + type: box.type, + hash: data.hash + }; cb(false); }; @@ -289,6 +291,24 @@ console.log(msg); } }; + handlers['RM_OWNER'] = function (ctx, box, data, cb) { + var msg = data.msg; + var content = msg.content; + + if (msg.author !== content.user.curvePublic) { return void cb(true); } + if (!content.channel) { + console.log('Remove invalid notification'); + return void cb(true); + } + + var channel = content.channel; + + if (addOwners[channel] && content.pending) { + return void cb(false, addOwners[channel]); + } + cb(false); + }; + return { add: function (ctx, box, data, cb) { /** diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index a8a00cd0b..2a03392be 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -477,7 +477,7 @@ define([ }); sframeChan.on('Q_ACCEPT_OWNERSHIP', function (data, cb) { - var data = { + var _data = { password: data.password, href: data.href, channel: data.channel, @@ -486,7 +486,7 @@ define([ expire: data.metadata.expire, forceSave: true }; - Cryptpad.setPadTitle(data, function (err) { + Cryptpad.setPadTitle(_data, function (err) { cb({error: err}); }); });