From 3de6377ad792e4a1966e2f02553e0fda55c4008d Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 2 Jun 2020 14:21:23 +0200 Subject: [PATCH] Better UX when transfering ownership to yourself --- www/common/inner/access.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/www/common/inner/access.js b/www/common/inner/access.js index b2705208f..55a4dbbe9 100644 --- a/www/common/inner/access.js +++ b/www/common/inner/access.js @@ -205,10 +205,14 @@ define([ var $sel = $div.find('.cp-usergrid-user.cp-selected'); var sel = $sel.toArray(); if (!sel.length) { return; } + var addMe = false; var toAdd = sel.map(function (el) { var curve = $(el).attr('data-curve'); - // If the pad is woned by a team, we can transfer ownership to ourselves - if (curve === user.curvePublic && teamOwner) { return priv.edPublic; } + // If the pad is owned by a team, we can transfer ownership to ourselves + if (curve === user.curvePublic && teamOwner) { + addMe = true; + return; + } var friend = friends[curve]; if (!friend) { return; } return friend.edPublic; @@ -282,10 +286,31 @@ define([ } })); } + }).nThen(function (waitFor) { + // Offer ownership to a friend + if (addMe) { + // Send the command + sframeChan.query('Q_SET_PAD_METADATA', { + channel: channel, + command: 'ADD_OWNERS', + value: [priv.edPublic], + teamId: teamOwner + }, waitFor(function (err, res) { + err = err || (res && res.error); + if (err) { + waitFor.abort(); + redrawAll(true); + var text = err === "INSUFFICIENT_PERMISSIONS" ? Messages.fm_forbidden + : Messages.error; + return void UI.warn(text); + } + })); + } }).nThen(function (waitFor) { sel.forEach(function (el) { var curve = $(el).attr('data-curve'); - var friend = curve === user.curvePublic ? user : friends[curve]; + if (curve === user.curvePublic) { return; } + var friend = friends[curve]; if (!friend) { return; } common.mailbox.sendTo("ADD_OWNER", { channel: channel,