Create an owned pad and view owned pads in the drive

This commit is contained in:
yflory
2018-01-08 17:36:44 +01:00
parent 1ec41f4e09
commit 0cea5f4596
10 changed files with 131 additions and 21 deletions

View File

@@ -1241,8 +1241,8 @@ define([
}
// XXX TODO remove these lines
ownedVal = undefined;
expire = undefined;
//ownedVal = undefined;
//expire = undefined;
sframeChan.query("Q_CREATE_PAD", {
owned: ownedVal,

View File

@@ -361,6 +361,7 @@ define([
Store.addPad = function (data, cb) {
if (!data.href) { return void cb({error:'NO_HREF'}); }
var pad = makePad(data.href, data.title);
if (data.owners) { pad.owners = data.owners; }
store.userObject.pushData(pad, function (e, id) {
if (e) { return void cb({error: "Error while adding a template:"+ e}); }
var path = data.path || ['root'];
@@ -522,6 +523,11 @@ define([
var p = Hash.parsePadUrl(href);
var h = p.hashData;
var owners;
if (Store.channel && Util.base64ToHex(h.channel) === Store.channel.wc.id) {
owners = Store.channel.data.owners || undefined;
}
var allPads = Util.find(store.proxy, ['drive', 'filesData']) || {};
var isStronger;
@@ -583,6 +589,7 @@ define([
Store.addPad({
href: href,
title: title,
owners: owners,
path: data.path || (store.data && store.data.initialPath)
}, cb);
return;
@@ -735,12 +742,14 @@ define([
// TODO with sharedworker
// channel will be an object storing the webchannel associated to each browser tab
var channel = {
queue: []
var channel = Store.channel = {
queue: [],
data: {}
};
Store.joinPad = function (data, cb) {
var conf = {
onReady: function () {
onReady: function (padData) {
channel.data = padData || {};
postMessage("PAD_READY");
}, // post EV_PAD_READY
onMessage: function (m) {

View File

@@ -36,6 +36,7 @@ define([], function () {
var owners = conf.owners;
var password = conf.password;
var expire = conf.expire;
var padData;
conf = undefined;
var initializing = true;
@@ -43,11 +44,11 @@ define([], function () {
var messageFromOuter = function () {};
var onRdy = function () {
var onRdy = function (padData) {
// Trigger onReady only if not ready yet. This is important because the history keeper sends a direct
// message through "network" when it is synced, and it triggers onReady for each channel joined.
if (!initializing) { return; }
onReady();
onReady(padData);
//sframeChan.event('EV_RT_READY', null);
// we're fully synced
initializing = false;
@@ -92,13 +93,14 @@ define([], function () {
if (parsed.channel === wc.id && !validateKey) {
validateKey = parsed.validateKey;
}
padData = parsed;
// We have to return even if it is not the current channel:
// we don't want to continue with other channels messages here
return;
}
if (parsed.state && parsed.state === 1 && parsed.channel) {
if (parsed.channel === wc.id) {
onRdy();
onRdy(padData);
}
// We have to return even if it is not the current channel:
// we don't want to continue with other channels messages here
@@ -180,7 +182,7 @@ define([], function () {
});
network.historyKeeper = hk;
var cfg = {
var cfg = padData = {
validateKey: validateKey,
lastKnownHash: lastKnownHash,
owners: owners,

View File

@@ -35,6 +35,8 @@ define([
};
window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) {
SFCommonO.start();
SFCommonO.start({
useCreationScreen: true
});
});
});

View File

@@ -567,7 +567,8 @@ define([
// Join the netflux channel
var rtStarted = false;
var startRealtime = function () {
var startRealtime = function (rtConfig) {
rtConfig = rtConfig || {};
rtStarted = true;
var replaceHash = function (hash) {
if (window.history && window.history.replaceState) {
@@ -581,7 +582,7 @@ define([
window.location.hash = hash;
};
CpNfOuter.start({
var cfg = {
sframeChan: sframeChan,
channel: secret.channel,
padRpc: Cryptpad.padRpc,
@@ -600,7 +601,11 @@ define([
if (readOnly || cfg.noHash) { return; }
replaceHash(Utils.Hash.getEditHashFromKeys(wc, secret.keys));
}
};
Object.keys(rtConfig).forEach(function (k) {
cfg[k] = rtConfig[k];
});
CpNfOuter.start(cfg);
};
sframeChan.on('Q_CREATE_PAD', function (data, cb) {
@@ -624,12 +629,11 @@ define([
var rtConfig = {};
if (data.owned) {
//rtConfig.owners = [edPublic];
rtConfig.owners = [edPublic];
}
if (data.expire) {
//rtConfig.expire = data.expire;
rtConfig.expire = data.expire;
}
if (data.template) {
// Pass rtConfig to useTemplate because Cryptput will create the file and
// we need to have the owners and expiration time in the first line on the
@@ -651,7 +655,7 @@ define([
if (!realtime) { return; }
if (isNewFile && Utils.LocalStore.isLoggedIn()
&& AppConfig.displayCreationScreen) { return; }
&& AppConfig.displayCreationScreen && cfg.useCreationScreen) { return; }
startRealtime();
});

View File

@@ -453,6 +453,12 @@ define([
.map(function (str) { return Number(str); });
return sorted;
};
exp.getOwnedPads = function (edPub) {
var allFiles = files[FILES_DATA];
return Object.keys(allFiles).filter(function (id) {
return allFiles[id].owners && allFiles[id].owners.indexOf(edPub) !== -1;
}).map(function (k) { return Number(k); });;
};
/**
* OPERATIONS