♻️ No idea, but errors all gone

This commit is contained in:
2025-07-08 23:55:31 +08:00
parent 2c67472894
commit 63b2b989ba
74 changed files with 1551 additions and 1100 deletions

View File

@@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using DysonNetwork.Pass.Account;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Services;
using DysonNetwork.Sphere.Localization;
using DysonNetwork.Sphere.Permission;
using DysonNetwork.Sphere.Realm;
using DysonNetwork.Sphere.Storage;
using Microsoft.AspNetCore.Authorization;
@@ -20,10 +20,12 @@ public class ChatRoomController(
FileReferenceService fileRefService,
ChatRoomService crs,
RealmService rs,
DysonNetwork.Shared.Services.IActionLogService als,
DysonNetwork.Shared.Services.INotificationService nty,
DysonNetwork.Shared.Services.IRelationshipService rels,
DysonNetwork.Shared.Services.IAccountEventService aes
IAccountService accounts,
IActionLogService als,
INotificationService nty,
IRelationshipService rels,
IAccountEventService aes,
IStringLocalizer<NotificationResource> localizer
) : ControllerBase
{
[HttpGet("{id:guid}")]
@@ -46,7 +48,7 @@ public class ChatRoomController(
[Authorize]
public async Task<ActionResult<List<ChatRoom>>> ListJoinedChatRooms()
{
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser)
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
return Unauthorized();
var userId = currentUser.Id;
@@ -72,10 +74,10 @@ public class ChatRoomController(
[Authorize]
public async Task<ActionResult<ChatRoom>> CreateDirectMessage([FromBody] DirectMessageRequest request)
{
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser)
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
return Unauthorized();
var relatedUser = await db.Accounts.FindAsync(request.RelatedUserId);
var relatedUser = await accounts.GetAccountById(request.RelatedUserId);
if (relatedUser is null)
return BadRequest("Related user was not found");
@@ -104,7 +106,7 @@ public class ChatRoomController(
{
AccountId = currentUser.Id,
Role = ChatMemberRole.Owner,
JoinedAt = NodaTime.Instant.FromDateTimeUtc(DateTime.UtcNow)
JoinedAt = Instant.FromDateTimeUtc(DateTime.UtcNow)
},
new()
{
@@ -118,9 +120,12 @@ public class ChatRoomController(
db.ChatRooms.Add(dmRoom);
await db.SaveChangesAsync();
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.ChatroomCreate,
new Dictionary<string, object> { { "chatroom_id", dmRoom.Id } }, Request
new Dictionary<string, object> { { "chatroom_id", dmRoom.Id } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
var invitedMember = dmRoom.Members.First(m => m.AccountId == request.RelatedUserId);
@@ -161,7 +166,7 @@ public class ChatRoomController(
[HttpPost]
[Authorize]
[RequiredPermissionAttribute("global", "chat.create")]
[DysonNetwork.Shared.Permission.RequiredPermission("global", "chat.create")]
public async Task<ActionResult<ChatRoom>> CreateChatRoom(ChatRoomRequest request)
{
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
@@ -224,9 +229,12 @@ public class ChatRoomController(
chatRoomResourceId
);
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.ChatroomCreate,
new Dictionary<string, object> { { "chatroom_id", chatRoom.Id } }, Request
new Dictionary<string, object> { { "chatroom_id", chatRoom.Id } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return Ok(chatRoom);
@@ -310,9 +318,12 @@ public class ChatRoomController(
db.ChatRooms.Update(chatRoom);
await db.SaveChangesAsync();
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.ChatroomUpdate,
new Dictionary<string, object> { { "chatroom_id", chatRoom.Id } }, Request
new Dictionary<string, object> { { "chatroom_id", chatRoom.Id } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return Ok(chatRoom);
@@ -344,9 +355,12 @@ public class ChatRoomController(
db.ChatRooms.Remove(chatRoom);
await db.SaveChangesAsync();
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.ChatroomDelete,
new Dictionary<string, object> { { "chatroom_id", chatRoom.Id } }, Request
new Dictionary<string, object> { { "chatroom_id", chatRoom.Id } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return NoContent();
@@ -435,7 +449,6 @@ public class ChatRoomController(
}
}
public class ChatMemberRequest
{
@@ -451,7 +464,7 @@ public class ChatRoomController(
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
var userId = currentUser.Id;
var relatedUser = await db.Accounts.FindAsync(request.RelatedUserId);
var relatedUser = await accounts.GetAccountById(request.RelatedUserId);
if (relatedUser is null) return BadRequest("Related user was not found");
if (await rels.HasRelationshipWithStatus(currentUser.Id, relatedUser.Id, RelationshipStatus.Blocked))
@@ -507,9 +520,12 @@ public class ChatRoomController(
newMember.ChatRoom = chatRoom;
await _SendInviteNotify(newMember, currentUser);
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.ChatroomInvite,
new Dictionary<string, object> { { "chatroom_id", chatRoom.Id }, { "account_id", relatedUser.Id } }, Request
new Dictionary<string, object> { { "chatroom_id", chatRoom.Id }, { "account_id", relatedUser.Id } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return Ok(newMember);
@@ -559,9 +575,12 @@ public class ChatRoomController(
await db.SaveChangesAsync();
_ = crs.PurgeRoomMembersCache(roomId);
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.ChatroomJoin,
new Dictionary<string, object> { { "chatroom_id", roomId } }, Request
new Dictionary<string, object> { { "chatroom_id", roomId } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return Ok(member);
@@ -675,7 +694,9 @@ public class ChatRoomController(
ActionLogType.RealmAdjustRole,
new Dictionary<string, object>
{ { "chatroom_id", roomId }, { "account_id", memberId }, { "new_role", newRole } },
Request
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return Ok(targetMember);
@@ -722,7 +743,10 @@ public class ChatRoomController(
als.CreateActionLogFromRequest(
ActionLogType.ChatroomKick,
new Dictionary<string, object> { { "chatroom_id", roomId }, { "account_id", memberId } }, Request
new Dictionary<string, object> { { "chatroom_id", roomId }, { "account_id", memberId } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return NoContent();
@@ -762,9 +786,12 @@ public class ChatRoomController(
await db.SaveChangesAsync();
_ = crs.PurgeRoomMembersCache(roomId);
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.ChatroomJoin,
new Dictionary<string, object> { { "chatroom_id", roomId } }, Request
new Dictionary<string, object> { { "chatroom_id", roomId } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return Ok(chatRoom);
@@ -799,15 +826,18 @@ public class ChatRoomController(
await db.SaveChangesAsync();
await crs.PurgeRoomMembersCache(roomId);
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.ChatroomLeave,
new Dictionary<string, object> { { "chatroom_id", roomId } }, Request
new Dictionary<string, object> { { "chatroom_id", roomId } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return NoContent();
}
private async Task _SendInviteNotify(ChatMember member, Shared.Models.Account sender)
private async Task _SendInviteNotify(ChatMember member, Account sender)
{
string title = localizer["ChatInviteTitle"];