From cb4d254099cf846f918214c2be07341d93d90900 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 19 Apr 2026 17:05:44 -0500 Subject: Remove Docker volume, create app directory in entrypoint script --- Dockerfile | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 94b3d4b5..de081302 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,13 +57,9 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ RUN groupadd -o -g 1000 slskd && \ useradd -o -u 1000 -g slskd slskd -RUN bash -c 'mkdir -p /app \ - && chown -R slskd:slskd /app \ - && mkdir -p /.net \ +RUN bash -c 'mkdir -p /.net \ && chmod 777 /.net' -VOLUME /app - HEALTHCHECK --interval=60s --timeout=3s --start-period=60m --retries=3 CMD wget -q -O - http://localhost:${SLSKD_HTTP_PORT}/health ENV SHELL=/usr/bin/bash \ @@ -116,14 +112,22 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi - # exit if /app is not writable; we can't fix this because we lack permissions - if [ ! -r /app ] || [ ! -w /app ]; then - echo "ERROR: /app is not readable and/or writable by the current user ($(id -u):$(id -g)); currently owned by owned by $(stat -c '%U:%G (%u:%g)' /app)." + # attempt to create the app dir; swallow the error if it fails, we'll give the user an informative message below + if [ ! -d "${SLSKD_APP_DIR}" ]; then + mkdir -p "${SLSKD_APP_DIR}" 2>/dev/null || true + fi + + # exit if app dir is not writable; we can't fix this because we lack permissions + if [ ! -r "${SLSKD_APP_DIR}" ] || [ ! -w "${SLSKD_APP_DIR}" ]; then + echo "ERROR: ${SLSKD_APP_DIR} is not readable and/or writable by the current user ($(id -u):$(id -g)); currently owned by $(stat -c '%U:%G (%u:%g)' ${SLSKD_APP_DIR})." echo "To fix: chown -R $(id -u):$(id -g) /path/to/your/mounted/app/directory" exit 1 fi - # should be good to go; set umask and launch + if ! mountpoint -q "${SLSKD_APP_DIR}"; then + echo "WARNING: ${SLSKD_APP_DIR} is not a bind mount or volume. Configuration and data will be lost if the container is removed." + fi + umask "$SLSKD_UMASK" exec "$@" fi @@ -131,11 +135,19 @@ fi # no --user supplied, neither PUID nor PGID supplied, run as root (same behavior as < 0.25.0) #--------------------------------------------------------------------------------------- if [ -z "${PUID}" ] && [ -z "${PGID}" ]; then + # create app dir as root, if it doesn't exist + # no need to change the owner of anything; we can write + mkdir -p "${SLSKD_APP_DIR}" + + if ! mountpoint -q "${SLSKD_APP_DIR}"; then + echo "WARNING: ${SLSKD_APP_DIR} is not a bind mount or volume. Configuration and data will be lost if the container is removed." + fi + umask "$SLSKD_UMASK" exec "$@" fi -# PUID/PGID mode; user has provided explicit user and group IDs to use +# PUID/PGID mode; user has provided explicit user and/or group IDs to use #--------------------------------------------------------------------------------------- PUID="${PUID:-1000}" PGID="${PGID:-1000}" @@ -160,14 +172,20 @@ if [ "$(id -u slskd)" != "$PUID" ] || [ "$(id -g slskd)" != "$PGID" ]; then usermod -o -u "$PUID" -g "$PGID" slskd fi -# change owner of the the /app directory if it isn't correct +# create app dir as root, if it doesn't exist +mkdir -p "${SLSKD_APP_DIR}" + +if ! mountpoint -q "${SLSKD_APP_DIR}"; then + echo "WARNING: ${SLSKD_APP_DIR} is not a bind mount or volume. Configuration and data will be lost if the container is removed." +fi + +# change owner of the the app directory if it isn't correct # we're not checking anything other than the root, and we're not recursively # applying the changes, which might be dangerous/unwanted and/or take forever -if [ "$(stat -c '%u:%g' /app)" != "${PUID}:${PGID}" ]; then - chown "${PUID}:${PGID}" /app +if [ "$(stat -c '%u:%g' "${SLSKD_APP_DIR}")" != "${PUID}:${PGID}" ]; then + chown "${PUID}:${PGID}" "${SLSKD_APP_DIR}" fi -# set umask and launch umask "$SLSKD_UMASK" exec gosu "${PUID}:${PGID}" "$@" -- cgit v1.2.3 From 300363d8aa1c2314641d374a4a5a7facc5b6b7aa Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 25 Apr 2026 18:53:29 -0500 Subject: map ipv6-mapped ipv4 IPs back to ipv4 before checking them against configured CIDR --- src/slskd/Relay/API/Hubs/RelayHub.cs | 42 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/slskd/Relay/API/Hubs/RelayHub.cs b/src/slskd/Relay/API/Hubs/RelayHub.cs index 53e2830f..8430164c 100644 --- a/src/slskd/Relay/API/Hubs/RelayHub.cs +++ b/src/slskd/Relay/API/Hubs/RelayHub.cs @@ -109,7 +109,6 @@ namespace slskd.Relay private IOptionsMonitor OptionsMonitor { get; } private OptionsAtStartup OptionsAtStartup { get; } private RelayMode OperationMode => OptionsAtStartup.Relay.Mode.ToEnum(); - private IPAddress RemoteIpAddress => Context.Features.Get().RemoteIpAddress; /// /// Executed when a new connection is established. @@ -119,13 +118,13 @@ namespace slskd.Relay { if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Controller, RelayMode.Debug }.Contains(OperationMode)) { - Log.Debug("Agent connection {Id} from {IP} aborted; Relay is not enabled, or is not in Controller mode", Context.ConnectionId, RemoteIpAddress); + Log.Debug("Agent connection {Id} from {IP} aborted; Relay is not enabled, or is not in Controller mode", Context.ConnectionId, GetRemoteIPAddress()); Context.Abort(); } var token = Relay.GenerateAuthenticationChallengeToken(Context.ConnectionId); - Log.Information("Agent connection {Id} from {IP} established. Sending authentication challenge {Token}...", Context.ConnectionId, RemoteIpAddress, token); + Log.Information("Agent connection {Id} from {IP} established. Sending authentication challenge {Token}...", Context.ConnectionId, GetRemoteIPAddress(), token); await Clients.Caller.Challenge(token); } @@ -138,7 +137,7 @@ namespace slskd.Relay { if (Relay.TryDeregisterAgent(Context.ConnectionId, out var record)) { - Log.Warning("Agent {Agent} (connection {Id}) from {IP} disconnected", record.Agent.Name, Context.ConnectionId, RemoteIpAddress); + Log.Warning("Agent {Agent} (connection {Id}) from {IP} disconnected", record.Agent.Name, Context.ConnectionId, GetRemoteIPAddress()); Relay.TryDeregisterAgent(record.Agent.Name, out _); } @@ -170,23 +169,25 @@ namespace slskd.Relay return false; } + var remoteIP = GetRemoteIPAddress(); + if (!TryGetAgentConfig(agent, out var agentOptions)) { - Log.Warning("Unauthorized login attempt from unknown Agent {Agent} (connection {Id}) from {IP}", agent, Context.ConnectionId, RemoteIpAddress); + Log.Warning("Unauthorized login attempt from unknown Agent {Agent} (connection {Id}) from {IP}", agent, Context.ConnectionId, remoteIP); throw new UnauthorizedAccessException(); } if (!agentOptions.Cidr.Split(',') .Select(cidr => IPAddressRange.Parse(cidr)) - .Any(range => range.Contains(RemoteIpAddress))) + .Any(range => range.Contains(remoteIP))) { - Log.Warning("Unauthorized login attempt by Agent {Agent} (connection {Id}); remote IP address {IP} is not within the configured range {CIDR}", agent, Context.ConnectionId, RemoteIpAddress, agentOptions.Cidr); + Log.Warning("Unauthorized login attempt by Agent {Agent} (connection {Id}); remote IP address {IP} is not within the configured range {CIDR}", agent, Context.ConnectionId, remoteIP, agentOptions.Cidr); throw new UnauthorizedAccessException(); } if (!Relay.TryValidateAuthenticationCredential(Context.ConnectionId, agent, challengeResponse)) { - Log.Warning("Unauthorized login attempt by Agent {Agent} (connection {Id}) from {IP}; authentication failed", agent, Context.ConnectionId, RemoteIpAddress); + Log.Warning("Unauthorized login attempt by Agent {Agent} (connection {Id}) from {IP}; authentication failed", agent, Context.ConnectionId, remoteIP); Relay.TryDeregisterAgent(Context.ConnectionId, out var _); // just in case! throw new UnauthorizedAccessException(); } @@ -208,12 +209,12 @@ namespace slskd.Relay if (!Relay.TryGetAgentRegistration(Context.ConnectionId, out var record)) { // this can happen if the agent attempts to upload before logging in - Log.Information("Agent connection {Id} from {IP} requested a share upload token, but is not registered.", Context.ConnectionId, RemoteIpAddress); + Log.Information("Agent connection {Id} from {IP} requested a share upload token, but is not registered.", Context.ConnectionId, GetRemoteIPAddress()); throw new UnauthorizedAccessException(); } var token = Relay.GenerateShareUploadToken(record.Agent.Name); - Log.Information("Agent {Agent} (connection {Id}) from {IP} requested share upload token {Token}", record.Agent.Name, record.ConnectionId, RemoteIpAddress, token); + Log.Information("Agent {Agent} (connection {Id}) from {IP} requested share upload token {Token}", record.Agent.Name, record.ConnectionId, GetRemoteIPAddress(), token); return token; } @@ -227,11 +228,11 @@ namespace slskd.Relay { if (!Relay.TryGetAgentRegistration(Context.ConnectionId, out var record)) { - Log.Warning("Agent connection {Id} from {IP} attempted to report a failed upload, but is not registered.", Context.ConnectionId, RemoteIpAddress); + Log.Warning("Agent connection {Id} from {IP} attempted to report a failed upload, but is not registered.", Context.ConnectionId, GetRemoteIPAddress()); throw new UnauthorizedAccessException(); } - Log.Warning("Agent {Agent} (connection {ConnectionId}) from {IP} reported upload failure for {Id}: {Message}", record.Agent, Context.ConnectionId, RemoteIpAddress, id, exception.Message); + Log.Warning("Agent {Agent} (connection {ConnectionId}) from {IP} reported upload failure for {Id}: {Message}", record.Agent, Context.ConnectionId, GetRemoteIPAddress(), id, exception.Message); Relay.NotifyFileStreamException(record.Agent.Name, id, exception); } @@ -247,13 +248,26 @@ namespace slskd.Relay { if (!Relay.TryGetAgentRegistration(Context.ConnectionId, out var record)) { - Log.Warning("Agent connection {Id} from {IP} attempted to return file information, but is not registered.", Context.ConnectionId, RemoteIpAddress); + Log.Warning("Agent connection {Id} from {IP} attempted to return file information, but is not registered.", Context.ConnectionId, GetRemoteIPAddress()); throw new UnauthorizedAccessException(); } - Log.Information("Agent {Agent} (connection {ConnectionId}) from {IP} returned file info for {Id}; exists: {Exists}, length: {Length}", record.Agent.Name, Context.ConnectionId, RemoteIpAddress, id, exists, length); + Log.Information("Agent {Agent} (connection {ConnectionId}) from {IP} returned file info for {Id}; exists: {Exists}, length: {Length}", record.Agent.Name, Context.ConnectionId, GetRemoteIPAddress(), id, exists, length); Relay.HandleFileInfoResponse(record.Agent.Name, id, (exists, length)); } + + private IPAddress GetRemoteIPAddress() + { + var ip = Context.Features.Get().RemoteIpAddress; + + // looks like '::ffff:127.0.0.1'; not compatible with CIDR.Contains(), so convert it back to IPv4 + if (ip.IsIPv4MappedToIPv6) + { + ip = ip.MapToIPv4(); + } + + return ip; + } } } \ No newline at end of file -- cgit v1.2.3 From 38c821d0eb5f22c30ca9be8f24e452f5ce0b83ca Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 25 Apr 2026 18:53:51 -0500 Subject: don't log share upload success on failure --- src/slskd/Relay/RelayClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs index 6fb2f360..de6edcf7 100644 --- a/src/slskd/Relay/RelayClient.cs +++ b/src/slskd/Relay/RelayClient.cs @@ -532,6 +532,8 @@ namespace slskd.Relay Log.Information("Uploading shares..."); await UploadSharesAsync(); + + Log.Information("Shares uploaded. Ready to relay files."); } catch (Exception ex) { @@ -542,8 +544,6 @@ namespace slskd.Relay await StopAsync(); _ = StartAsync(); } - - Log.Information("Shares uploaded. Ready to relay files."); } private Task HubConnection_Reconnecting(Exception arg) -- cgit v1.2.3 From 3b9d14bf6f128d771149f6589f345967aea5dc4d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 25 Apr 2026 18:54:10 -0500 Subject: don't try to catch typed exceptions from hub invocations --- src/slskd/Relay/RelayClient.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs index de6edcf7..9aec7b00 100644 --- a/src/slskd/Relay/RelayClient.cs +++ b/src/slskd/Relay/RelayClient.cs @@ -362,11 +362,6 @@ namespace slskd.Relay LoggedInTaskCompletionSource.TrySetResult(); } - catch (UnauthorizedAccessException) - { - await HubConnection.StopAsync(); - Log.Error("Relay controller authentication failed. Check configuration."); - } catch (Exception ex) { Log.Error(ex, "Failed to handle authentication challenge: {Message}", ex.Message); -- cgit v1.2.3 From acbfa366baa274c04499e835f469168477e387af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 03:42:48 +0000 Subject: Bump follow-redirects from 1.15.11 to 1.16.0 in /src/web Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.11 to 1.16.0. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.11...v1.16.0) --- updated-dependencies: - dependency-name: follow-redirects dependency-version: 1.16.0 dependency-type: indirect ... Signed-off-by: dependabot[bot] --- src/web/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/web/package-lock.json b/src/web/package-lock.json index f309d9af..22d9c714 100644 --- a/src/web/package-lock.json +++ b/src/web/package-lock.json @@ -10906,9 +10906,9 @@ "license": "ISC" }, "node_modules/follow-redirects": { - "version": "1.15.11", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz", - "integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==", + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", + "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==", "funding": [ { "type": "individual", -- cgit v1.2.3 From 50608eb15eaed8c951eed0599be28df2821c79b3 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 2 May 2026 10:01:34 -0500 Subject: Fix formatting issues in FORKING.md --- FORKING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FORKING.md b/FORKING.md index 5b76f580..6b9aaa28 100644 --- a/FORKING.md +++ b/FORKING.md @@ -6,7 +6,7 @@ The requirements exist for two reasons, and both are about the people who use th The first is to make sure users always know they are using software licensed under the AGPL. That matters because the AGPL gives users meaningful rights: the right to know that the source code exists, the right to access it, and the right to understand what they are running. Those rights only mean something if users are actually informed of them. Requiring that the full LICENSE be included with every distribution, and that license notices be preserved everywhere they appear, ensures that no user ever ends up with a copy of this software that hides or obscures the terms under which it was released. -The second is to make sure users understand who made the software they are using. They should be able to tell where it came from, who maintains it, what has been changed and by whom, and whether it is the original project or a fork. A user who installs a fork deserves to know it is a fork. The requirements around naming, branding, source file headers, and identification notices all serve this goal. They are not intended to discourage forking — they are intended to make sure that anyone who uses a fork has an accurate picture of what they have. +The second is to make sure users understand who made the software they are using. They should be able to tell where it came from, who maintains it, what has been changed and by whom, and whether it is the original project or a fork. A user who installs a fork deserves to know it is a fork. The requirements around naming, branding, source file headers, and identification notices all serve this goal. They are not intended to discourage forking, they are intended to make sure that anyone who uses a fork has an accurate picture of what they have. Read the LICENSE in full. This document is a plain-language guide, not a substitute for it. -- cgit v1.2.3 From 8ddc38f768e18a7c72a3b904446fdb01835092bd Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 10:04:14 -0500 Subject: disable weird rule --- src/web/.eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/web/.eslintrc.js b/src/web/.eslintrc.js index 0c36e3ed..81d1001c 100644 --- a/src/web/.eslintrc.js +++ b/src/web/.eslintrc.js @@ -5,6 +5,7 @@ const overrides = { 'no-eq-null': 'off', // noisy 'react/forbid-component-props': 'off', // noisy 'react/prop-types': 'off', // noisy + 'canonical/sort-keys': 'off', // noisy 'unicorn/no-array-reduce': 'off', // noisy }; -- cgit v1.2.3 From 8a22018aefbb89d1b74788a0d6bda97b0d8da6b0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 10:05:03 -0500 Subject: use state for message input instead of dom ref (causing delay in updates) --- src/web/src/components/Chat/Chat.jsx | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 23619bd1..9e3605b8 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -20,6 +20,7 @@ const initialState = { conversations: {}, interval: undefined, loading: false, + message: '', }; class Chat extends Component { @@ -106,21 +107,15 @@ class Chat extends Component { await chat.acknowledge({ username }); }; - sendMessage = async (username, message) => { - if (!username || !message || username === '') return; - await chat.send({ message, username }); - }; - sendReply = async () => { - const { active } = this.state; - const message = this.messageRef.current.value; + const { active, message } = this.state; if (!this.validInput()) { return; } - await this.sendMessage(active, message); - this.messageRef.current.value = ''; + await chat.send({ username: active, message }); + this.setState({ message: '' }); // force a refresh to append the message // we could probably do this in the browser but we can be lazy @@ -129,12 +124,7 @@ class Chat extends Component { validInput = () => (this.state.active || '').length > 0 && - ( - (this.messageRef && - this.messageRef.current && - this.messageRef.current.value) || - '' - ).length > 0; + (this.state.message || '').length > 0; focusInput = () => { this.messageRef.current.focus(); @@ -294,7 +284,7 @@ class Chat extends Component { name="send" /> ), - onClick: this.sendMessage, + onClick: this.sendReply, }} fluid input={ @@ -302,7 +292,11 @@ class Chat extends Component { autoComplete="off" data-lpignore="true" id="chat-message-input" + onChange={(event) => + this.setState({ message: event.target.value }) + } type="text" + value={this.state.message} /> } onKeyUp={(event) => -- cgit v1.2.3 From e70664167d1766b63a12fa1833b452a217e8b6cc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 10:05:18 -0500 Subject: focus input when conversation is loaded --- src/web/src/components/Chat/Chat.jsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 9e3605b8..0a080466 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -170,6 +170,12 @@ class Chat extends Component { } catch { // no-op } + + try { + this.messageRef.current.focus(); + } catch { + // no-op + } }, ); }, -- cgit v1.2.3 From 402b4d7509c582bd2d93e73a33778068e660259e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 11:09:33 -0500 Subject: use state instead of dom ref for rooms --- src/web/src/components/Rooms/Rooms.jsx | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index 0f2e4382..d30828eb 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -32,6 +32,7 @@ const initialState = { }, joined: [], loading: false, + message: '', room: { messages: [], users: [], @@ -131,6 +132,12 @@ class Rooms extends Component { } catch { // no-op } + + try { + this.messageRef.current.focus(); + } catch { + // no-op + } }); }, ); @@ -150,12 +157,7 @@ class Rooms extends Component { validInput = () => (this.state.active || '').length > 0 && - ( - (this.messageRef && - this.messageRef.current && - this.messageRef.current.value) || - '' - ).length > 0; + (this.state.message || '').length > 0; focusInput = () => { this.messageRef.current.focus(); @@ -174,15 +176,14 @@ class Rooms extends Component { }; sendMessage = async () => { - const { active } = this.state; - const message = this.messageRef.current.value; + const { active, message } = this.state; if (!this.validInput()) { return; } await rooms.sendMessage({ message, roomName: active }); - this.messageRef.current.value = ''; + this.setState({ message: '' }); }; handleContextMenu = (clickEvent, message) => { @@ -207,8 +208,12 @@ class Rooms extends Component { }; handleReply = () => { - this.messageRef.current.value = `[${this.state.contextMenu.message.username}] ${this.state.contextMenu.message.message} --> `; - this.focusInput(); + this.setState( + (previousState) => ({ + message: `[${previousState.contextMenu.message.username}] ${previousState.contextMenu.message.message} --> `, + }), + () => this.focusInput(), + ); }; handleUserProfile = () => { @@ -364,7 +369,11 @@ class Rooms extends Component { autoComplete="off" data-lpignore="true" id="room-message-input" + onChange={(event) => + this.setState({ message: event.target.value }) + } type="text" + value={this.state.message} /> } onKeyUp={(event) => -- cgit v1.2.3 From a232848ee4f5539b0041e3581705edd00aec80f0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 13:27:20 -0500 Subject: clear any captured message when changing room/conversation --- src/web/src/components/Chat/Chat.jsx | 1 + src/web/src/components/Rooms/Rooms.jsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 0a080466..72960129 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -147,6 +147,7 @@ class Chat extends Component { { active: username, loading: true, + message: '', }, async () => { const { active, conversations } = this.state; diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index d30828eb..0b1366fd 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -118,6 +118,7 @@ class Rooms extends Component { { active: roomName, loading: true, + message: '', room: initialState.room, }, async () => { -- cgit v1.2.3 From 9a7556a9c9b3c1313f11f369d8b38ad8fe144b58 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 13:30:50 -0500 Subject: don't clear the message if the same room/convo is re-selected Co-authored-by: Copilot --- src/web/src/components/Chat/Chat.jsx | 6 +++--- src/web/src/components/Rooms/Rooms.jsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 72960129..086d2cd8 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -144,11 +144,11 @@ class Chat extends Component { selectConversation = (username) => { this.setState( - { + (previousState) => ({ active: username, loading: true, - message: '', - }, + message: previousState.active === username ? previousState.message : '', + }), async () => { const { active, conversations } = this.state; diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index 0b1366fd..3d29242b 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -115,12 +115,12 @@ class Rooms extends Component { selectRoom = async (roomName) => { this.setState( - { + (previousState) => ({ active: roomName, loading: true, - message: '', + message: previousState.active === roomName ? previousState.message : '', room: initialState.room, - }, + }), async () => { const { active } = this.state; -- cgit v1.2.3 From 9ad8b004544e9edcf5141f536bb6be99b49dba51 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 13:51:20 -0500 Subject: memoize history Co-authored-by: Copilot --- src/web/src/components/Chat/Chat.jsx | 58 ++++++++++++++++++++++------------ src/web/src/components/Rooms/Rooms.jsx | 58 ++++++++++++++++++++-------------- 2 files changed, 73 insertions(+), 43 deletions(-) diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 086d2cd8..39dd1a44 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -23,6 +23,32 @@ const initialState = { message: '', }; +const ChatMessageHistory = React.memo( + ({ formatTimestamp, messages, selfUsername }) => { + return ( + <> + {messages.map((message) => ( + + + {formatTimestamp(message.timestamp)} + + + {message.direction === 'Out' ? selfUsername : message.username}: + + {message.message} + + ))} + + + ); + }, +); + +ChatMessageHistory.displayName = 'ChatMessageHistory'; + class Chat extends Component { constructor(props) { super(props); @@ -63,6 +89,13 @@ class Chat extends Component { // fetch all of the active conversations (but no messages) let conversations = await chat.getAll(); + // the username '..' breaks nearly everything in slskd because it's a path traversal + // sequence and no API endpoints that expect usernames in the path work + // rather than letting this sit broken, i'm making the choice to filter it out + // eslint-disable-next-line no-warning-comments + // todo: remove this filter when the API can handle '..' + conversations = conversations.filter((f) => f.username !== '..'); + // turn into a map, keyed by username // if there are no active conversations, set to an empty map if (conversations.length === 0) { @@ -257,26 +290,11 @@ class Chat extends Component { - {messages.map((message) => ( - - - {this.formatTimestamp(message.timestamp)} - - - {message.direction === 'Out' - ? user.username - : message.username} - :{' '} - - - {message.message} - - - ))} - + diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index 3d29242b..f6bdb685 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -39,6 +39,36 @@ const initialState = { }, }; +const RoomMessageHistory = React.memo( + ({ formatTimestamp, messages, onHandleContextMenu }) => { + return ( + <> + {messages.map((message) => ( +
+ onHandleContextMenu(clickEvent, message) + } + > + + + {formatTimestamp(message.timestamp)} + + {message.username}: + {message.message} + +
+ ))} + + + ); + }, +); + +RoomMessageHistory.displayName = 'RoomMessageHistory'; + class Rooms extends Component { constructor(props) { super(props); @@ -325,29 +355,11 @@ class Rooms extends Component { - {room.messages.map((message) => ( -
- this.handleContextMenu(clickEvent, message) - } - > - - - {this.formatTimestamp(message.timestamp)} - - - {message.username}:{' '} - - - {message.message} - - -
- ))} - +
-- cgit v1.2.3