Fix /collapse and /expand from interacting with the server in public mode (#4488)

Reported by xnaas on IRC
This commit is contained in:
Max Leiter 2022-02-18 12:21:17 -08:00 committed by GitHub
parent 66455f2c40
commit 551f85ea51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 33 deletions

View file

@ -22,7 +22,7 @@ function input() {
} }
// Tell the server we're toggling so it remembers at page reload // Tell the server we're toggling so it remembers at page reload
if (messageIds.length > 0) { if (!document.body.classList.contains("public") && messageIds.length > 0) {
socket.emit("msg:preview:toggle", { socket.emit("msg:preview:toggle", {
target: store.state.activeChannel.channel.id, target: store.state.activeChannel.channel.id,
messageIds: messageIds, messageIds: messageIds,

View file

@ -22,7 +22,7 @@ function input() {
} }
// Tell the server we're toggling so it remembers at page reload // Tell the server we're toggling so it remembers at page reload
if (messageIds.length > 0) { if (!document.body.classList.contains("public") && messageIds.length > 0) {
socket.emit("msg:preview:toggle", { socket.emit("msg:preview:toggle", {
target: store.state.activeChannel.channel.id, target: store.state.activeChannel.channel.id,
messageIds: messageIds, messageIds: messageIds,

View file

@ -503,43 +503,49 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
); );
}); });
socket.on("msg:preview:toggle", (data) => { // In public mode only one client can be connected,
if (!_.isPlainObject(data)) { // so there's no need to handle msg:preview:toggle
return; if (!Helper.config.public) {
} socket.on("msg:preview:toggle", (data) => {
if (_.isPlainObject(data)) {
const networkAndChan = client.find(data.target); return;
const newState = Boolean(data.shown);
if (!networkAndChan) {
return;
}
// Process multiple message at once for /collapse and /expand commands
if (Array.isArray(data.messageIds)) {
for (const msgId of data.messageIds) {
const message = networkAndChan.chan.findMessage(msgId);
for (const preview of message.previews) {
preview.shown = newState;
}
} }
return; const networkAndChan = client.find(data.target);
} const newState = Boolean(data.shown);
const message = networkAndChan.chan.findMessage(data.msgId); if (!networkAndChan) {
return;
}
if (!message) { // Process multiple message at once for /collapse and /expand commands
return; if (Array.isArray(data.messageIds)) {
} for (const msgId of data.messageIds) {
const message = networkAndChan.chan.findMessage(msgId);
const preview = message.findPreview(data.link); if (message) {
for (const preview of message.previews) {
preview.shown = newState;
}
}
}
if (preview) { return;
preview.shown = newState; }
}
}); const message = networkAndChan.chan.findMessage(data.msgId);
if (!message) {
return;
}
const preview = message.findPreview(data.link);
if (preview) {
preview.shown = newState;
}
});
}
socket.on("mentions:get", () => { socket.on("mentions:get", () => {
socket.emit("mentions:list", client.mentions); socket.emit("mentions:list", client.mentions);