💥 Update push notification
This commit is contained in:
parent
57775eb0a1
commit
7dee2a15e7
@ -206,12 +206,10 @@ public class NotificationService(
|
|||||||
["notif_id"] = notification.Id.ToString(),
|
["notif_id"] = notification.Id.ToString(),
|
||||||
["apns_id"] = notification.Id.ToString(),
|
["apns_id"] = notification.Id.ToString(),
|
||||||
["topic"] = _notifyTopic,
|
["topic"] = _notifyTopic,
|
||||||
["category"] = notification.Topic,
|
|
||||||
["tokens"] = deviceTokens,
|
["tokens"] = deviceTokens,
|
||||||
["alert"] = new Dictionary<string, object>(),
|
|
||||||
["data"] = new Dictionary<string, object>
|
["data"] = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
["d_topic"] = notification.Topic,
|
["type"] = notification.Topic,
|
||||||
["meta"] = notification.Meta ?? new Dictionary<string, object>(),
|
["meta"] = notification.Meta ?? new Dictionary<string, object>(),
|
||||||
},
|
},
|
||||||
["mutable_content"] = true,
|
["mutable_content"] = true,
|
||||||
@ -237,7 +235,7 @@ public class NotificationService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (notification.Priority >= 5)
|
if (notification.Priority >= 5)
|
||||||
dict["sound"] = "default";
|
dict["name"] = "default";
|
||||||
|
|
||||||
dict["platform"] = platformCode;
|
dict["platform"] = platformCode;
|
||||||
dict["alert"] = alertDict;
|
dict["alert"] = alertDict;
|
||||||
|
@ -12,7 +12,7 @@ namespace DysonNetwork.Sphere.Chat;
|
|||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/chat")]
|
[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
|
public class MarkMessageReadRequest
|
||||||
{
|
{
|
||||||
@ -148,13 +148,7 @@ public partial class ChatController(AppDatabase db, ChatService cs) : Controller
|
|||||||
(request.AttachmentsId == null || request.AttachmentsId.Count == 0))
|
(request.AttachmentsId == null || request.AttachmentsId.Count == 0))
|
||||||
return BadRequest("You cannot send an empty message.");
|
return BadRequest("You cannot send an empty message.");
|
||||||
|
|
||||||
var member = await db.ChatMembers
|
var member = await crs.GetRoomMember(currentUser.Id, roomId);
|
||||||
.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();
|
|
||||||
if (member == null || member.Role < ChatMemberRole.Member)
|
if (member == null || member.Role < ChatMemberRole.Member)
|
||||||
return StatusCode(403, "You need to be a normal member to send messages here.");
|
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);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpPatch("{roomId:guid}/messages/{messageId:guid}")]
|
[HttpPatch("{roomId:guid}/messages/{messageId:guid}")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<ActionResult> UpdateMessage([FromBody] SendMessageRequest request, Guid roomId, Guid messageId)
|
public async Task<ActionResult> UpdateMessage([FromBody] SendMessageRequest request, Guid roomId, Guid messageId)
|
||||||
|
@ -33,7 +33,7 @@ public class ChatRoomService(AppDatabase db, ICacheService cache)
|
|||||||
return members;
|
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 cacheKey = string.Format(ChatMemberCacheKey, accountId, chatRoomId);
|
||||||
var member = await cache.GetAsync<ChatMember?>(cacheKey);
|
var member = await cache.GetAsync<ChatMember?>(cacheKey);
|
||||||
@ -42,6 +42,8 @@ public class ChatRoomService(AppDatabase db, ICacheService cache)
|
|||||||
member = await db.ChatMembers
|
member = await db.ChatMembers
|
||||||
.Include(m => m.Account)
|
.Include(m => m.Account)
|
||||||
.ThenInclude(m => m.Profile)
|
.ThenInclude(m => m.Profile)
|
||||||
|
.Include(m => m.ChatRoom)
|
||||||
|
.ThenInclude(m => m.Realm)
|
||||||
.Where(m => m.AccountId == accountId && m.ChatRoomId == chatRoomId)
|
.Where(m => m.AccountId == accountId && m.ChatRoomId == chatRoomId)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ public class RealtimeCallController(
|
|||||||
|
|
||||||
// Fetch the ChatMember profile if we have an account ID
|
// Fetch the ChatMember profile if we have an account ID
|
||||||
if (p.AccountId.HasValue)
|
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);
|
participants.Add(participant);
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class MessageReadHandler(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sender = await crs.GetChannelMember(currentUser.Id, request.ChatRoomId);
|
var sender = await crs.GetRoomMember(currentUser.Id, request.ChatRoomId);
|
||||||
if (sender is null)
|
if (sender is null)
|
||||||
{
|
{
|
||||||
await socket.SendAsync(
|
await socket.SendAsync(
|
||||||
|
@ -33,7 +33,7 @@ public class MessageTypingHandler(ChatRoomService crs) : IWebSocketPacketHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sender = await crs.GetChannelMember(currentUser.Id, request.ChatRoomId);
|
var sender = await crs.GetRoomMember(currentUser.Id, request.ChatRoomId);
|
||||||
if (sender is null)
|
if (sender is null)
|
||||||
{
|
{
|
||||||
await socket.SendAsync(
|
await socket.SendAsync(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user