From 32b6e44f6db7a77905e45e7bbbe94f91be02fdee Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 12 Sep 2021 11:07:19 -0500 Subject: remove ISoulseekClient from PeerService --- src/slskd/Application/Application.cs | 15 ++++++++++++--- src/slskd/Application/IApplication.cs | 7 +++++++ src/slskd/Application/Peer/PeerService.cs | 21 ++++++++++----------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs index 2f5fc9f3..87f589f7 100644 --- a/src/slskd/Application/Application.cs +++ b/src/slskd/Application/Application.cs @@ -269,7 +269,8 @@ namespace slskd public Task StartPublicChatAsync() => SoulseekClient.StartPublicChatAsync(); public Task StopPublicChatAsync() => SoulseekClient.StopPublicChatAsync(); - public Task AcknowledgePrivateMessageAsnyc(int id) => SoulseekClient.AcknowledgePrivateMessageAsync(id); + public Task SendPrivateMessageAsync(string username, string message) => SoulseekClient.SendPrivateMessageAsync(username, message); + public Task AcknowledgePrivateMessageAsync(int id) => SoulseekClient.AcknowledgePrivateMessageAsync(id); public Task SendRoomMessageAsync(string roomName, string message) => SoulseekClient.SendRoomMessageAsync(roomName, message); public Task SetRoomTickerAsync(string roomName, string message) @@ -277,12 +278,18 @@ namespace slskd public Task AddPrivateRoomMemberAsync(string roomName, string username) => SoulseekClient.AddPrivateRoomMemberAsync(roomName, username); public Task GetRoomListAsync() => SoulseekClient.GetRoomListAsync(); - public Task JoinRoomAsync(string roomName) => SoulseekClient.JoinRoomAsync(roomName); public Task LeaveRoomAsync(string roomName) => SoulseekClient.LeaveRoomAsync(roomName); public Task DownloadAsync(string username, string filename, Stream outputStream, long? size, long startOffset = 0, int? token = null, TransferOptions options = null, CancellationToken? cancellationToken = null) => SoulseekClient.DownloadAsync(username, filename, outputStream, size, startOffset, token, options, cancellationToken); public Task GetDownloadPlaceInQueueAsync(string username, string filename) => SoulseekClient.GetDownloadPlaceInQueueAsync(username, filename); + public Task GetUserEndPointAsync(string username) => SoulseekClient.GetUserEndPointAsync(username); + public Task GetUserStatusAsync(string username) => SoulseekClient.GetUserStatusAsync(username); + public Task GrantUserPrivilegesAsync(string username, int days) => SoulseekClient.GrantUserPrivilegesAsync(username, days); + public Task GetUserPrivilegedAsync(string username) => SoulseekClient.GetUserPrivilegedAsync(username); + public Task AddUserAsync(string username) => SoulseekClient.AddUserAsync(username); + public Task BrowseAsync(string username) => SoulseekClient.BrowseAsync(username); + public Task GetUserInfoAsync(string username) => SoulseekClient.GetUserInfoAsync(username); private async Task OptionsMonitor_OnChange(Options newOptions) { @@ -558,7 +565,7 @@ namespace slskd } } - private async Task JoinRoomAsync(string roomName) + public async Task JoinRoomAsync(string roomName) { Logger.Debug("Joining room {Room}", roomName); @@ -567,10 +574,12 @@ namespace slskd var data = await SoulseekClient.JoinRoomAsync(roomName); Logger.Information("Joined room {Room}", roomName); Logger.Debug("Room data for {Room}: {Info}", roomName, data.ToJson()); + return data; } catch (Exception ex) { Logger.Warning("Failed to join room {Room}: {Message}", roomName, ex.Message); + throw; } } diff --git a/src/slskd/Application/IApplication.cs b/src/slskd/Application/IApplication.cs index 0bf83899..78a05151 100644 --- a/src/slskd/Application/IApplication.cs +++ b/src/slskd/Application/IApplication.cs @@ -19,6 +19,7 @@ namespace slskd { using System; using System.IO; + using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Hosting; @@ -43,5 +44,11 @@ namespace slskd public Task DownloadAsync(string username, string filename, Stream outputStream, long? size, long startOffset = 0, int? token = null, TransferOptions options = null, CancellationToken? cancellationToken = null); public Task GetDownloadPlaceInQueueAsync(string username, string filename); public Task BrowseAsync(string username); + public Task GetUserInfoAsync(string username); + public Task GetUserEndPointAsync(string username); + public Task GetUserStatusAsync(string username); + public Task GrantUserPrivilegesAsync(string username, int days); + public Task GetUserPrivilegedAsync(string username); + public Task AddUserAsync(string username); } } diff --git a/src/slskd/Application/Peer/PeerService.cs b/src/slskd/Application/Peer/PeerService.cs index e0e03fa6..96d65bd5 100644 --- a/src/slskd/Application/Peer/PeerService.cs +++ b/src/slskd/Application/Peer/PeerService.cs @@ -22,7 +22,6 @@ namespace slskd.Peer using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; - using ISoulseekClient = Soulseek.ISoulseekClient; /// /// Provides information and operations for network peers. @@ -34,20 +33,20 @@ namespace slskd.Peer /// /// Initializes a new instance of the class. /// - /// The client instance to use. + /// /// The database context to use. /// The logger. public PeerService( - ISoulseekClient client, + IApplication application, IDbContextFactory contextFactory, ILogger log) { - Client = client; + Application = application; ContextFactory = contextFactory; Log = log; } - private ISoulseekClient Client { get; } + private IApplication Application { get; } private IDbContextFactory ContextFactory { get; } private ILogger Log { get; set; } @@ -69,7 +68,7 @@ namespace slskd.Peer return info; } - var soulseekUserInfo = await Client.GetUserInfoAsync(username); + var soulseekUserInfo = await Application.GetUserInfoAsync(username); info = Info.FromSoulseekUserInfo(username, soulseekUserInfo); if (peerExists) @@ -93,7 +92,7 @@ namespace slskd.Peer /// The retrieved endpoint. public Task GetIPEndPointAsync(string username) { - return Client.GetUserEndPointAsync(username); + return Application.GetUserEndPointAsync(username); } /// @@ -103,7 +102,7 @@ namespace slskd.Peer /// The retrieved status. public async Task GetStatusAsync(string username) { - var soulseekStatus = await Client.GetUserStatusAsync(username); + var soulseekStatus = await Application.GetUserStatusAsync(username); return Status.FromSoulseekUserStatus(soulseekStatus); } @@ -115,7 +114,7 @@ namespace slskd.Peer /// The number of days to grant. /// The operation context. public Task GrantPrivilegesAsync(string username, int days) - => Client.GrantUserPrivilegesAsync(username, days); + => Application.GrantUserPrivilegesAsync(username, days); /// /// Retrieves a value indicating whether the specified peer is privileged. @@ -123,7 +122,7 @@ namespace slskd.Peer /// The username of the peer. /// A value indicating whether the specified peer is privileged. public Task IsPrivilegedAsync(string username) - => Client.GetUserPrivilegedAsync(username); + => Application.GetUserPrivilegedAsync(username); /// /// Adds the specified username to the server-side user list. @@ -132,7 +131,7 @@ namespace slskd.Peer /// The operation context. public async Task WatchAsync(string username) { - await Client.AddUserAsync(username); + await Application.AddUserAsync(username); } } } \ No newline at end of file -- cgit v1.2.3