From 0eb773dbd4aa2fe971bc55e5c5f12413003296bb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Sep 2021 08:28:11 -0500 Subject: move stuff again --- .../Messaging/API/DTO/PrivateMessageResponse.cs | 74 +++++++++++++++++++ src/slskd/Messaging/API/DTO/RoomInfoResponse.cs | 60 +++++++++++++++ src/slskd/Messaging/API/DTO/RoomMessageResponse.cs | 62 ++++++++++++++++ src/slskd/Messaging/API/DTO/RoomResponse.cs | 75 +++++++++++++++++++ src/slskd/Messaging/API/DTO/UserDataResponse.cs | 85 ++++++++++++++++++++++ 5 files changed, 356 insertions(+) create mode 100644 src/slskd/Messaging/API/DTO/PrivateMessageResponse.cs create mode 100644 src/slskd/Messaging/API/DTO/RoomInfoResponse.cs create mode 100644 src/slskd/Messaging/API/DTO/RoomMessageResponse.cs create mode 100644 src/slskd/Messaging/API/DTO/RoomResponse.cs create mode 100644 src/slskd/Messaging/API/DTO/UserDataResponse.cs (limited to 'src/slskd/Messaging/API/DTO') diff --git a/src/slskd/Messaging/API/DTO/PrivateMessageResponse.cs b/src/slskd/Messaging/API/DTO/PrivateMessageResponse.cs new file mode 100644 index 00000000..a7e08d50 --- /dev/null +++ b/src/slskd/Messaging/API/DTO/PrivateMessageResponse.cs @@ -0,0 +1,74 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Messaging.API +{ + using System; + using slskd.Messaging; + + public class PrivateMessageResponse + { + /// + /// A value indicating whether the message has been acknowledged. + /// + public bool Acknowledged { get; set; } = false; + + /// + /// The unique message id, used to acknowledge receipt. + /// + public int Id { get; set; } + + /// + /// The message. + /// + public string Message { get; set; } + + /// + /// A value indicating whether the message was replayed. + /// + public bool Replayed { get; set; } + + /// + /// The UTC timestamp of the message. + /// + public DateTime Timestamp { get; set; } = DateTime.UtcNow; + + /// + /// The username of the user who sent the message. + /// + public string Username { get; set; } + + /// + /// A value indicating whether this message was sent by the currently logged in user. + /// + public bool? Self { get; set; } + + public static PrivateMessageResponse FromPrivateMessage(PrivateMessage privateMessage, bool self = false) + { + return new PrivateMessageResponse() + { + Id = privateMessage.Id, + Timestamp = privateMessage.Timestamp, + Username = privateMessage.Username, + Message = privateMessage.Message, + Acknowledged = privateMessage.Acknowledged, + Replayed = privateMessage.Replayed, + Self = self ? self : (bool?)null, + }; + } + } +} diff --git a/src/slskd/Messaging/API/DTO/RoomInfoResponse.cs b/src/slskd/Messaging/API/DTO/RoomInfoResponse.cs new file mode 100644 index 00000000..46edbdc8 --- /dev/null +++ b/src/slskd/Messaging/API/DTO/RoomInfoResponse.cs @@ -0,0 +1,60 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Messaging.API +{ + using Soulseek; + + public class RoomInfoResponse + { + /// + /// Gets the room name. + /// + public string Name { get; init; } + + /// + /// Gets the number of users in the room. + /// + public int UserCount { get; init; } + + /// + /// Gets a value indicating whether the room is private. + /// + public bool IsPrivate { get; init; } + + /// + /// Gets a value indicating whether the room is owned by the currently logged in user. + /// + public bool IsOwned { get; init; } + + /// + /// Gets a value indicating whether the room is moderated by the currently logged in user. + /// + public bool IsModerated { get; set; } + + public static RoomInfoResponse FromRoomInfo(RoomInfo info, bool isPrivate = false, bool isOwned = false) + { + return new RoomInfoResponse() + { + Name = info.Name, + UserCount = info.UserCount, + IsPrivate = isPrivate, + IsOwned = isOwned, + }; + } + } +} diff --git a/src/slskd/Messaging/API/DTO/RoomMessageResponse.cs b/src/slskd/Messaging/API/DTO/RoomMessageResponse.cs new file mode 100644 index 00000000..965c63a6 --- /dev/null +++ b/src/slskd/Messaging/API/DTO/RoomMessageResponse.cs @@ -0,0 +1,62 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Messaging.API +{ + using System; + using slskd.Messaging; + + public class RoomMessageResponse + { + /// + /// The timestamp of the message. + /// + public DateTime Timestamp { get; set; } = DateTime.UtcNow; + + /// + /// The username of the user who sent the message. + /// + public string Username { get; set; } + + /// + /// The message. + /// + public string Message { get; set; } + + /// + /// The room to which the message pertains. + /// + public string RoomName { get; set; } + + /// + /// A value indicating whether this user data belongs to the currently logged in user. + /// + public bool? Self { get; set; } + + public static RoomMessageResponse FromRoomMessage(RoomMessage roomMessage, bool self = false) + { + return new RoomMessageResponse() + { + Timestamp = roomMessage.Timestamp, + Username = roomMessage.Username, + Message = roomMessage.Message, + RoomName = roomMessage.RoomName, + Self = self ? self : (bool?)null, + }; + } + } +} diff --git a/src/slskd/Messaging/API/DTO/RoomResponse.cs b/src/slskd/Messaging/API/DTO/RoomResponse.cs new file mode 100644 index 00000000..cf7e1478 --- /dev/null +++ b/src/slskd/Messaging/API/DTO/RoomResponse.cs @@ -0,0 +1,75 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Messaging.API +{ + using System.Collections.Generic; + using System.Linq; + using slskd.Messaging; + + public class RoomResponse + { + /// + /// The room name. + /// + public string Name { get; set; } + + /// + /// A value indicating whether the room is private. + /// + public bool IsPrivate { get; set; } + + /// + /// The number of operators in the room, if private. + /// + public int? OperatorCount { get; set; } + + /// + /// The operators in the room, if private. + /// + public IList Operators { get; set; } + + /// + /// The owner of the room, if private. + /// + public string Owner { get; set; } + + /// + /// The list of users in the room. + /// + public IEnumerable Users { get; set; } = new List(); + + /// + /// The list of messages. + /// + public IEnumerable Messages { get; set; } = new List(); + + public static RoomResponse FromRoom(Room room) + { + return new RoomResponse() + { + Name = room.Name, + IsPrivate = room.IsPrivate, + OperatorCount = room.OperatorCount, + Operators = room.Operators?.ToList(), + Owner = room.Owner, + Users = new List(), + Messages = new List(), + }; + } + } +} diff --git a/src/slskd/Messaging/API/DTO/UserDataResponse.cs b/src/slskd/Messaging/API/DTO/UserDataResponse.cs new file mode 100644 index 00000000..8f1e9544 --- /dev/null +++ b/src/slskd/Messaging/API/DTO/UserDataResponse.cs @@ -0,0 +1,85 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Messaging.API +{ + using Soulseek; + + public class UserDataResponse + { + /// + /// The average upload speed of the user. + /// + public int AverageSpeed { get; set; } + + /// + /// The user's country code, if provided. + /// + public string CountryCode { get; set; } + + /// + /// The number of directories shared by the user. + /// + public int DirectoryCount { get; set; } + + /// + /// The number of files shared by the user. + /// + public int FileCount { get; set; } + + /// + /// A value indicating whether this user data belongs to the currently logged in user. + /// + public bool? Self { get; set; } + + /// + /// The number of the user's free download slots, if provided. + /// + public int? SlotsFree { get; set; } + + /// + /// The status of the user (0 = offline, 1 = away, 2 = online). + /// + public UserPresence Status { get; set; } + + /// + /// The number of uploads tracked by the server for the user. + /// + public long UploadCount { get; set; } + + /// + /// The username of the user. + /// + public string Username { get; set; } + + public static UserDataResponse FromUserData(UserData userData, bool self = false) + { + return new UserDataResponse() + { + AverageSpeed = userData.AverageSpeed, + CountryCode = userData.CountryCode, + DirectoryCount = userData.DirectoryCount, + UploadCount = userData.UploadCount, + FileCount = userData.FileCount, + SlotsFree = userData.SlotsFree, + Status = userData.Status, + Username = userData.Username, + Self = self ? self : (bool?)null, + }; + } + } +} \ No newline at end of file -- cgit v1.2.3