💥 Update push notification

This commit is contained in:
2025-06-01 02:51:39 +08:00
parent 57775eb0a1
commit 7dee2a15e7
6 changed files with 10 additions and 17 deletions

View File

@ -12,7 +12,7 @@ namespace DysonNetwork.Sphere.Chat;
[ApiController]
[Route("/chat")]
public partial class ChatController(AppDatabase db, ChatService cs) : ControllerBase
public partial class ChatController(AppDatabase db, ChatService cs, ChatRoomService crs) : ControllerBase
{
public class MarkMessageReadRequest
{
@ -148,13 +148,7 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
(request.AttachmentsId == null || request.AttachmentsId.Count == 0))
return BadRequest("You cannot send an empty message.");
var member = await db.ChatMembers
.Where(m => m.AccountId == currentUser.Id && m.ChatRoomId == roomId)
.Include(m => m.ChatRoom)
.Include(m => m.ChatRoom.Realm)
.Include(m => m.Account)
.Include(m => m.Account.Profile)
.FirstOrDefaultAsync();
var member = await crs.GetRoomMember(currentUser.Id, roomId);
if (member == null || member.Role < ChatMemberRole.Member)
return StatusCode(403, "You need to be a normal member to send messages here.");
@ -219,7 +213,6 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
return Ok(result);
}
[HttpPatch("{roomId:guid}/messages/{messageId:guid}")]
[Authorize]
public async Task<ActionResult> UpdateMessage([FromBody] SendMessageRequest request, Guid roomId, Guid messageId)

View File

@ -33,7 +33,7 @@ public class ChatRoomService(AppDatabase db, ICacheService cache)
return members;
}
public async Task<ChatMember?> GetChannelMember(Guid accountId, Guid chatRoomId)
public async Task<ChatMember?> GetRoomMember(Guid accountId, Guid chatRoomId)
{
var cacheKey = string.Format(ChatMemberCacheKey, accountId, chatRoomId);
var member = await cache.GetAsync<ChatMember?>(cacheKey);
@ -42,6 +42,8 @@ public class ChatRoomService(AppDatabase db, ICacheService cache)
member = await db.ChatMembers
.Include(m => m.Account)
.ThenInclude(m => m.Profile)
.Include(m => m.ChatRoom)
.ThenInclude(m => m.Realm)
.Where(m => m.AccountId == accountId && m.ChatRoomId == chatRoomId)
.FirstOrDefaultAsync();

View File

@ -119,7 +119,7 @@ public class RealtimeCallController(
// Fetch the ChatMember profile if we have an account ID
if (p.AccountId.HasValue)
participant.Profile = await chatRoomService.GetChannelMember(p.AccountId.Value, roomId);
participant.Profile = await chatRoomService.GetRoomMember(p.AccountId.Value, roomId);
participants.Add(participant);
}