Enable change events in the drive

pull/1/head
yflory 7 years ago
parent 17636769e4
commit 9eb33e39e6

@ -99,7 +99,10 @@ define([
common.userObjectCommand = function (data, cb) { common.userObjectCommand = function (data, cb) {
postMessage("DRIVE_USEROBJECT", data, cb); postMessage("DRIVE_USEROBJECT", data, cb);
}; };
common.onDriveLog = Util.mkEvent(); common.drive = {};
common.drive.onLog = Util.mkEvent();
common.drive.onChange = Util.mkEvent();
common.drive.onRemove = Util.mkEvent();
// Profile // Profile
common.getProfileEditUrl = function (cb) { common.getProfileEditUrl = function (cb) {
postMessage("GET", ['profile', 'edit'], function (obj) { postMessage("GET", ['profile', 'edit'], function (obj) {
@ -649,7 +652,13 @@ define([
} }
// Drive // Drive
case 'DRIVE_LOG': { case 'DRIVE_LOG': {
common.onDriveLog.fire(data); common.drive.onLog.fire(data);
}
case 'DRIVE_CHANGE': {
common.drive.onChange.fire(data);
}
case 'DRIVE_REMOVE': {
common.drive.onRemove.fire(data);
} }
} }
}; };
@ -696,7 +705,8 @@ define([
anonHash: LocalStore.getFSHash(), anonHash: LocalStore.getFSHash(),
localToken: tryParsing(localStorage.getItem(Constants.tokenKey)), localToken: tryParsing(localStorage.getItem(Constants.tokenKey)),
language: common.getLanguage(), language: common.getLanguage(),
messenger: rdyCfg.messenger messenger: rdyCfg.messenger,
driveEvents: rdyCfg.driveEvents
}; };
if (sessionStorage[Constants.newPadPathKey]) { if (sessionStorage[Constants.newPadPathKey]) {
cfg.initialPath = sessionStorage[Constants.newPadPathKey]; cfg.initialPath = sessionStorage[Constants.newPadPathKey];

@ -264,7 +264,6 @@ define([
}; };
Store.getFileSize = function (data, cb) { Store.getFileSize = function (data, cb) {
console.log(data, cb);
if (!store.anon_rpc) { return void cb({error: 'ANON_RPC_NOT_READY'}); } if (!store.anon_rpc) { return void cb({error: 'ANON_RPC_NOT_READY'}); }
var channelId = Hash.hrefToHexChannelId(data.href); var channelId = Hash.hrefToHexChannelId(data.href);
@ -930,7 +929,7 @@ define([
ChainPad: ChainPad, ChainPad: ChainPad,
classic: true, classic: true,
}; };
var rt = Listmap.create(listmapConfig); var rt = window.rt = Listmap.create(listmapConfig);
store.proxy = rt.proxy; store.proxy = rt.proxy;
store.loggedIn = typeof(data.userHash) !== "undefined"; store.loggedIn = typeof(data.userHash) !== "undefined";
@ -959,6 +958,7 @@ define([
if (path[0] === 'drive' && path[1] === "migrate" && value === 1) { if (path[0] === 'drive' && path[1] === "migrate" && value === 1) {
rt.network.disconnect(); rt.network.disconnect();
rt.realtime.abort(); rt.realtime.abort();
postMessage('NETWORK_DISCONNECT');
} }
}); });
@ -1007,6 +1007,23 @@ define([
var messagingCfg = getMessagingCfg(); var messagingCfg = getMessagingCfg();
Messaging.addDirectMessageHandler(messagingCfg); Messaging.addDirectMessageHandler(messagingCfg);
// Send events whenever there is a change or a removal in the drive
if (data.driveEvents) {
store.proxy.on('change', [], function (o, n, p) {
postMessage('DRIVE_CHANGE', {
old: o,
new: n,
path: p
})
});
store.proxy.on('remove', [], function (o, p) {
postMessage('DRIVE_REMOVE', {
old: o,
path: p
})
});
}
if (data.messenger) { if (data.messenger) {
var messenger = store.messenger = Messenger.messenger(store); // TODO var messenger = store.messenger = Messenger.messenger(store); // TODO
messenger.on('message', function (message) { messenger.on('message', function (message) {

@ -86,7 +86,8 @@ define([
sframeChan = sfc; sframeChan = sfc;
}), false, { cache: cache, localStore: localStore, language: Cryptpad.getLanguage() }); }), false, { cache: cache, localStore: localStore, language: Cryptpad.getLanguage() });
Cryptpad.ready(waitFor(), { Cryptpad.ready(waitFor(), {
messenger: cfg.messaging messenger: cfg.messaging,
driveEvents: cfg.driveEvents
}); });
if (!cfg.newNetwork) { if (!cfg.newNetwork) {

@ -203,6 +203,9 @@ define({
'Q_DRIVE_GETOBJECT': true, 'Q_DRIVE_GETOBJECT': true,
// Store's userObject need to send log messages to inner to display them in the UI // Store's userObject need to send log messages to inner to display them in the UI
'EV_DRIVE_LOG': true, 'EV_DRIVE_LOG': true,
// Refresh the drive when the drive has changed ('change' or 'remove' events)
'EV_DRIVE_CHANGE': true,
'EV_DRIVE_REMOVE': true,
// Notifications about connection and disconnection from the network // Notifications about connection and disconnection from the network
'EV_NETWORK_DISCONNECT': true, 'EV_NETWORK_DISCONNECT': true,

@ -2869,9 +2869,10 @@ define([
onRefresh.to = window.setTimeout(refresh, 500); onRefresh.to = window.setTimeout(refresh, 500);
} }
}; };
/*proxy.on('change', [], function () {
sframeChan.on('EV_DRIVE_CHANGE', function (data) {
if (history.isHistoryMode) { return; } if (history.isHistoryMode) { return; }
var path = arguments[2]; var path = data.path;
if (path[0] !== 'drive') { return false; } if (path[0] !== 'drive') { return false; }
path = path.slice(1); path = path.slice(1);
var cPath = currentPath.slice(); var cPath = currentPath.slice();
@ -2884,26 +2885,21 @@ define([
} }
APP.resetTree(); APP.resetTree();
return false; return false;
}).on('remove', [], function () { });
sframeChan.on('EV_DRIVE_REMOVE', function (data) {
if (history.isHistoryMode) { return; } if (history.isHistoryMode) { return; }
var path = arguments[1]; var path = data.path;
if (path[0] !== 'drive') { return false; } if (path[0] !== 'drive') { return false; }
path = path.slice(1); path = path.slice(1);
var cPath = currentPath.slice(); var cPath = currentPath.slice();
if ((filesOp.isPathIn(cPath, ['hrefArray', TRASH]) && cPath[0] === path[0]) || if ((filesOp.isPathIn(cPath, ['hrefArray', TRASH]) && cPath[0] === path[0]) ||
(path.length >= cPath.length && filesOp.isSubpath(path, cPath))) { (path.length >= cPath.length && filesOp.isSubpath(path, cPath))) {
// Reload after a few to make sure all the change events have been received // Reload after a few to make sure all the change events have been received
onRefresh.to = window.setTimeout(refresh, 500); onRefresh.refresh();
} }
APP.resetTree(); APP.resetTree();
return false; return false;
}).on('change', ['drive', 'migrate'], function () { });
var path = arguments[2];
var value = arguments[1];
if (path[1] === "migrate" && value === 1) {
if (APP.onDisconnect) { APP.onDisconnect(true); }
}
});*/
history.onEnterHistory = function (obj) { history.onEnterHistory = function (obj) {
var files = obj.drive; var files = obj.drive;

@ -62,18 +62,21 @@ define([
Cryptpad.onNetworkReconnect.reg(function (data) { Cryptpad.onNetworkReconnect.reg(function (data) {
sframeChan.event('EV_NETWORK_RECONNECT', data); sframeChan.event('EV_NETWORK_RECONNECT', data);
}); });
Cryptpad.onDriveLog.reg(function (msg) { Cryptpad.drive.onLog.reg(function (msg) {
sframeChan.event('EV_DRIVE_LOG', msg); sframeChan.event('EV_DRIVE_LOG', msg);
}); });
// History? Cryptpad.drive.onChange.reg(function (data) {
sframeChan.event('EV_DRIVE_CHANGE', data);
});
Cryptpad.drive.onRemove.reg(function (data) {
sframeChan.event('EV_DRIVE_REMOVE', data);
});
}; };
//Netflux.connect(NetConfig.getWebsocketURL()).then(function (network) {
SFCommonO.start({ SFCommonO.start({
getSecrets: getSecrets, getSecrets: getSecrets,
//newNetwork: network,
noHash: true, noHash: true,
driveEvents: true,
addRpc: addRpc addRpc: addRpc
}); });
//}, function (err) { console.error(err); });
}); });
}); });

@ -362,7 +362,7 @@ define([
return cb(); return cb();
} }
var path; var path;
fo.addFolder(["root", "Folder2"], "subsub", function (e, o) { path = o.newPath; }); fo.addFolder(["root", "Folder2"], "subsub", function (o) { path = o.newPath; });
if (!files.root.Folder2.subsub || path.length !== 3) { if (!files.root.Folder2.subsub || path.length !== 3) {
console.log("DRIVE operations: add folder"); console.log("DRIVE operations: add folder");
return cb(); return cb();

Loading…
Cancel
Save