Merge branch 'staging' into support
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
define([
|
||||
'/common/common-messaging.js',
|
||||
], function (Messaging) {
|
||||
'/common/common-hash.js',
|
||||
], function (Messaging, Hash) {
|
||||
|
||||
var getRandomTimeout = function (ctx) {
|
||||
var lag = ctx.store.realtime.getLag().lag || 0;
|
||||
@@ -156,6 +157,50 @@ define([
|
||||
cb(true);
|
||||
};
|
||||
|
||||
// Hide duplicates when receiving a SHARE_PAD notification:
|
||||
// Keep only one notification per channel: the stronger and more recent one
|
||||
var channels = {};
|
||||
handlers['SHARE_PAD'] = function (ctx, box, data, cb) {
|
||||
var msg = data.msg;
|
||||
var hash = data.hash;
|
||||
var content = msg.content;
|
||||
// content.name, content.title, content.href, content.password
|
||||
|
||||
var channel = Hash.hrefToHexChannelId(content.href, content.password);
|
||||
var parsed = Hash.parsePadUrl(content.href);
|
||||
var mode = parsed.hashData && parsed.hashData.mode || 'n/a';
|
||||
|
||||
var old = channels[channel];
|
||||
var toRemove;
|
||||
if (old) {
|
||||
// New hash is weaker, ignore
|
||||
if (old.mode === 'edit' && mode === 'view') {
|
||||
return void cb(true);
|
||||
}
|
||||
// New hash is not weaker, clear the old one
|
||||
toRemove = old.data;
|
||||
}
|
||||
|
||||
// Update the data
|
||||
channels[channel] = {
|
||||
mode: mode,
|
||||
data: {
|
||||
type: box.type,
|
||||
hash: hash
|
||||
}
|
||||
};
|
||||
|
||||
cb(false, toRemove);
|
||||
};
|
||||
removeHandlers['SHARE_PAD'] = function (ctx, box, data, hash) {
|
||||
var content = data.content;
|
||||
var channel = Hash.hrefToHexChannelId(content.href, content.password);
|
||||
var old = channels[channel];
|
||||
if (old && old.data && old.data.hash === hash) {
|
||||
delete channels[channel];
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
add: function (ctx, box, data, cb) {
|
||||
/**
|
||||
|
||||
@@ -187,6 +187,7 @@ proxy.mailboxes = {
|
||||
var openChannel = function (ctx, type, m, onReady) {
|
||||
var box = ctx.boxes[type] = {
|
||||
channel: m.channel,
|
||||
type: type,
|
||||
queue: [], // Store the messages to send when the channel is ready
|
||||
history: [], // All the hashes loaded from the server in corretc order
|
||||
content: {}, // Content of the messages that should be displayed
|
||||
@@ -259,8 +260,8 @@ proxy.mailboxes = {
|
||||
msg: msg,
|
||||
hash: hash
|
||||
};
|
||||
Handlers.add(ctx, box, message, function (toDismiss) {
|
||||
if (toDismiss) {
|
||||
Handlers.add(ctx, box, message, function (dismissed, toDismiss) {
|
||||
if (dismissed) { // This message should be removed
|
||||
dismiss(ctx, {
|
||||
type: type,
|
||||
hash: hash
|
||||
@@ -269,6 +270,11 @@ proxy.mailboxes = {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (toDismiss) { // List of other messages to remove
|
||||
dismiss(ctx, toDismiss, '', function () {
|
||||
console.log('Notification handled automatically');
|
||||
});
|
||||
}
|
||||
box.content[hash] = msg;
|
||||
showMessage(ctx, type, message);
|
||||
});
|
||||
|
||||
@@ -26,7 +26,10 @@ define([
|
||||
if (!c.id) { c.id = chan.wc.myID + '-' + client; }
|
||||
|
||||
chan.history.forEach(function (msg) {
|
||||
ctx.emit('MESSAGE', msg, [client]);
|
||||
ctx.emit('MESSAGE', {
|
||||
msg: msg,
|
||||
validateKey: chan.validateKey
|
||||
}, [client]);
|
||||
});
|
||||
|
||||
// ==> And push the new tab to the list
|
||||
@@ -37,7 +40,8 @@ define([
|
||||
var onOpen = function (wc) {
|
||||
|
||||
ctx.channels[channel] = ctx.channels[channel] || {
|
||||
history: []
|
||||
history: [],
|
||||
validateKey: obj.validateKey
|
||||
};
|
||||
|
||||
chan = ctx.channels[channel];
|
||||
@@ -61,7 +65,10 @@ define([
|
||||
});
|
||||
wc.on('message', function (msg) {
|
||||
chan.history.push(msg);
|
||||
ctx.emit('MESSAGE', msg, chan.clients);
|
||||
ctx.emit('MESSAGE', {
|
||||
msg: msg,
|
||||
validateKey: chan.validateKey
|
||||
}, chan.clients);
|
||||
});
|
||||
|
||||
chan.wc = wc;
|
||||
@@ -101,6 +108,7 @@ define([
|
||||
};
|
||||
|
||||
network.on('message', function (msg, sender) {
|
||||
if (!ctx.channels[channel]) { return; }
|
||||
var hk = network.historyKeeper;
|
||||
if (sender !== hk) { return; }
|
||||
|
||||
@@ -115,7 +123,12 @@ define([
|
||||
// Keep only metadata messages for the current channel
|
||||
if (parsed.channel && parsed.channel !== channel) { return; }
|
||||
// Ignore the metadata message
|
||||
if (parsed.validateKey && parsed.channel) { return; }
|
||||
if (parsed.validateKey && parsed.channel) {
|
||||
if (!chan.validateKey) {
|
||||
chan.validateKey = parsed.validateKey;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// End of history: emit READY
|
||||
if (parsed.state && parsed.state === 1 && parsed.channel) {
|
||||
ctx.emit('READY', '', chan.clients);
|
||||
@@ -132,7 +145,9 @@ define([
|
||||
if (hash === chan.lastKnownHash || hash === chan.lastCpHash) { return; }
|
||||
|
||||
chan.lastKnownHash = hash;
|
||||
ctx.emit('MESSAGE', msg, chan.clients);
|
||||
ctx.emit('MESSAGE', {
|
||||
msg: msg,
|
||||
}, chan.clients);
|
||||
chan.history.push(msg);
|
||||
});
|
||||
|
||||
@@ -176,7 +191,9 @@ define([
|
||||
return void chan.sendMsg(data.isCp, cb);
|
||||
}
|
||||
chan.sendMsg(data.msg, cb);
|
||||
ctx.emit('MESSAGE', data.msg, chan.clients.filter(function (cl) {
|
||||
ctx.emit('MESSAGE', {
|
||||
msg: data.msg
|
||||
}, chan.clients.filter(function (cl) {
|
||||
return cl !== clientId;
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -625,6 +625,11 @@ define([
|
||||
var root = exp.find([ROOT]);
|
||||
var toClean = [];
|
||||
for (var id in fd) {
|
||||
if (String(id) !== String(Number(id))) {
|
||||
debug("Invalid file ID in filesData.", id);
|
||||
toClean.push(id);
|
||||
continue;
|
||||
}
|
||||
id = Number(id);
|
||||
var el = fd[id];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user