From 40b8ea8eb8e5f83213c5013dbdf81626dc724f2f Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 30 Nov 2025 19:59:30 +0800 Subject: [PATCH] :card_file_box: Bring account id back to chat room --- DysonNetwork.Shared/Models/ChatRoom.cs | 2 ++ DysonNetwork.Sphere/Chat/ChatRoomController.cs | 10 ++++++---- .../Migrations/AppDatabaseModelSnapshot.cs | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/DysonNetwork.Shared/Models/ChatRoom.cs b/DysonNetwork.Shared/Models/ChatRoom.cs index 34d55cf..963bd62 100644 --- a/DysonNetwork.Shared/Models/ChatRoom.cs +++ b/DysonNetwork.Shared/Models/ChatRoom.cs @@ -25,6 +25,8 @@ public class SnChatRoom : ModelBase, IIdentifiedResource [JsonIgnore] public ICollection Members { get; set; } = new List(); + public Guid? AccountId { get; set; } + [NotMapped] public SnAccount? Account { get; set; } public Guid? RealmId { get; set; } [NotMapped] public SnRealm? Realm { get; set; } diff --git a/DysonNetwork.Sphere/Chat/ChatRoomController.cs b/DysonNetwork.Sphere/Chat/ChatRoomController.cs index 05c9676..850c21f 100644 --- a/DysonNetwork.Sphere/Chat/ChatRoomController.cs +++ b/DysonNetwork.Sphere/Chat/ChatRoomController.cs @@ -182,8 +182,9 @@ public class ChatRoomController( [RequiredPermission("global", "chat.create")] public async Task> CreateChatRoom(ChatRoomRequest request) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); + if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); if (request.Name is null) return BadRequest("You cannot create a chat room without a name."); + var accountId = Guid.Parse(currentUser.Id); var chatRoom = new SnChatRoom { @@ -192,13 +193,14 @@ public class ChatRoomController( IsCommunity = request.IsCommunity ?? false, IsPublic = request.IsPublic ?? false, Type = ChatRoomType.Group, + AccountId = accountId, Members = new List { new() { Role = ChatMemberRole.Owner, - AccountId = Guid.Parse(currentUser.Id), - JoinedAt = Instant.FromDateTimeUtc(DateTime.UtcNow) + AccountId = accountId, + JoinedAt = SystemClock.Instance.GetCurrentInstant() } } }; @@ -294,7 +296,7 @@ public class ChatRoomController( [HttpPatch("{id:guid}")] public async Task> UpdateChatRoom(Guid id, [FromBody] ChatRoomRequest request) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); + if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); var chatRoom = await db.ChatRooms .Where(e => e.Id == id) diff --git a/DysonNetwork.Sphere/Migrations/AppDatabaseModelSnapshot.cs b/DysonNetwork.Sphere/Migrations/AppDatabaseModelSnapshot.cs index 5d56342..256c626 100644 --- a/DysonNetwork.Sphere/Migrations/AppDatabaseModelSnapshot.cs +++ b/DysonNetwork.Sphere/Migrations/AppDatabaseModelSnapshot.cs @@ -247,6 +247,10 @@ namespace DysonNetwork.Sphere.Migrations .HasColumnType("uuid") .HasColumnName("id"); + b.Property("AccountId") + .HasColumnType("uuid") + .HasColumnName("account_id"); + b.Property("Background") .HasColumnType("jsonb") .HasColumnName("background");