Accept and decline ownership offers
This commit is contained in:
parent
c76363e765
commit
e131661673
@ -427,7 +427,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: row;
|
flex-flow: row;
|
||||||
|
|
||||||
.cp-share-column {
|
& > .cp-share-column {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
}
|
}
|
||||||
|
|||||||
3
rpc.js
3
rpc.js
@ -367,7 +367,8 @@ var setMetadata = function (Env, data, unsafeKey, cb) {
|
|||||||
metadata.owners.indexOf(unsafeKey) === -1) {
|
metadata.owners.indexOf(unsafeKey) === -1) {
|
||||||
|
|
||||||
// If you are a pending owner, make sure you can only add yourelf as an owner
|
// If you are a pending owner, make sure you can only add yourelf as an owner
|
||||||
if (command !== 'ADD_OWNERS' || !Array.isArray(data.value)
|
if ((command !== 'ADD_OWNERS' && command !== 'RM_PENDING_OWNERS')
|
||||||
|
|| !Array.isArray(data.value)
|
||||||
|| data.value.length !== 1
|
|| data.value.length !== 1
|
||||||
|| data.value[0] !== unsafeKey) {
|
|| data.value[0] !== unsafeKey) {
|
||||||
g();
|
g();
|
||||||
|
|||||||
@ -107,11 +107,12 @@ define([
|
|||||||
common.getPadAttribute('tags', waitFor(function (err, val) {
|
common.getPadAttribute('tags', waitFor(function (err, val) {
|
||||||
data.tags = val;
|
data.tags = val;
|
||||||
}));
|
}));
|
||||||
common.getSframeChannel().query('Q_GET_PAD_METADATA', null, waitFor(function (err, val) {
|
common.getPadMetadata(null, waitFor(function (obj) {
|
||||||
if (err) { return; }
|
console.log(obj);
|
||||||
data.owners = val.owners;
|
if (obj && obj.error) { return; }
|
||||||
data.expire = val.expire;
|
data.owners = obj.owners;
|
||||||
data.pending_owners = val.pending_owners;
|
data.expire = obj.expire;
|
||||||
|
data.pending_owners = obj.pending_owners;
|
||||||
}));
|
}));
|
||||||
/*
|
/*
|
||||||
common.getPadAttribute('owners', waitFor(function (err, val) {
|
common.getPadAttribute('owners', waitFor(function (err, val) {
|
||||||
@ -132,14 +133,20 @@ define([
|
|||||||
var edPublic = priv.edPublic;
|
var edPublic = priv.edPublic;
|
||||||
var channel = data.channel;
|
var channel = data.channel;
|
||||||
var owners = data.owners;
|
var owners = data.owners;
|
||||||
|
var pending_owners = data.pending_owners;
|
||||||
|
|
||||||
var $div1, $div2;
|
|
||||||
var redrawAll = function () {};
|
var redrawAll = function () {};
|
||||||
|
|
||||||
|
var div1 = h('div.cp-share-friends.cp-share-column');
|
||||||
|
var div2 = h('div.cp-share-friends.cp-share-column');
|
||||||
|
var $div1 = $(div1);
|
||||||
|
var $div2 = $(div2);
|
||||||
|
|
||||||
// Remove owner column
|
// Remove owner column
|
||||||
var drawRemove = function () {
|
var drawRemove = function (pending) {
|
||||||
var _owners = {};
|
var _owners = {};
|
||||||
owners.forEach(function (ed) {
|
var o = pending ? pending_owners : owners;
|
||||||
|
o.forEach(function (ed) {
|
||||||
var f;
|
var f;
|
||||||
Object.keys(friends).some(function (c) {
|
Object.keys(friends).some(function (c) {
|
||||||
if (friends[c].edPublic === ed) {
|
if (friends[c].edPublic === ed) {
|
||||||
@ -153,17 +160,19 @@ define([
|
|||||||
edPublic: ed,
|
edPublic: ed,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
var removeCol = UIElements.getFriendsList('Remove an existing owner instantly', {
|
var msg = pending ? 'Remove a pending owner:'
|
||||||
|
: 'Remove an existing owner:'; // XXX
|
||||||
|
var removeCol = UIElements.getFriendsList(msg, {
|
||||||
common: common,
|
common: common,
|
||||||
friends: _owners,
|
friends: _owners,
|
||||||
noFilter: true
|
noFilter: true
|
||||||
}, function () {
|
}, function () {
|
||||||
console.log(arguments);
|
console.log(arguments);
|
||||||
});
|
});
|
||||||
$div1 = $(removeCol.div);
|
var $div = $(removeCol.div);
|
||||||
var others1 = removeCol.others;
|
var others1 = removeCol.others;
|
||||||
$div1.append(h('div.cp-share-grid', others1));
|
$div.append(h('div.cp-share-grid', others1));
|
||||||
$div1.find('.cp-share-friend').click(function () {
|
$div.find('.cp-share-friend').click(function () {
|
||||||
var sel = $(this).hasClass('cp-selected');
|
var sel = $(this).hasClass('cp-selected');
|
||||||
if (!sel) {
|
if (!sel) {
|
||||||
$(this).addClass('cp-selected');
|
$(this).addClass('cp-selected');
|
||||||
@ -175,10 +184,11 @@ define([
|
|||||||
});
|
});
|
||||||
// When clicking on the remove button, we check the selected users.
|
// When clicking on the remove button, we check the selected users.
|
||||||
// If you try to remove yourself, we'll display an additional warning message
|
// If you try to remove yourself, we'll display an additional warning message
|
||||||
var removeButton = h('button.no-margin', 'Remove owners'); // XXX
|
var btnMsg = pending ? 'Remove pending owners' : 'Remove owners'; // XXX
|
||||||
|
var removeButton = h('button.no-margin', btnMsg);
|
||||||
$(removeButton).click(function () {
|
$(removeButton).click(function () {
|
||||||
// Check selection
|
// Check selection
|
||||||
var $sel = $div1.find('.cp-share-friend.cp-selected');
|
var $sel = $div.find('.cp-share-friend.cp-selected');
|
||||||
var sel = $sel.toArray();
|
var sel = $sel.toArray();
|
||||||
var me = false;
|
var me = false;
|
||||||
var toRemove = sel.map(function (el) {
|
var toRemove = sel.map(function (el) {
|
||||||
@ -191,12 +201,11 @@ define([
|
|||||||
var send = function () {
|
var send = function () {
|
||||||
sframeChan.query('Q_SET_PAD_METADATA', {
|
sframeChan.query('Q_SET_PAD_METADATA', {
|
||||||
channel: channel,
|
channel: channel,
|
||||||
command: 'RM_OWNERS',
|
command: pending ? 'RM_PENDING_OWNERS' : 'RM_OWNERS',
|
||||||
value: toRemove
|
value: toRemove
|
||||||
}, function (err, res) {
|
}, function (err, res) {
|
||||||
err = err || (res && res.error);
|
err = err || (res && res.error);
|
||||||
if (err) { return void UI.warn('ERROR' + err); } // XXX
|
if (err) { return void UI.warn('ERROR' + err); } // XXX
|
||||||
owners = res.owners;
|
|
||||||
redrawAll();
|
redrawAll();
|
||||||
UI.log('DONE'); // XXX
|
UI.log('DONE'); // XXX
|
||||||
});
|
});
|
||||||
@ -209,8 +218,8 @@ define([
|
|||||||
send();
|
send();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$div1.append(h('p', removeButton));
|
$div.append(h('p', removeButton));
|
||||||
return $div1;
|
return $div;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add owners column
|
// Add owners column
|
||||||
@ -261,20 +270,22 @@ define([
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
|
console.log('koko');
|
||||||
// Send the command
|
// Send the command
|
||||||
sframeChan.query('Q_SET_PAD_METADATA', {
|
sframeChan.query('Q_SET_PAD_METADATA', {
|
||||||
channel: channel,
|
channel: channel,
|
||||||
command: 'ADD_PENDING_OWNERS',
|
command: 'ADD_PENDING_OWNERS',
|
||||||
value: toAdd
|
value: toAdd
|
||||||
}, waitFor(function (err, res) {
|
}, waitFor(function (err, res) {
|
||||||
|
console.error(arguments);
|
||||||
err = err || (res && res.error);
|
err = err || (res && res.error);
|
||||||
if (err) {
|
if (err) {
|
||||||
waitFor.abort();
|
waitFor.abort();
|
||||||
return void UI.warn('ERROR' + err);
|
return void UI.warn('ERROR' + err);
|
||||||
} // XXX
|
} // XXX
|
||||||
owners = res.owners;
|
|
||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
|
console.log('okok');
|
||||||
// TODO send notifications
|
// TODO send notifications
|
||||||
sel.forEach(function (el) {
|
sel.forEach(function (el) {
|
||||||
var friend = friends[$(el).attr('data-curve')];
|
var friend = friends[$(el).attr('data-curve')];
|
||||||
@ -307,18 +318,26 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
redrawAll = function () {
|
redrawAll = function () {
|
||||||
var $d1 = $div1;
|
$div1.empty();
|
||||||
var $d2 = $div2;
|
$div2.empty();
|
||||||
drawRemove().insertBefore($d1);
|
common.getPadMetadata(null, function (obj) {
|
||||||
$d1.remove();
|
if (obj && obj.error) { return; }
|
||||||
drawAdd().insertBefore($d2);
|
owners = obj.owners;
|
||||||
$d2.remove();
|
pending_owners = obj.pending_owners;
|
||||||
|
$div1.append(drawRemove(false)).append(drawRemove(true));
|
||||||
|
$div2.append(drawAdd());
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$div1.append(drawRemove(false)).append(drawRemove(true));
|
||||||
|
$div2.append(drawAdd());
|
||||||
|
|
||||||
// Create modal
|
// Create modal
|
||||||
var link = h('div.cp-share-columns', [
|
var link = h('div.cp-share-columns', [
|
||||||
drawRemove()[0],
|
div1,
|
||||||
drawAdd()[0]
|
div2
|
||||||
|
/*drawRemove()[0],
|
||||||
|
drawAdd()[0]*/
|
||||||
]);
|
]);
|
||||||
var linkButtons = [{
|
var linkButtons = [{
|
||||||
className: 'cancel',
|
className: 'cancel',
|
||||||
@ -3260,8 +3279,10 @@ define([
|
|||||||
|
|
||||||
UIElements.displayAddOwnerModal = function (common, data) {
|
UIElements.displayAddOwnerModal = function (common, data) {
|
||||||
var priv = common.getMetadataMgr().getPrivateData();
|
var priv = common.getMetadataMgr().getPrivateData();
|
||||||
|
var user = common.getMetadataMgr().getUserData();
|
||||||
var sframeChan = common.getSframeChannel();
|
var sframeChan = common.getSframeChannel();
|
||||||
var msg = data.content.msg;
|
var msg = data.content.msg;
|
||||||
|
|
||||||
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
||||||
var title = Util.fixHTML(msg.content.title);
|
var title = Util.fixHTML(msg.content.title);
|
||||||
|
|
||||||
@ -3274,8 +3295,8 @@ define([
|
|||||||
$(link).click(function (e) {
|
$(link).click(function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (data.content.password) {
|
if (msg.content.password) {
|
||||||
common.sessionStorage.put('newPadPassword', data.content.password, function () {
|
common.sessionStorage.put('newPadPassword', msg.content.password, function () {
|
||||||
common.openURL(msg.content.href);
|
common.openURL(msg.content.href);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -3288,23 +3309,76 @@ define([
|
|||||||
link
|
link
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
var answer = function (yes) {
|
||||||
|
common.mailbox.sendTo("ADD_OWNER_ANSWER", {
|
||||||
|
channel: msg.content.channel,
|
||||||
|
href: msg.content.href,
|
||||||
|
password: msg.content.password,
|
||||||
|
title: msg.content.title,
|
||||||
|
answer: yes,
|
||||||
|
user: {
|
||||||
|
displayName: user.name,
|
||||||
|
avatar: user.avatar,
|
||||||
|
profile: user.profile,
|
||||||
|
notifications: user.notifications,
|
||||||
|
curvePublic: user.curvePublic,
|
||||||
|
edPublic: priv.edPublic
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
channel: msg.content.user.notifications,
|
||||||
|
curvePublic: msg.content.user.curvePublic
|
||||||
|
});
|
||||||
|
common.mailbox.dismiss(data, function (err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var todo = function (yes) {
|
var todo = function (yes) {
|
||||||
if (yes) {
|
if (yes) {
|
||||||
|
// ACCEPT
|
||||||
sframeChan.query('Q_SET_PAD_METADATA', {
|
sframeChan.query('Q_SET_PAD_METADATA', {
|
||||||
channel: data.content.channel,
|
channel: msg.content.channel,
|
||||||
command: 'ADD_OWNERS',
|
command: 'ADD_OWNERS',
|
||||||
value: [priv.edPublic]
|
value: [priv.edPublic]
|
||||||
}, function (err, res) {
|
}, function (err, res) {
|
||||||
err = err || (res && res.error);
|
err = err || (res && res.error);
|
||||||
if (err) {
|
if (err) {
|
||||||
return void UI.warn('ERROR' + err);
|
return void UI.warn('ERROR ' + err);
|
||||||
} // XXX
|
} // XXX
|
||||||
UI.log('DONE'); // XXX
|
UI.log('DONE'); // XXX
|
||||||
// TODO send notification to the sender?
|
|
||||||
|
// Send notification to the sender
|
||||||
|
answer(true);
|
||||||
|
|
||||||
|
// Remove yourself from the pending owners
|
||||||
|
sframeChan.query('Q_SET_PAD_METADATA', {
|
||||||
|
channel: msg.content.channel,
|
||||||
|
command: 'RM_PENDING_OWNERS',
|
||||||
|
value: [priv.edPublic]
|
||||||
|
}, function (err, res) {
|
||||||
|
err = err || (res && res.error);
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// XXX implement decline?
|
|
||||||
|
// DECLINE
|
||||||
|
// Remove yourself from the pending owners
|
||||||
|
sframeChan.query('Q_SET_PAD_METADATA', {
|
||||||
|
channel: msg.content.channel,
|
||||||
|
command: 'RM_PENDING_OWNERS',
|
||||||
|
value: [priv.edPublic]
|
||||||
|
}, function (err, res) {
|
||||||
|
err = err || (res && res.error);
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
// Send notification to the sender
|
||||||
|
answer(false);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var buttons = [{
|
var buttons = [{
|
||||||
|
|||||||
@ -216,12 +216,15 @@ define([
|
|||||||
var msg = content.msg;
|
var msg = content.msg;
|
||||||
|
|
||||||
// Display the notification
|
// Display the notification
|
||||||
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
||||||
|
var title = Util.fixHTML(msg.content.title);
|
||||||
|
Messages.owner_request = '{0} wants you to be an owner of <b>{1}</b>'; // XXX
|
||||||
content.getFormatText = function () {
|
content.getFormatText = function () {
|
||||||
return Messages._getKey('friendRequest_notification', [name]);
|
return Messages._getKey('owner_request', [name, title]);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check authenticity
|
// Check authenticity
|
||||||
if (msg.author !== msg.content.curvePublic) { return; }
|
if (msg.author !== msg.content.user.curvePublic) { return; }
|
||||||
|
|
||||||
// if not archived, add handlers
|
// if not archived, add handlers
|
||||||
if (!content.archived) {
|
if (!content.archived) {
|
||||||
@ -231,6 +234,24 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handlers['ADD_OWNER_ANSWER'] = 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_request_accepted = '{0} has accepted your offer to be an owner of <b>{1}</b>'; // XXX
|
||||||
|
Messages.owner_request_declined = '{0} has declined your offer to be an owner of <b>{1}</b>'; // XXX
|
||||||
|
var key = 'owner_request_' + (msg.content.answer ? 'accepted' : 'declined');
|
||||||
|
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"
|
// NOTE: don't forget to fixHTML everything returned by "getFormatText"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1397,6 +1397,7 @@ define([
|
|||||||
cb(channel.data || {});
|
cb(channel.data || {});
|
||||||
};
|
};
|
||||||
Store.setPadMetadata = function (clientId, data, cb) {
|
Store.setPadMetadata = function (clientId, data, cb) {
|
||||||
|
console.log(data);
|
||||||
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
|
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
|
||||||
if (!data.command) { return void cb({ error: 'EINVAL' }); }
|
if (!data.command) { return void cb({ error: 'EINVAL' }); }
|
||||||
store.rpc.setMetadata(data, function (err, res) {
|
store.rpc.setMetadata(data, function (err, res) {
|
||||||
|
|||||||
@ -264,6 +264,7 @@ define([
|
|||||||
handlers['ADD_OWNER'] = function (ctx, box, data, cb) {
|
handlers['ADD_OWNER'] = function (ctx, box, data, cb) {
|
||||||
var msg = data.msg;
|
var msg = data.msg;
|
||||||
var content = msg.content;
|
var content = msg.content;
|
||||||
|
console.log(msg);
|
||||||
|
|
||||||
if (msg.author !== content.user.curvePublic) { return void cb(true); }
|
if (msg.author !== content.user.curvePublic) { return void cb(true); }
|
||||||
if (!content.href || !content.title || !content.channel) {
|
if (!content.href || !content.title || !content.channel) {
|
||||||
|
|||||||
@ -467,6 +467,13 @@ define([
|
|||||||
}, { timeout: 60000 });
|
}, { timeout: 60000 });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
funcs.getPadMetadata = function (data, cb) {
|
||||||
|
ctx.sframeChan.query('Q_GET_PAD_METADATA', data, function (err, val) {
|
||||||
|
if (err || (val && val.error)) { return void cb({error: err || val.error}); }
|
||||||
|
cb(val);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
funcs.gotoURL = function (url) { ctx.sframeChan.event('EV_GOTO_URL', url); };
|
funcs.gotoURL = function (url) { ctx.sframeChan.event('EV_GOTO_URL', url); };
|
||||||
funcs.openURL = function (url) { ctx.sframeChan.event('EV_OPEN_URL', url); };
|
funcs.openURL = function (url) { ctx.sframeChan.event('EV_OPEN_URL', url); };
|
||||||
funcs.openUnsafeURL = function (url) {
|
funcs.openUnsafeURL = function (url) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user