Fix extra channels not pinned until reload

This commit is contained in:
yflory 2025-05-16 11:54:59 +02:00
parent 1fb2fd83cf
commit d64d580733
6 changed files with 57 additions and 11 deletions

View File

@ -746,6 +746,10 @@ const factory = (Sortify, UserObject, ProxyManager,
if (data.password) { pad.password = data.password; }
if (data.channel || secret) { pad.channel = data.channel || secret.channel; }
if (data.readme) { pad.readme = 1; }
Object.keys(data.attributes || {}).forEach(k => {
if (!data.attributes[k]) { return; } // undefined
pad[k] = data.attributes[k];
});
if (data.teamId === -1) { data.teamId = undefined; }
var s = getStore(data.teamId);
@ -1309,7 +1313,8 @@ const factory = (Sortify, UserObject, ProxyManager,
owners: owners,
expire: expire,
password: data.password,
path: data.path
path: data.path,
attributes: data.attributes
}, cb);
// Let inner know that dropped files shouldn't trigger the popup
postMessage(clientId, "AUTOSTORE_DISPLAY_POPUP", {

View File

@ -1159,6 +1159,13 @@ define([
}
}
// Make sure we also store additionnal data to pin all the channels
// (OO and forms)
data.attributes = {};
Object.keys(common?.otherPadAttrs || {}).forEach(k => {
data.attributes[k] = common.otherPadAttrs[k];
});
postMessage("SET_PAD_TITLE", data, function (obj) {
if (obj && obj.error) {
if (obj.error !== "EAUTH") { console.log("unable to set pad title"); }
@ -1181,6 +1188,8 @@ define([
return;
}
let rtChannel, lastVersion, answersChannel;
let attributes = {};
nThen(function (waitFor) {
if (parsed.hashData.type !== 'pad') { return; }
// Set the correct owner and expiration time if we can find them
@ -1191,6 +1200,14 @@ define([
data.owners = obj.owners;
data.expire = +obj.expire;
}));
common.getPadAttribute('', waitFor(function (err, _data) {
attributes.rtChannel = _data?.rtChannel;
attributes.lastVersion = _data?.lastVersion;
attributes.answersChannel = _data?.answersChannel;
Object.keys(common?.otherPadAttrs || {}).forEach(k => {
attributes[k] = common.otherPadAttrs[k];
});
}), data.href);
}).nThen(function () {
postMessage("SET_PAD_TITLE", {
teamId: data.teamId,
@ -1201,6 +1218,7 @@ define([
path: data.path,
owners: data.owners,
expire: data.expire,
attributes,
forceSave: 1
}, function (obj) {
if (obj && obj.error) { return void cb(obj.error); }

View File

@ -46,20 +46,32 @@ define([
sframeChan.on('Q_OO_SAVE', function (data, cb) {
var chanId = Utils.Hash.hrefToHexChannelId(data.url);
Cryptpad.getPadAttribute('lastVersion', function (err, data) {
if (data) {
var oldChanId = Utils.Hash.hrefToHexChannelId(data);
if (oldChanId !== chanId) { Cryptpad.unpinPads([oldChanId], function () {}); }
}
if (!data) { return; }
var oldChanId = Utils.Hash.hrefToHexChannelId(data);
if (oldChanId !== chanId) { Cryptpad.unpinPads([oldChanId], function () {}); }
});
Cryptpad.pinPads([chanId], function (e) {
if (e) { return void cb(e); }
Cryptpad.setPadAttribute('lastVersion', data.url, cb);
channels.lastVersion = data.url;
// If pad is stored, pin
Cryptpad.getPadAttribute('channel', function (err, data) {
if (err || !data) { return; }
Cryptpad.pinPads([chanId], function (e) {
if (e) { return void cb(e); }
});
});
Cryptpad.setPadAttribute('lastVersion', data.url, cb);
channels.lastVersion = data.url;
Cryptpad.setPadAttribute('lastCpHash', data.hash, cb);
channels.lastCpHash = data.hash;
});
sframeChan.on('Q_OO_OPENCHANNEL', function (data, cb) {
const other = Cryptpad.otherPadAttrs = {
rtChannel: data.channel
};
if (channels.lastVersion) {
other.lastVersion = channels.lastVersion;
}
other.lastCpHash = channels.lastCpHash;
Cryptpad.getPadAttribute('rtChannel', function (err, res) {
// If already stored, don't pin it again
if (res && res === data.channel) { return; }

View File

@ -1401,7 +1401,15 @@ const factory = (UserObject, Util, Hash,
});
};
if (!Env.pinPads) { return void todo(); }
Env.pinPads([pad.channel], function (obj) {
let channels = [pad.channel];
if (pad.rtChannel) { channels.push(pad.rtChannel); }
if (pad.answersChannel) { channels.push(pad.answersChannel); }
if (pad.lastVersion) {
channels.push(Hash.hrefToHexChannelId(pad.lastVersion));
}
Env.pinPads(channels, function (obj) {
if (obj && obj.error) { return void cb(obj.error); }
todo();
});

File diff suppressed because one or more lines are too long

View File

@ -45,6 +45,9 @@ define([
var addRpc = function (sframeChan, Cryptpad) {
sframeChan.on('EV_FORM_PIN', function (data) {
channels.answersChannel = data.channel;
Cryptpad.otherPadAttrs = {
answersChannel: data.channel
};
Cryptpad.changeMetadata();
Cryptpad.getPadAttribute('answersChannel', function (err, res) {
// If already stored, don't pin it again