Add notifications when removed from owners or pending_owners

pull/1/head
yflory 5 years ago
parent d190b8acd0
commit 4708d59a65

@ -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));

@ -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 <b>{1}</b>'; // XXX
Messages.owner_removedPending = '{0} has removed your pending ownership of <b>{1}</b>'; // 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 {

@ -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) {
/**

@ -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});
});
});

Loading…
Cancel
Save