Enable change events in the drive

This commit is contained in:
yflory
2017-12-05 18:09:43 +01:00
parent 17636769e4
commit 9eb33e39e6
7 changed files with 59 additions and 29 deletions

View File

@@ -99,7 +99,10 @@ define([
common.userObjectCommand = function (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
common.getProfileEditUrl = function (cb) {
postMessage("GET", ['profile', 'edit'], function (obj) {
@@ -649,7 +652,13 @@ define([
}
// Drive
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(),
localToken: tryParsing(localStorage.getItem(Constants.tokenKey)),
language: common.getLanguage(),
messenger: rdyCfg.messenger
messenger: rdyCfg.messenger,
driveEvents: rdyCfg.driveEvents
};
if (sessionStorage[Constants.newPadPathKey]) {
cfg.initialPath = sessionStorage[Constants.newPadPathKey];

View File

@@ -264,7 +264,6 @@ define([
};
Store.getFileSize = function (data, cb) {
console.log(data, cb);
if (!store.anon_rpc) { return void cb({error: 'ANON_RPC_NOT_READY'}); }
var channelId = Hash.hrefToHexChannelId(data.href);
@@ -930,7 +929,7 @@ define([
ChainPad: ChainPad,
classic: true,
};
var rt = Listmap.create(listmapConfig);
var rt = window.rt = Listmap.create(listmapConfig);
store.proxy = rt.proxy;
store.loggedIn = typeof(data.userHash) !== "undefined";
@@ -959,6 +958,7 @@ define([
if (path[0] === 'drive' && path[1] === "migrate" && value === 1) {
rt.network.disconnect();
rt.realtime.abort();
postMessage('NETWORK_DISCONNECT');
}
});
@@ -1007,6 +1007,23 @@ define([
var messagingCfg = getMessagingCfg();
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) {
var messenger = store.messenger = Messenger.messenger(store); // TODO
messenger.on('message', function (message) {

View File

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

View File

@@ -203,6 +203,9 @@ define({
'Q_DRIVE_GETOBJECT': true,
// Store's userObject need to send log messages to inner to display them in the UI
'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
'EV_NETWORK_DISCONNECT': true,