Refresh properties modal when receiving metadata updates

pull/1/head
yflory 5 years ago
parent d52e449f87
commit 32f1d1627f

@ -271,14 +271,12 @@ define([
}
}));
}).nThen(function (waitFor) {
console.log('koko');
// Send the command
sframeChan.query('Q_SET_PAD_METADATA', {
channel: channel,
command: 'ADD_PENDING_OWNERS',
value: toAdd
}, waitFor(function (err, res) {
console.error(arguments);
err = err || (res && res.error);
if (err) {
waitFor.abort();
@ -286,8 +284,6 @@ define([
} // XXX
}));
}).nThen(function (waitFor) {
console.log('okok');
// TODO send notifications
sel.forEach(function (el) {
var friend = friends[$(el).attr('data-curve')];
if (!friend) { return; }
@ -318,13 +314,17 @@ define([
return $div2;
};
var pending = false;
redrawAll = function () {
$div1.empty();
$div2.empty();
if (pending) { return; }
pending = true;
common.getPadMetadata(null, function (obj) {
pending = false;
if (obj && obj.error) { return; }
owners = obj.owners;
pending_owners = obj.pending_owners;
$div1.empty();
$div2.empty();
$div1.append(drawRemove(false)).append(drawRemove(true));
$div2.append(drawAdd());
});
@ -333,6 +333,15 @@ define([
$div1.append(drawRemove(false)).append(drawRemove(true));
$div2.append(drawAdd());
var handler = sframeChan.on('EV_RT_METADATA', function (md) {
if (!$div1.length) {
return void handler.stop();
}
owners = md.owners;
pending_owners = md.pending_owners;
redrawAll();
});
// Create modal
var link = h('div.cp-share-columns', [
div1,
@ -349,9 +358,11 @@ define([
return UI.dialog.customModal(link, {buttons: linkButtons});
};
var getRightsProperties = function (common, data, cb) {
var $d = $('<div>');
if (!data) { return void cb(void 0, $d); }
var $div = $('<div>');
if (!data) { return void cb(void 0, $div); }
var draw = function () {
var $d = $('<div>');
$('<label>', {'for': 'cp-app-prop-owners'}).text(Messages.creation_owners)
.appendTo($d);
var owners = Messages.creation_noOwner;
@ -480,8 +491,25 @@ define([
$d.append(changePass);
}
}
return $d;
};
cb(void 0, $d);
var sframeChan = common.getSframeChannel();
var handler = sframeChan.on('EV_RT_METADATA', function (md) {
if (!$div.length) {
handler.stop();
return;
}
md = JSON.parse(JSON.stringify(md));
data.owners = md.owners;
data.expire = md.expire;
data.pending_owners = md.pending_owners;
$div.empty();
$div.append(draw());
});
$div.append(draw());
cb(void 0, $div);
};
var getPadProperties = function (common, data, cb) {
var $d = $('<div>');
@ -568,6 +596,8 @@ define([
} else {
cb(void 0, $d);
}
};
UIElements.getProperties = function (common, data, cb) {
var c1;

@ -757,6 +757,7 @@ define([
pad.onDisconnectEvent = Util.mkEvent();
pad.onConnectEvent = Util.mkEvent();
pad.onErrorEvent = Util.mkEvent();
pad.onMetadataEvent = Util.mkEvent();
pad.getPadMetadata = function (data, cb) {
postMessage('GET_PAD_METADATA', data, cb);
@ -1208,6 +1209,7 @@ define([
PAD_DISCONNECT: common.padRpc.onDisconnectEvent.fire,
PAD_CONNECT: common.padRpc.onConnectEvent.fire,
PAD_ERROR: common.padRpc.onErrorEvent.fire,
PAD_METADATA: common.padRpc.onMetadataEvent.fire,
// Drive
DRIVE_LOG: common.drive.onLog.fire,
DRIVE_CHANGE: common.drive.onChange.fire,

@ -1205,7 +1205,6 @@ define([
}
},
onMetadataUpdate: function (metadata) {
console.log('onMetadataUpdate', metadata);
channel.data = metadata || {};
var allData = store.manager.findChannel(data.channel);
allData.forEach(function (obj) {
@ -1214,7 +1213,7 @@ define([
obj.data.expire = +metadata.expire;
}
});
//channel.bcast("PAD_METADATA", metadata);
channel.bcast("PAD_METADATA", metadata);
},
crypto: {
// The encryption and decryption is done in the outer window.
@ -1374,7 +1373,6 @@ define([
};
Store.getPadMetadata = function (clientId, data, cb) {
console.log(data);
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
var channel = channels[data.channel];
if (!channel) { return void cb({ error: 'ENOTFOUND' }); }
@ -1397,7 +1395,6 @@ define([
cb(channel.data || {});
};
Store.setPadMetadata = function (clientId, data, cb) {
console.log(data);
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
if (!data.command) { return void cb({ error: 'EINVAL' }); }
store.rpc.setMetadata(data, function (err, res) {

@ -742,7 +742,7 @@ define([
datas.forEach(function (d) {
var atime = d.data.atime;
var value = attr ? d.data[attr] : JSON.parse(JSON.stringify(d.data));
var value = data.attr ? d.data[data.attr] : JSON.parse(JSON.stringify(d.data));
if (!res.value || res.atime < atime) {
res.atime = atime;
res.value = value;

@ -118,6 +118,10 @@ define([], function () {
onOpen(data);
});
padRpc.onMetadataEvent.reg(function (data) {
sframeChan.event('EV_RT_METADATA', data);
});
padRpc.onErrorEvent.reg(function (err) {
sframeChan.event('EV_RT_ERROR', err);
});

@ -1025,7 +1025,6 @@ define([
channel: secret.channel
};
}
console.log(data);
Cryptpad.getPadMetadata(data, cb);
});
sframeChan.on('Q_SET_PAD_METADATA', function (data, cb) {

Loading…
Cancel
Save