💥 Switch all id to uuid
This commit is contained in:
@ -16,7 +16,7 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
|
||||
public class MarkMessageReadRequest
|
||||
{
|
||||
public Guid MessageId { get; set; }
|
||||
public long ChatRoomId { get; set; }
|
||||
public Guid ChatRoomId { get; set; }
|
||||
}
|
||||
|
||||
public class SendMessageRequest
|
||||
@ -29,8 +29,8 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
|
||||
public Guid? ForwardedMessageId { get; set; }
|
||||
}
|
||||
|
||||
[HttpGet("{roomId:long}/messages")]
|
||||
public async Task<ActionResult<List<Message>>> ListMessages(long roomId, [FromQuery] int offset, [FromQuery] int take = 20)
|
||||
[HttpGet("{roomId:guid}/messages")]
|
||||
public async Task<ActionResult<List<Message>>> ListMessages(Guid roomId, [FromQuery] int offset, [FromQuery] int take = 20)
|
||||
{
|
||||
var currentUser = HttpContext.Items["CurrentUser"] as Account.Account;
|
||||
|
||||
@ -67,8 +67,8 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
|
||||
return Ok(messages);
|
||||
}
|
||||
|
||||
[HttpGet("{roomId:long}/messages/{messageId:guid}")]
|
||||
public async Task<ActionResult<Message>> GetMessage(long roomId, Guid messageId)
|
||||
[HttpGet("{roomId:guid}/messages/{messageId:guid}")]
|
||||
public async Task<ActionResult<Message>> GetMessage(Guid roomId, Guid messageId)
|
||||
{
|
||||
var currentUser = HttpContext.Items["CurrentUser"] as Account.Account;
|
||||
|
||||
@ -104,10 +104,10 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
|
||||
[GeneratedRegex("@([A-Za-z0-9_-]+)")]
|
||||
private static partial Regex MentionRegex();
|
||||
|
||||
[HttpPost("{roomId:long}/messages")]
|
||||
[HttpPost("{roomId:guid}/messages")]
|
||||
[Authorize]
|
||||
[RequiredPermission("global", "chat.messages.create")]
|
||||
public async Task<ActionResult> SendMessage([FromBody] SendMessageRequest request, long roomId)
|
||||
public async Task<ActionResult> SendMessage([FromBody] SendMessageRequest request, Guid roomId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
if (string.IsNullOrWhiteSpace(request.Content) && (request.AttachmentsId == null || request.AttachmentsId.Count == 0))
|
||||
@ -185,9 +185,9 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
|
||||
|
||||
|
||||
|
||||
[HttpPatch("{roomId:long}/messages/{messageId:guid}")]
|
||||
[HttpPatch("{roomId:guid}/messages/{messageId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult> UpdateMessage([FromBody] SendMessageRequest request, long roomId, Guid messageId)
|
||||
public async Task<ActionResult> UpdateMessage([FromBody] SendMessageRequest request, Guid roomId, Guid messageId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
|
||||
@ -254,9 +254,9 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
|
||||
return Ok(message);
|
||||
}
|
||||
|
||||
[HttpDelete("{roomId:long}/messages/{messageId:guid}")]
|
||||
[HttpDelete("{roomId:guid}/messages/{messageId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult> DeleteMessage(long roomId, Guid messageId)
|
||||
public async Task<ActionResult> DeleteMessage(Guid roomId, Guid messageId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
|
||||
@ -280,8 +280,8 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
|
||||
public long LastSyncTimestamp { get; set; }
|
||||
}
|
||||
|
||||
[HttpPost("{roomId:long}/sync")]
|
||||
public async Task<ActionResult<SyncResponse>> GetSyncData([FromBody] SyncRequest request, long roomId)
|
||||
[HttpPost("{roomId:guid}/sync")]
|
||||
public async Task<ActionResult<SyncResponse>> GetSyncData([FromBody] SyncRequest request, Guid roomId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
@ -14,7 +14,7 @@ public enum ChatRoomType
|
||||
|
||||
public class ChatRoom : ModelBase
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
[MaxLength(1024)] public string Name { get; set; } = string.Empty;
|
||||
[MaxLength(4096)] public string Description { get; set; } = string.Empty;
|
||||
public ChatRoomType Type { get; set; }
|
||||
@ -27,7 +27,7 @@ public class ChatRoom : ModelBase
|
||||
|
||||
[JsonIgnore] public ICollection<ChatMember> Members { get; set; } = new List<ChatMember>();
|
||||
|
||||
public long? RealmId { get; set; }
|
||||
public Guid? RealmId { get; set; }
|
||||
public Realm.Realm? Realm { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
@ -53,9 +53,9 @@ public enum ChatMemberNotify
|
||||
public class ChatMember : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public long ChatRoomId { get; set; }
|
||||
public Guid ChatRoomId { get; set; }
|
||||
public ChatRoom ChatRoom { get; set; } = null!;
|
||||
public long AccountId { get; set; }
|
||||
public Guid AccountId { get; set; }
|
||||
public Account.Account Account { get; set; } = null!;
|
||||
|
||||
[MaxLength(1024)] public string? Nick { get; set; }
|
||||
@ -69,8 +69,8 @@ public class ChatMember : ModelBase
|
||||
public class ChatMemberTransmissionObject : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public long ChatRoomId { get; set; }
|
||||
public long AccountId { get; set; }
|
||||
public Guid ChatRoomId { get; set; }
|
||||
public Guid AccountId { get; set; }
|
||||
public Account.Account Account { get; set; } = null!;
|
||||
|
||||
[MaxLength(1024)] public string? Nick { get; set; }
|
||||
|
@ -12,8 +12,8 @@ namespace DysonNetwork.Sphere.Chat;
|
||||
[Route("/chat")]
|
||||
public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService crs) : ControllerBase
|
||||
{
|
||||
[HttpGet("{id:long}")]
|
||||
public async Task<ActionResult<ChatRoom>> GetChatRoom(long id)
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<ActionResult<ChatRoom>> GetChatRoom(Guid id)
|
||||
{
|
||||
var chatRoom = await db.ChatRooms
|
||||
.Where(c => c.Id == id)
|
||||
@ -59,7 +59,7 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
.Include(m => m.Account)
|
||||
.Include(m => m.Account.Profile)
|
||||
.ToDictionaryAsync(m => m.ChatRoomId, m => m)
|
||||
: new Dictionary<long, ChatMember>();
|
||||
: new Dictionary<Guid, ChatMember>();
|
||||
|
||||
// Map the results
|
||||
var result = chatRooms.Select(r =>
|
||||
@ -75,7 +75,7 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
|
||||
public class DirectMessageRequest
|
||||
{
|
||||
[Required] public long RelatedUserId { get; set; }
|
||||
[Required] public Guid RelatedUserId { get; set; }
|
||||
}
|
||||
|
||||
[HttpPost("direct")]
|
||||
@ -139,7 +139,7 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
[MaxLength(4096)] public string? Description { get; set; }
|
||||
public string? PictureId { get; set; }
|
||||
public string? BackgroundId { get; set; }
|
||||
public long? RealmId { get; set; }
|
||||
public Guid? RealmId { get; set; }
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -202,8 +202,8 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
}
|
||||
|
||||
|
||||
[HttpPatch("{id:long}")]
|
||||
public async Task<ActionResult<ChatRoom>> UpdateChatRoom(long id, [FromBody] ChatRoomRequest request)
|
||||
[HttpPatch("{id:guid}")]
|
||||
public async Task<ActionResult<ChatRoom>> UpdateChatRoom(Guid id, [FromBody] ChatRoomRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
|
||||
@ -273,8 +273,8 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
return Ok(chatRoom);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:long}")]
|
||||
public async Task<ActionResult> DeleteChatRoom(long id)
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<ActionResult> DeleteChatRoom(Guid id)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
|
||||
@ -315,9 +315,9 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("{roomId:long}/members/me")]
|
||||
[HttpGet("{roomId:guid}/members/me")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<ChatMember>> GetRoomIdentity(long roomId)
|
||||
public async Task<ActionResult<ChatMember>> GetRoomIdentity(Guid roomId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser)
|
||||
return Unauthorized();
|
||||
@ -334,8 +334,8 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
return Ok(member);
|
||||
}
|
||||
|
||||
[HttpGet("{roomId:long}/members")]
|
||||
public async Task<ActionResult<List<ChatMember>>> ListMembers(long roomId, [FromQuery] int take = 20,
|
||||
[HttpGet("{roomId:guid}/members")]
|
||||
public async Task<ActionResult<List<ChatMember>>> ListMembers(Guid roomId, [FromQuery] int take = 20,
|
||||
[FromQuery] int skip = 0)
|
||||
{
|
||||
var currentUser = HttpContext.Items["CurrentUser"] as Account.Account;
|
||||
@ -371,13 +371,13 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
|
||||
public class ChatMemberRequest
|
||||
{
|
||||
[Required] public long RelatedUserId { get; set; }
|
||||
[Required] public Guid RelatedUserId { get; set; }
|
||||
[Required] public ChatMemberRole Role { get; set; }
|
||||
}
|
||||
|
||||
[HttpPost("invites/{roomId:long}")]
|
||||
[HttpPost("invites/{roomId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<ChatMember>> InviteMember(long roomId,
|
||||
public async Task<ActionResult<ChatMember>> InviteMember(Guid roomId,
|
||||
[FromBody] ChatMemberRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
@ -448,9 +448,9 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
return members.ToList();
|
||||
}
|
||||
|
||||
[HttpPost("invites/{roomId:long}/accept")]
|
||||
[HttpPost("invites/{roomId:guid}/accept")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<ChatRoom>> AcceptChatInvite(long roomId)
|
||||
public async Task<ActionResult<ChatRoom>> AcceptChatInvite(Guid roomId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
var userId = currentUser.Id;
|
||||
@ -469,9 +469,9 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
return Ok(member);
|
||||
}
|
||||
|
||||
[HttpPost("invites/{roomId:long}/decline")]
|
||||
[HttpPost("invites/{roomId:guid}/decline")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult> DeclineChatInvite(long roomId)
|
||||
public async Task<ActionResult> DeclineChatInvite(Guid roomId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
var userId = currentUser.Id;
|
||||
@ -489,9 +489,9 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPatch("{roomId:long}/members/{memberId:long}/role")]
|
||||
[HttpPatch("{roomId:guid}/members/{memberId:guid}/role")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<ChatMember>> UpdateChatMemberRole(long roomId, long memberId,
|
||||
public async Task<ActionResult<ChatMember>> UpdateChatMemberRole(Guid roomId, Guid memberId,
|
||||
[FromBody] ChatMemberRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
@ -542,9 +542,9 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
[HttpDelete("{roomId:long}/members/{memberId:long}")]
|
||||
[HttpDelete("{roomId:guid}/members/{memberId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult> RemoveChatMember(long roomId, long memberId)
|
||||
public async Task<ActionResult> RemoveChatMember(Guid roomId, Guid memberId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
|
||||
@ -591,9 +591,9 @@ public class ChatRoomController(AppDatabase db, FileService fs, ChatRoomService
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
[HttpDelete("{roomId:long}/members/me")]
|
||||
[HttpDelete("{roomId:guid}/members/me")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult> LeaveChat(long roomId)
|
||||
public async Task<ActionResult> LeaveChat(Guid roomId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class ChatService(AppDatabase db, IServiceScopeFactory scopeFactory)
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
public async Task MarkMessageAsReadAsync(Guid messageId, long roomId, long userId)
|
||||
public async Task MarkMessageAsReadAsync(Guid messageId, Guid roomId, Guid userId)
|
||||
{
|
||||
var existingStatus = await db.ChatStatuses
|
||||
.FirstOrDefaultAsync(x => x.MessageId == messageId && x.Sender.AccountId == userId);
|
||||
@ -81,13 +81,13 @@ public class ChatService(AppDatabase db, IServiceScopeFactory scopeFactory)
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> GetMessageReadStatus(Guid messageId, long userId)
|
||||
public async Task<bool> GetMessageReadStatus(Guid messageId, Guid userId)
|
||||
{
|
||||
return await db.ChatStatuses
|
||||
.AnyAsync(x => x.MessageId == messageId && x.Sender.AccountId == userId);
|
||||
}
|
||||
|
||||
public async Task<int> CountUnreadMessage(long userId, long chatRoomId)
|
||||
public async Task<int> CountUnreadMessage(Guid userId, Guid chatRoomId)
|
||||
{
|
||||
var messages = await db.ChatMessages
|
||||
.Where(m => m.ChatRoomId == chatRoomId)
|
||||
@ -101,7 +101,7 @@ public class ChatService(AppDatabase db, IServiceScopeFactory scopeFactory)
|
||||
return messages.Count(m => !m.IsRead);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<long, int>> CountUnreadMessagesForJoinedRoomsAsync(long userId)
|
||||
public async Task<Dictionary<Guid, int>> CountUnreadMessagesForJoinedRoomsAsync(Guid userId)
|
||||
{
|
||||
var userRooms = await db.ChatMembers
|
||||
.Where(m => m.AccountId == userId)
|
||||
@ -149,7 +149,7 @@ public class ChatService(AppDatabase db, IServiceScopeFactory scopeFactory)
|
||||
return call;
|
||||
}
|
||||
|
||||
public async Task EndCallAsync(long roomId)
|
||||
public async Task EndCallAsync(Guid roomId)
|
||||
{
|
||||
var call = await GetCallOngoingAsync(roomId);
|
||||
if (call is null) throw new InvalidOperationException("No ongoing call was not found.");
|
||||
@ -170,7 +170,7 @@ public class ChatService(AppDatabase db, IServiceScopeFactory scopeFactory)
|
||||
}, call.Sender, call.Room);
|
||||
}
|
||||
|
||||
public async Task<RealtimeCall?> GetCallOngoingAsync(long roomId)
|
||||
public async Task<RealtimeCall?> GetCallOngoingAsync(Guid roomId)
|
||||
{
|
||||
return await db.ChatRealtimeCall
|
||||
.Where(c => c.RoomId == roomId)
|
||||
@ -180,7 +180,7 @@ public class ChatService(AppDatabase db, IServiceScopeFactory scopeFactory)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<SyncResponse> GetSyncDataAsync(long roomId, long lastSyncTimestamp)
|
||||
public async Task<SyncResponse> GetSyncDataAsync(Guid roomId, long lastSyncTimestamp)
|
||||
{
|
||||
var timestamp = Instant.FromUnixTimeMilliseconds(lastSyncTimestamp);
|
||||
var changes = await db.ChatMessages
|
||||
|
@ -27,7 +27,7 @@ public class Message : ModelBase
|
||||
|
||||
public Guid SenderId { get; set; }
|
||||
public ChatMember Sender { get; set; } = null!;
|
||||
public long ChatRoomId { get; set; }
|
||||
public Guid ChatRoomId { get; set; }
|
||||
[JsonIgnore] public ChatRoom ChatRoom { get; set; } = null!;
|
||||
|
||||
public Message Clone()
|
||||
|
@ -10,6 +10,6 @@ public class RealtimeCall : ModelBase
|
||||
|
||||
public Guid SenderId { get; set; }
|
||||
public ChatMember Sender { get; set; } = null!;
|
||||
public long RoomId { get; set; }
|
||||
public Guid RoomId { get; set; }
|
||||
public ChatRoom Room { get; set; } = null!;
|
||||
}
|
@ -32,9 +32,9 @@ public class RealtimeCallController(IConfiguration configuration, AppDatabase db
|
||||
public string Token { get; set; } = null!;
|
||||
}
|
||||
|
||||
[HttpGet("{roomId:long}")]
|
||||
[HttpGet("{roomId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<RealtimeChatToken>> GetToken(long roomId)
|
||||
public async Task<ActionResult<RealtimeChatToken>> GetToken(Guid roomId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
|
||||
@ -60,9 +60,9 @@ public class RealtimeCallController(IConfiguration configuration, AppDatabase db
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("{roomId:long}")]
|
||||
[HttpPost("{roomId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> StartCall(long roomId)
|
||||
public async Task<IActionResult> StartCall(Guid roomId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
|
||||
@ -79,9 +79,9 @@ public class RealtimeCallController(IConfiguration configuration, AppDatabase db
|
||||
return Ok(call);
|
||||
}
|
||||
|
||||
[HttpDelete("{roomId:long}")]
|
||||
[HttpDelete("{roomId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> EndCall(long roomId)
|
||||
public async Task<IActionResult> EndCall(Guid roomId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
|
||||
|
Reference in New Issue
Block a user