Pin images included in the spreadsheets
This commit is contained in:
parent
7f4dbd3245
commit
dbb726e4ce
@ -1260,6 +1260,23 @@ define([
|
|||||||
return stringify(obj);
|
return stringify(obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var pinImages = function () {
|
||||||
|
if (content.mediasSources) {
|
||||||
|
var toPin = Object.keys(content.mediasSources || {}).map(function (id) {
|
||||||
|
var data = content.mediasSources[id] || {};
|
||||||
|
var src = data.src;
|
||||||
|
if (!src) { return; }
|
||||||
|
// Remove trailing slash
|
||||||
|
if (src.slice(-1) === '/') {
|
||||||
|
src = src.slice(0, -1);
|
||||||
|
}
|
||||||
|
// Extract the channel id from the source href
|
||||||
|
return src.slice(src.lastIndexOf('/') + 1);
|
||||||
|
}).filter(Boolean);
|
||||||
|
sframeChan.query('EV_OO_PIN_IMAGES', toPin);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
APP.getContent = function () { return content; };
|
APP.getContent = function () { return content; };
|
||||||
|
|
||||||
APP.onLocal = config.onLocal = function () {
|
APP.onLocal = config.onLocal = function () {
|
||||||
@ -1269,6 +1286,7 @@ define([
|
|||||||
// Update metadata
|
// Update metadata
|
||||||
var content = stringifyInner();
|
var content = stringifyInner();
|
||||||
APP.realtime.contentUpdate(content);
|
APP.realtime.contentUpdate(content);
|
||||||
|
pinImages();
|
||||||
};
|
};
|
||||||
|
|
||||||
config.onInit = function (info) {
|
config.onInit = function (info) {
|
||||||
@ -1422,6 +1440,7 @@ define([
|
|||||||
handleNewLocks(oldLocks, content.locks);
|
handleNewLocks(oldLocks, content.locks);
|
||||||
oldLocks = JSON.parse(JSON.stringify(content.locks));
|
oldLocks = JSON.parse(JSON.stringify(content.locks));
|
||||||
}
|
}
|
||||||
|
pinImages();
|
||||||
};
|
};
|
||||||
|
|
||||||
config.onAbort = function () {
|
config.onAbort = function () {
|
||||||
|
|||||||
@ -88,6 +88,32 @@ define([
|
|||||||
}, cb);
|
}, cb);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
sframeChan.on('EV_OO_PIN_IMAGES', function (list) {
|
||||||
|
Cryptpad.getPadAttribute('ooImages', function (err, res) {
|
||||||
|
if (err) { return; }
|
||||||
|
if (!res || !Array.isArray(res)) { res = []; }
|
||||||
|
var toPin = [];
|
||||||
|
var toUnpin = [];
|
||||||
|
res.forEach(function (id) {
|
||||||
|
if (list.indexOf(id) === -1) {
|
||||||
|
toUnpin.push(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
list.forEach(function (id) {
|
||||||
|
if (res.indexOf(id) === -1) {
|
||||||
|
toPin.push(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
toPin = Utils.Util.deduplicateString(toPin);
|
||||||
|
toUnpin = Utils.Util.deduplicateString(toUnpin);
|
||||||
|
Cryptpad.pinPads(toPin, function () {});
|
||||||
|
Cryptpad.unpinPads(toUnpin, function () {});
|
||||||
|
if (!toPin.length && !toUnpin.length) { return; }
|
||||||
|
Cryptpad.setPadAttribute('ooImages', list, function (err) {
|
||||||
|
if (err) { console.error(err); }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
sframeChan.on('Q_OO_COMMAND', function (obj, cb) {
|
sframeChan.on('Q_OO_COMMAND', function (obj, cb) {
|
||||||
if (obj.cmd === 'SEND_MESSAGE') {
|
if (obj.cmd === 'SEND_MESSAGE') {
|
||||||
obj.data.msg = Utils.crypto.encrypt(JSON.stringify(obj.data.msg));
|
obj.data.msg = Utils.crypto.encrypt(JSON.stringify(obj.data.msg));
|
||||||
|
|||||||
@ -972,16 +972,22 @@ define([
|
|||||||
if (!data) { return; }
|
if (!data) { return; }
|
||||||
// Don't pin pads owned by someone else
|
// Don't pin pads owned by someone else
|
||||||
if (_ownedByOther(Env, data.owners)) { return; }
|
if (_ownedByOther(Env, data.owners)) { return; }
|
||||||
// Don't push duplicates
|
// Pin onlyoffice checkpoints
|
||||||
if (data.lastVersion) {
|
if (data.lastVersion) {
|
||||||
var otherChan = Hash.hrefToHexChannelId(data.lastVersion);
|
var otherChan = Hash.hrefToHexChannelId(data.lastVersion);
|
||||||
if (result.indexOf(otherChan) === -1) {
|
if (result.indexOf(otherChan) === -1) {
|
||||||
result.push(otherChan);
|
result.push(otherChan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Pin onlyoffice realtime patches
|
||||||
if (data.rtChannel && result.indexOf(data.rtChannel) === -1) {
|
if (data.rtChannel && result.indexOf(data.rtChannel) === -1) {
|
||||||
result.push(data.rtChannel);
|
result.push(data.rtChannel);
|
||||||
}
|
}
|
||||||
|
// Pin onlyoffice images
|
||||||
|
if (data.ooImages && Array.isArray(data.ooImages)) {
|
||||||
|
Array.prototype.push.apply(result, data.ooImages);
|
||||||
|
}
|
||||||
|
// Pin the pad
|
||||||
if (result.indexOf(data.channel) === -1) {
|
if (result.indexOf(data.channel) === -1) {
|
||||||
result.push(data.channel);
|
result.push(data.channel);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user