From 865187a892e0201a25bd1ea8b825d4e98da104a3 Mon Sep 17 00:00:00 2001 From: samhatter Date: Sat, 22 Feb 2025 22:23:49 -0800 Subject: Adding context menu to rooms with reply, view user profile, and browse shares --- src/web/src/components/Browse/Browse.jsx | 18 +++-- src/web/src/components/Rooms/Rooms.css | 6 ++ src/web/src/components/Rooms/Rooms.jsx | 118 +++++++++++++++++++++++++++---- src/web/src/components/Users/Users.jsx | 5 +- 4 files changed, 127 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Browse/Browse.jsx b/src/web/src/components/Browse/Browse.jsx index 75c8fb53..d5e16cb3 100644 --- a/src/web/src/components/Browse/Browse.jsx +++ b/src/web/src/components/Browse/Browse.jsx @@ -6,6 +6,7 @@ import Directory from './Directory'; import DirectoryTree from './DirectoryTree'; import * as lzString from 'lz-string'; import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; import { Card, Icon, Input, Loader, Segment } from 'semantic-ui-react'; const initialState = { @@ -42,6 +43,9 @@ class Browse extends Component { }, () => this.saveState(), ); + if (this.props.location.state?.user) { + this.setState({ username: this.props.location.state.user }, this.browse); + } document.addEventListener('keyup', this.keyUp, false); } @@ -150,11 +154,13 @@ class Browse extends Component { loadState = () => { this.setState( - JSON.parse( - lzString.decompress( - localStorage.getItem('soulseek-example-browse-state') || '', - ), - ) || initialState, + (!this.props.location.state?.user && + JSON.parse( + lzString.decompress( + localStorage.getItem('soulseek-example-browse-state') || '', + ), + )) || + initialState, ); }; @@ -351,4 +357,4 @@ class Browse extends Component { } } -export default Browse; +export default withRouter(Browse); diff --git a/src/web/src/components/Rooms/Rooms.css b/src/web/src/components/Rooms/Rooms.css index e001d6ea..62bd45e6 100644 --- a/src/web/src/components/Rooms/Rooms.css +++ b/src/web/src/components/Rooms/Rooms.css @@ -1,3 +1,9 @@ +.popup-menu { + overflow-y: auto; + position: fixed; + z-index: 1000; +} + .rooms { padding-left: 15px; padding-right: 15px; diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index 54e67d3c..0f2e4382 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -4,19 +4,28 @@ import PlaceholderSegment from '../Shared/PlaceholderSegment'; import RoomMenu from './RoomMenu'; import RoomUserList from './RoomUserList'; import React, { Component, createRef } from 'react'; +import { withRouter } from 'react-router-dom'; import { + Button, Card, Dimmer, Icon, Input, List, Loader, + Portal, Ref, Segment, } from 'semantic-ui-react'; const initialState = { active: '', + contextMenu: { + message: null, + open: false, + x: 0, + y: 0, + }, intervals: { messages: undefined, rooms: undefined, @@ -48,6 +57,7 @@ class Rooms extends Component { async () => { await this.fetchJoinedRooms(); this.selectRoom(this.state.active || this.getFirstRoom()); + document.addEventListener('click', this.handleCloseContextMenu); }, ); } @@ -59,6 +69,8 @@ class Rooms extends Component { clearInterval(roomsInterval); clearInterval(messagesInterval); + document.removeEventListener('click', this.handleCloseContextMenu); + this.setState({ intervals: initialState.intervals }); } @@ -173,6 +185,79 @@ class Rooms extends Component { this.messageRef.current.value = ''; }; + handleContextMenu = (clickEvent, message) => { + clickEvent.preventDefault(); + this.setState({ + contextMenu: { + message, + open: true, + x: clickEvent.pageX, + y: clickEvent.pageY, + }, + }); + }; + + handleCloseContextMenu = () => { + this.setState((previousState) => ({ + contextMenu: { + ...previousState.contextMenu, + open: false, + }, + })); + }; + + handleReply = () => { + this.messageRef.current.value = `[${this.state.contextMenu.message.username}] ${this.state.contextMenu.message.message} --> `; + this.focusInput(); + }; + + handleUserProfile = () => { + this.props.history.push('/users', { + user: this.state.contextMenu.message.username, + }); + }; + + handleBrowseShares = () => { + this.props.history.push('/browse', { + user: this.state.contextMenu.message.username, + }); + }; + + renderContextMenu() { + const { contextMenu } = this.state; + return ( + +
+ + + +
+
+ ); + } + render() { const { active = [], joined = [], loading, room } = this.state; @@ -235,20 +320,26 @@ class Rooms extends Component { {room.messages.map((message) => ( - + this.handleContextMenu(clickEvent, message) + } > - - {this.formatTimestamp(message.timestamp)} - - - {message.username}:{' '} - - - {message.message} - - + + + {this.formatTimestamp(message.timestamp)} + + + {message.username}:{' '} + + + {message.message} + + + ))} @@ -295,9 +386,10 @@ class Rooms extends Component { )} + {this.renderContextMenu()} ); } } -export default Rooms; +export default withRouter(Rooms); diff --git a/src/web/src/components/Users/Users.jsx b/src/web/src/components/Users/Users.jsx index e7f279ea..55dc1047 100644 --- a/src/web/src/components/Users/Users.jsx +++ b/src/web/src/components/Users/Users.jsx @@ -4,9 +4,11 @@ import * as users from '../../lib/users'; import PlaceholderSegment from '../Shared/PlaceholderSegment'; import User from './User'; import React, { useEffect, useLayoutEffect, useRef, useState } from 'react'; +import { useLocation } from 'react-router-dom'; import { Icon, Input, Item, Loader, Segment } from 'semantic-ui-react'; const Users = () => { + const location = useLocation(); const inputRef = useRef(); const [user, setUser] = useState(); const [usernameInput, setUsernameInput] = useState(); @@ -42,7 +44,8 @@ const Users = () => { useEffect(() => { document.addEventListener('keyup', keyUp, false); - const storedUsername = localStorage.getItem(activeUserInfoKey); + const storedUsername = + location.state?.user || localStorage.getItem(activeUserInfoKey); if (storedUsername !== undefined) { setSelectedUsername(storedUsername); -- cgit v1.2.3 From 71fe0a4a578fdd9f0945923eb655ddf2a546f1db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 23 Feb 2025 19:39:31 +0000 Subject: Bump serialize-javascript from 6.0.1 to 6.0.2 in /src/web Bumps [serialize-javascript](https://github.com/yahoo/serialize-javascript) from 6.0.1 to 6.0.2. - [Release notes](https://github.com/yahoo/serialize-javascript/releases) - [Commits](https://github.com/yahoo/serialize-javascript/compare/v6.0.1...v6.0.2) --- updated-dependencies: - dependency-name: serialize-javascript dependency-type: indirect ... Signed-off-by: dependabot[bot] --- src/web/package-lock.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/web/package-lock.json b/src/web/package-lock.json index 912ea6e9..a61bca8f 100644 --- a/src/web/package-lock.json +++ b/src/web/package-lock.json @@ -18432,10 +18432,11 @@ "dev": true }, "node_modules/serialize-javascript": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.1.tgz", - "integrity": "sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", + "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "randombytes": "^2.1.0" } -- cgit v1.2.3 From 8dddf66d1372d913ac81374af0a0e0b47e49b157 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 12 Mar 2025 18:40:15 -0500 Subject: unimportant tweak --- src/slskd/Search/API/Controllers/SearchesController.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Search/API/Controllers/SearchesController.cs b/src/slskd/Search/API/Controllers/SearchesController.cs index 58e1fe37..1d00b482 100644 --- a/src/slskd/Search/API/Controllers/SearchesController.cs +++ b/src/slskd/Search/API/Controllers/SearchesController.cs @@ -82,6 +82,7 @@ namespace slskd.Search.API try { search = await Searches.StartAsync(id, SearchQuery.FromText(request.SearchText), SearchScope.Network, request.ToSearchOptions()); + return Ok(search); } catch (Exception ex) when (ex is ArgumentException || ex is Soulseek.DuplicateTokenException) { @@ -98,8 +99,6 @@ namespace slskd.Search.API Log.Error(ex, "Failed to execute search {Search}: {Message}", request, ex.Message); return StatusCode(500, ex.Message); } - - return Ok(search); } /// -- cgit v1.2.3 From 3fa9c6f1a0ae11a45475e7681372154a23a844f3 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 13 Mar 2025 17:46:36 -0500 Subject: move setup into try --- src/slskd/Search/SearchService.cs | 64 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs index b4864918..e0466043 100644 --- a/src/slskd/Search/SearchService.cs +++ b/src/slskd/Search/SearchService.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -239,41 +239,41 @@ namespace slskd.Search StartedAt = DateTime.UtcNow, }; - using var context = ContextFactory.CreateDbContext(); - context.Add(search); - context.SaveChanges(); + try + { + using var context = ContextFactory.CreateDbContext(); + context.Add(search); + context.SaveChanges(); - await SearchHub.BroadcastCreateAsync(search); + await SearchHub.BroadcastCreateAsync(search); - // initialize the list of responses that we'll use to accumulate them - // populated by the responseHandler we pass to SearchAsync - List responses = new(); + // initialize the list of responses that we'll use to accumulate them + // populated by the responseHandler we pass to SearchAsync + List responses = new(); - options ??= new SearchOptions(); - options = options.WithActions( - stateChanged: (args) => - { - search = search.WithSoulseekSearch(args.Search); - SearchHub.BroadcastUpdateAsync(search); - Update(search); - }, - responseReceived: (args) => rateLimiter.Invoke(() => - { - // note: this is rate limited, but has the potential to update the database every 250ms (or whatever the - // interval is set to) for the duration of the search. any issues with disk i/o or performance while searches - // are running should investigate this as a cause - search.ResponseCount = args.Search.ResponseCount; - search.FileCount = args.Search.FileCount; - search.LockedFileCount = args.Search.LockedFileCount; - - // note that we're not actually doing anything with the response here, that's happening in the - // response handler. we're only updating counts here. - SearchHub.BroadcastUpdateAsync(search); - Update(search); - })); + options ??= new SearchOptions(); + options = options.WithActions( + stateChanged: (args) => + { + search = search.WithSoulseekSearch(args.Search); + SearchHub.BroadcastUpdateAsync(search); + Update(search); + }, + responseReceived: (args) => rateLimiter.Invoke(() => + { + // note: this is rate limited, but has the potential to update the database every 250ms (or whatever the + // interval is set to) for the duration of the search. any issues with disk i/o or performance while searches + // are running should investigate this as a cause + search.ResponseCount = args.Search.ResponseCount; + search.FileCount = args.Search.FileCount; + search.LockedFileCount = args.Search.LockedFileCount; + + // note that we're not actually doing anything with the response here, that's happening in the + // response handler. we're only updating counts here. + SearchHub.BroadcastUpdateAsync(search); + Update(search); + })); - try - { // initiate the search. this can throw at invocation if there's a problem with // the client state (e.g. disconnected) or a problem with the search (e.g. no terms) var soulseekSearchTask = Client.SearchAsync( -- cgit v1.2.3 From 45c5bd50b0f3d406ea0fb535ab3ff488e6ea8c2f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 13 Mar 2025 17:50:13 -0500 Subject: track progress, undo properly --- src/slskd/Search/SearchService.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs index e0466043..20f9255f 100644 --- a/src/slskd/Search/SearchService.cs +++ b/src/slskd/Search/SearchService.cs @@ -239,14 +239,21 @@ namespace slskd.Search StartedAt = DateTime.UtcNow, }; + bool searchCreated = false; + bool searchBroadcasted = false; + try { using var context = ContextFactory.CreateDbContext(); context.Add(search); context.SaveChanges(); + searchCreated = true; + await SearchHub.BroadcastCreateAsync(search); + searchBroadcasted = true; + // initialize the list of responses that we'll use to accumulate them // populated by the responseHandler we pass to SearchAsync List responses = new(); @@ -333,11 +340,18 @@ namespace slskd.Search // the app isn't connected, and a few other straightforward issues that arise before even requesting the search Log.Error(ex, "Failed to execute search {Search}: {Message}", new { query, scope, options }, ex.Message); - search.State = SearchStates.Completed | SearchStates.Errored; - search.EndedAt = search.StartedAt; - Update(search); + // selectively 'undo' whatever actions we were able to take successfully + if (searchCreated) + { + search.State = SearchStates.Completed | SearchStates.Errored; + search.EndedAt = search.StartedAt; + Update(search); - await SearchHub.BroadcastUpdateAsync(search with { Responses = [] }); + if (searchBroadcasted) + { + await SearchHub.BroadcastUpdateAsync(search with { Responses = [] }); + } + } throw; } -- cgit v1.2.3 From 58bf88cd6acd402b7ffd9ef25cf1cc4ccaf50bbd Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 13 Mar 2025 17:50:34 -0500 Subject: clarify final broadcast --- src/slskd/Search/SearchService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs index 20f9255f..8668d684 100644 --- a/src/slskd/Search/SearchService.cs +++ b/src/slskd/Search/SearchService.cs @@ -330,8 +330,8 @@ namespace slskd.Search } }); + // broadcast and return the _newly created_ search; it will continue to be updated in the background await SearchHub.BroadcastUpdateAsync(search); - return search; } catch (Exception ex) -- cgit v1.2.3 From fd1f0c094a130325fd901aae91297d6d3bad78ca Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 25 Mar 2025 18:34:01 -0500 Subject: bump Soulseek.NET --- src/slskd/slskd.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj index 0a282645..fa127429 100644 --- a/src/slskd/slskd.csproj +++ b/src/slskd/slskd.csproj @@ -67,7 +67,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- cgit v1.2.3 From 87323146bbca590834a72016e285c86f9a1d29b7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 25 Mar 2025 18:35:44 -0500 Subject: refactor error handling for searches --- src/slskd/Search/SearchService.cs | 61 ++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs index 8668d684..ac99ee2e 100644 --- a/src/slskd/Search/SearchService.cs +++ b/src/slskd/Search/SearchService.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -262,9 +262,15 @@ namespace slskd.Search options = options.WithActions( stateChanged: (args) => { + // this logic is executed by Soulseek.NET upon each transition of the searcn, including the final + // transition to Completed. if for some reason something goes wrong, we won't see the final Completed + // transition, we should instead see the task below throw, in which case it will become + // faulted and we'll set the Completed flag manually in the ContinueWith() block search = search.WithSoulseekSearch(args.Search); SearchHub.BroadcastUpdateAsync(search); Update(search); + + Log.Debug("Search for '{Query}' state changed: {State} (id: {Id})", query, search.State, id); }, responseReceived: (args) => rateLimiter.Invoke(() => { @@ -291,42 +297,51 @@ namespace slskd.Search options, cancellationToken: cancellationTokenSource.Token); - // seach looks ok so far; let the rest of the logic run asynchronously + // search looks ok so far; let the rest of the logic run asynchronously // on a background thread. this logic needs to clean up after itself and // update the search record to accurately reflect the final state _ = Task.Run(async () => + { + var soulseekSearch = await soulseekSearchTask; + search = search.WithSoulseekSearch(soulseekSearch); + + Log.Debug("Search for '{Query}' ended normally (id: {Id})", query, id); + }, cancellationToken: cancellationTokenSource.Token) + .ContinueWith(async task => { try { - var soulseekSearch = await soulseekSearchTask; - search = search.WithSoulseekSearch(soulseekSearch); + // the only way we should ever get to this point is if we encounter an error sending the search + // request to the server (timeout, cancelled) or hit some highly improbable error within Soulseek.NET, + // potentially OOM or something. in these cases the task will throw and we need to force the + // search record into Errored state. + if (task.IsFaulted) + { + Log.Error(task.Exception, "Failed to execute search for '{Query}' (id: {Id}): {Message}", query, id, task.Exception?.Message ?? "Task completed in Faulted state, but there is no Exception"); + search.State = SearchStates.Completed | SearchStates.Errored; + } + + search.EndedAt = DateTime.UtcNow; + search.Responses = responses.Select(r => Response.FromSoulseekSearchResponse(r)); + + Update(search); + + // zero responses before broadcasting, as we don't want to blast this + // data out over the SignalR socket + await SearchHub.BroadcastUpdateAsync(search with { Responses = [] }); + + Log.Debug("Search for '{Query}' finalized (id: {Id}): {Search}", query, id, search with { Responses = [] }); } catch (Exception ex) { - Log.Error(ex, "Failed to execute search {Search}: {Message}", new { query, scope, options }, ex.Message); - search.State = SearchStates.Completed | SearchStates.Errored; + // record may be left 'hanging' and will need to be cleaned up at the next boot; we tried to update but failed + Log.Error(ex, "Failed to finalize search for '{Query}' (id: {Id}): {Message}", query, id, ex.Message); + throw; } finally { rateLimiter.Dispose(); CancellationTokens.TryRemove(id, out _); - - try - { - search.EndedAt = DateTime.UtcNow; - search.Responses = responses.Select(r => Response.FromSoulseekSearchResponse(r)); - - Update(search); - - // zero responses before broadcasting, as we don't want to blast this - // data out over the SignalR socket - await SearchHub.BroadcastUpdateAsync(search with { Responses = [] }); - } - catch (Exception ex) - { - // record may be left 'hanging' and will need to be cleaned up at the next boot - Log.Error(ex, "Failed to persist search for {SearchQuery} ({Id})", query, id); - } } }); -- cgit v1.2.3 From fcc0499ca6846f42820e952663fc1b4067e11634 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 26 Mar 2025 14:59:08 -0500 Subject: fix directory contents resolver --- src/slskd/Application.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 791cf245..e5681442 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1258,18 +1258,18 @@ namespace slskd /// The unique token for the request, supplied by the requesting user. /// The requested directory. /// A Task resolving an instance of Soulseek.Directory containing the contents of the requested directory. - private async Task DirectoryContentsResponseResolver(string username, IPEndPoint endpoint, int token, string directory) + private async Task> DirectoryContentsResponseResolver(string username, IPEndPoint endpoint, int token, string directory) { if (Users.IsBlacklisted(username, endpoint.Address)) { Log.Information("Returned empty directory listing for blacklisted user {Username} ({IP})", username, endpoint.Address); - return new Soulseek.Directory(directory); + return [new Soulseek.Directory(directory)]; } try { var dir = await Shares.ListDirectoryAsync(directory); - return dir; + return [dir]; } catch (Exception ex) { -- cgit v1.2.3 From 03f4e86500350ba3a939afd8e1e4e8274aac4314 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 27 Mar 2025 18:00:25 -0500 Subject: bump Soulseek.NET to 7.0.1 --- src/slskd/slskd.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj index fa127429..0a5d0683 100644 --- a/src/slskd/slskd.csproj +++ b/src/slskd/slskd.csproj @@ -67,7 +67,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- cgit v1.2.3 From 891d221e2e9833e2798a294bbdc2e7bdee6fd14a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 27 Mar 2025 18:00:37 -0500 Subject: add Queued state --- src/web/src/components/Search/SearchStatusIcon.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Search/SearchStatusIcon.jsx b/src/web/src/components/Search/SearchStatusIcon.jsx index 9658b626..0a3d4a5d 100644 --- a/src/web/src/components/Search/SearchStatusIcon.jsx +++ b/src/web/src/components/Search/SearchStatusIcon.jsx @@ -1,9 +1,9 @@ import React from 'react'; import { Icon, Popup } from 'semantic-ui-react'; -// as of 4.5.2, states are: +// as of 3/26/25 states are: // transient: -// None, Requested, InProgress +// None, Queued, Requested, InProgress // terminal: // good: Completed, [TimedOut | ResponseLimitReached | FileLimitReached] // bad: Completed, [Errored | Cancelled] @@ -11,6 +11,7 @@ import { Icon, Popup } from 'semantic-ui-react'; const getIcon = ({ state, ...props }) => { switch (state) { case 'None': + case 'Queued': case 'Requested': return (