fix(pinning): check if rtChannel is missing when storing a pad

This commit is contained in:
yflory 2026-03-13 16:09:41 +01:00
parent 618a71bffe
commit d807591366
3 changed files with 53 additions and 24 deletions

View File

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

View File

@ -662,11 +662,27 @@ const factory = (Sortify, UserObject, ProxyManager,
};
};
const getRtChannelFromPad = (data, cb) => {
const opts = {
network: store.network
};
const href = data.href;
opts.password = data.password;
const parsed = Hash.parsePadUrl(href);
Cryptget.get(parsed.hash, (err, content) => {
if (err) { return void cb(err); }
const p = Util.tryParse(content);
const rtChannel = p?.content?.channel;
if (!rtChannel) { return void cb('NO_CHAN'); }
cb(void 0, rtChannel);
}, opts);
};
Store.addPad = function (clientId, data, cb) {
if (!data.href && !data.roHref) { return void cb({error:'NO_HREF'}); }
var secret;
var parsed = Hash.parsePadUrl(data.href || data.roHref);
if (!data.roHref) {
var parsed = Hash.parsePadUrl(data.href);
if (parsed.hashData.type === "pad") {
secret = Hash.getSecrets(parsed.type, parsed.hash, data.password);
data.roHref = '/' + parsed.type + '/#' + Hash.getViewHashFromKeys(secret);
@ -687,18 +703,35 @@ const factory = (Sortify, UserObject, ProxyManager,
var s = getStore(data.teamId);
if (!s || !s.manager) { return void cb({ error: 'ENOTFOUND' }); }
s.manager.addPad(data.path, pad, function (e) {
if (e) { return void cb({error: e}); }
// Send a CHANGE events to all the teams because we may have just
// added a pad to a shared folder stored in multiple teams
getAllStores().forEach(function (_s) {
var send = _s.id ? _s.sendEvent : sendDriveEvent;
send('DRIVE_CHANGE', {
path: ['drive', UserObject.FILES_DATA]
}, clientId);
const add = Util.once(() => {
s.manager.addPad(data.path, pad, function (e) {
if (e) { return void cb({error: e}); }
// Send a CHANGE events to all the teams because we may have just
// added a pad to a shared folder stored in multiple teams
getAllStores().forEach(function (_s) {
var send = _s.id ? _s.sendEvent : sendDriveEvent;
send('DRIVE_CHANGE', {
path: ['drive', UserObject.FILES_DATA]
}, clientId);
});
onSync(data.teamId, cb);
});
onSync(data.teamId, cb);
});
if (['doc', 'sheet', 'presentation'].includes(parsed.type)) {
if (!pad.rtChannel) {
return getRtChannelFromPad(pad, (err, rtChannel) => {
if (!err) {
const key = 'ADDPAD_NO_RT_CHANNEL' ;
const team = data.teamId ? 'TEAM' : 'OWN';
Feedback.send(`${key}:${team}`, true);
pad.rtChannel = rtChannel;
}
add();
});
}
}
add();
};
var getOwnedPads = function (account) {
@ -2257,24 +2290,15 @@ const factory = (Sortify, UserObject, ProxyManager,
}
let n = nThen;
const opts = {
network: store.network
};
Object.keys(all).forEach(chan => {
n = n(waitFor => {
const data = all[chan];
const href = data.href;
opts.password = data.password;
const parsed = Hash.parsePadUrl(href);
Cryptget.get(parsed.hash, waitFor((err, content) => {
getRtChannelFromPad(data, waitFor((err, rtChannel) => {
if (err) { return; }
const p = Util.tryParse(content);
const rtChannel = p?.content?.channel;
if (!rtChannel) { return; }
data.list.forEach(proxy => {
proxy.rtChannel = rtChannel;
});
}), opts);
}));
}).nThen;
});
n(() => {

File diff suppressed because one or more lines are too long