Display a shared folder in the drive

This commit is contained in:
yflory
2018-07-09 14:36:55 +02:00
parent 0c9dfc1fb5
commit e0cc1a6eb6
8 changed files with 176 additions and 48 deletions

View File

@@ -38,7 +38,7 @@ define([
Realtime.whenRealtimeSyncs(store.realtime, waitFor());
if (store.sharedFolders) {
for (var k in store.sharedFolders) {
Realtime.whenRealtimeSync(store.sharedFolders[k].realtime, waitFor());
Realtime.whenRealtimeSyncs(store.sharedFolders[k].realtime, waitFor());
}
}
}).nThen(function () { cb(); });
@@ -61,6 +61,13 @@ define([
onSync(cb);
};
Store.getSharedFolder = function (clientId, id, cb) {
if (store.manager.folders[id]) {
return void cb(store.manager.folders[id].proxy);
}
cb({});
};
Store.hasSigningKeys = function () {
if (!store.proxy) { return; }
return typeof(store.proxy.edPrivate) === 'string' &&
@@ -1166,7 +1173,7 @@ define([
var id;
nThen(function (waitFor) {
// TODO XXX get the folder data (href, title, ...)
var folderData = {};
var folderData = data.folderData || {};
// 1. add the shared folder to our list of shared folders
store.userObject.pushSharedFolder(folderData, waitFor(function (err, folderId) {
if (err) {
@@ -1177,6 +1184,7 @@ define([
}));
}).nThen(function (waitFor) {
// 2a. add the shared folder to the path in our drive
console.log('adding');
store.userObject.add(id, path);
onSync(waitFor());
@@ -1189,6 +1197,23 @@ define([
cb();
});
};
store.createSharedFolder = function () {
// XXX
var hash = Hash.createRandomHash('folder');
var href = '/folder/#' + hash;
var secret = Hash.getSecrets('folder', hash);
Store.addSharedFolder(null, {
path: ['root'],
folderData: {
href: href,
roHref: '/folder/#' + Hash.getViewHashFromKeys(secret),
channel: secret.channel,
title: "Test",
}
}, function () {
console.log('done');
});
};
// Drive

View File

@@ -52,6 +52,7 @@ define([
GET_PAD_DATA: Store.getPadData,
GET_STRONGER_HASH: Store.getStrongerHash,
INCREMENT_TEMPLATE_USE: Store.incrementTemplateUse,
GET_SHARED_FOLDER: Store.getSharedFolder,
// Messaging
INVITE_FROM_USERLIST: Store.inviteFromUserlist,
ADD_DIRECT_MESSAGE_HANDLERS: Store.addDirectMessageHandlers,

View File

@@ -69,6 +69,23 @@ define([
});
};
exp.pushSharedFolder = function (data, cb) {
if (typeof cb !== "function") { cb = function () {}; }
var todo = function () {
var id = Util.createRandomInteger();
files[SHARED_FOLDERS][id] = data;
cb(null, id);
};
if (!loggedIn || !AppConfig.enablePinning || config.testMode) {
return void cb("EAUTH");
}
if (!pinPads) { return void cb('EAUTH'); }
pinPads([data.channel], function (obj) {
if (obj && obj.error) { return void cb(obj.error); }
todo();
});
};
// FILES DATA
var spliceFileData = function (id) {
delete files[FILES_DATA][id];
@@ -191,6 +208,7 @@ define([
var toRemove = [];
Object.keys(data).forEach(function (id) {
id = Number(id);
// Find and maybe update existing pads with the same channel id
var d = data[id];
var found = false;
@@ -332,9 +350,9 @@ define([
};
exp.add = function (id, path) {
// TODO WW
if (!loggedIn && !config.testMode) { return; }
var data = files[FILES_DATA][id];
id = Number(id);
var data = files[FILES_DATA][id] || files[SHARED_FOLDERS][id];
if (!data || typeof(data) !== "object") { return; }
var newPath = path, parentEl;
if (path && !Array.isArray(path)) {
@@ -438,7 +456,6 @@ define([
});
delete files[OLD_FILES_DATA];
delete files.migrate;
console.log('done');
todo();
};
if (exp.rt) {
@@ -581,7 +598,7 @@ define([
});
};
var fixFilesData = function () {
if (typeof files[FILES_DATA] !== "object") { debug("OLD_FILES_DATA was not an object"); files[FILES_DATA] = {}; }
if (typeof files[FILES_DATA] !== "object") { debug("FILES_DATA was not an object"); files[FILES_DATA] = {}; }
var fd = files[FILES_DATA];
var rootFiles = exp.getFiles([ROOT, TRASH, 'hrefArray']);
var root = exp.find([ROOT]);
@@ -649,7 +666,8 @@ define([
secret = Hash.getSecrets(parsed.type, parsed.hash, el.password);
}
el.channel = secret.channel;
console.log('Adding missing channel in filesData ', el.channel);
console.log(el);
debug('Adding missing channel in filesData ', el.channel);
} catch (e) {
console.error(e);
}