Merge branch 'staging' into team

This commit is contained in:
yflory
2019-09-10 15:32:05 +02:00
19 changed files with 185 additions and 91 deletions

View File

@@ -703,8 +703,13 @@ define([
href: href,
channel: channel,
title: data.driveReadmeTitle,
owners: [ store.proxy.edPublic ],
};
Store.addPad(clientId, fileData, cb);
}, {
metadata: {
owners: [ store.proxy.edPublic ],
},
});
});
};
@@ -989,11 +994,18 @@ define([
pad.href = href;
});
// If we've just accepted ownership for a pad stored in a shared folder,
// we need to make a copy of this pad in our drive. We're going to check
// the pad is owned by us BUT is not stored in our main drive
var inMyDrive = datas.some(function (obj) {
return !obj.fId;
});
// XXX owned by one of our teams?
var ownedByMe = Array.isArray(owners) && owners.indexOf(store.proxy.edPublic) !== -1;
// Add the pad if it does not exist in our drive
if (!contains) {
if (!contains || (ownedByMe && !inMyDrive)) {
var autoStore = Util.find(store.proxy, ['settings', 'general', 'autostore']);
// XXX owned by one of our teams?
var ownedByMe = Array.isArray(owners) && owners.indexOf(store.proxy.edPublic) !== -1;
if (autoStore !== 1 && !data.forceSave && !data.path && !ownedByMe) {
// send event to inner to display the corner popup
postMessage(clientId, "AUTOSTORE_DISPLAY_POPUP", {
@@ -1920,12 +1932,12 @@ define([
broadcast([], "UPDATE_METADATA");
},
pinPads: function (data, cb) { Store.pinPads(null, data, cb); },
}, waitFor, function (ev, data, clients) {
}, waitFor, function (ev, data, clients, cb) {
clients.forEach(function (cId) {
postMessage(cId, 'MAILBOX_EVENT', {
ev: ev,
data: data
});
}, cb);
});
});
};

View File

@@ -148,12 +148,15 @@ define([
return void cb({error: err});
});
network.on('reconnect', function () {
var onReconnect = function () {
if (!ctx.channels[channel]) { console.log("cant reconnect", channel); return; }
network.join(channel).then(onOpen, function (err) {
console.error(err);
});
});
};
ctx.channels[channel] = ctx.channels[channel] || {};
ctx.channels[channel].onReconnect = onReconnect;
network.on('reconnect', onReconnect);
};
var updateCursor = function (ctx, data, client, cb) {
@@ -173,6 +176,10 @@ define([
var channel = ctx.channels[cursorChan];
if (channel.padChan !== padChan) { return; }
if (channel.wc) { channel.wc.leave(); }
if (channel.onReconnect) {
var network = ctx.store.network;
network.off('reconnect', channel.onReconnect);
}
delete ctx.channels[cursorChan];
return true;
});
@@ -190,6 +197,10 @@ define([
chan.clients = chan.clients.filter(filter);
if (chan.clients.length === 0) {
if (chan.wc) { chan.wc.leave(); }
if (chan.onReconnect) {
var network = ctx.store.network;
network.off('reconnect', chan.onReconnect);
}
delete ctx.channels[k];
}
}

View File

@@ -2,10 +2,11 @@ define([
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-realtime.js',
'/common/notify.js',
'/common/outer/mailbox-handlers.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/chainpad-crypto/crypto.js',
], function (Util, Hash, Realtime, Handlers, CpNetflux, Crypto) {
], function (Util, Hash, Realtime, Notify, Handlers, CpNetflux, Crypto) {
var Mailbox = {};
var TYPES = [
@@ -54,11 +55,11 @@ proxy.mailboxes = {
return (m.viewed || []).indexOf(hash) === -1 && hash !== m.lastKnownHash;
};
var showMessage = function (ctx, type, msg, cId) {
var showMessage = function (ctx, type, msg, cId, cb) {
ctx.emit('MESSAGE', {
type: type,
content: msg
}, cId ? [cId] : ctx.clients);
}, cId ? [cId] : ctx.clients, cb);
};
var hideMessage = function (ctx, type, hash, clients) {
ctx.emit('VIEWED', {
@@ -272,7 +273,11 @@ proxy.mailboxes = {
});
}
box.content[hash] = msg;
showMessage(ctx, type, message);
showMessage(ctx, type, message, null, function (obj) {
if (!box.ready) { return; }
if (!obj || !obj.msg) { return; }
Notify.system(undefined, obj.msg);
});
});
} else {
// Message has already been viewed by the user
@@ -320,6 +325,7 @@ proxy.mailboxes = {
view(n);
}
});
box.ready = true;
// Continue
onReady();
};