✨ Chat room member managements
This commit is contained in:
		| @@ -35,7 +35,9 @@ public class Profile : ModelBase | ||||
|     [MaxLength(256)] public string? LastName { get; set; } | ||||
|     [MaxLength(4096)] public string? Bio { get; set; } | ||||
|  | ||||
|     public string? PictureId { get; set; } | ||||
|     public Storage.CloudFile? Picture { get; set; } | ||||
|     public string? BackgroundId { get; set; } | ||||
|     public Storage.CloudFile? Background { get; set; } | ||||
|  | ||||
|     [JsonIgnore] public Account Account { get; set; } = null!; | ||||
|   | ||||
| @@ -25,8 +25,6 @@ public class AccountController( | ||||
|     { | ||||
|         var account = await db.Accounts | ||||
|             .Include(e => e.Profile) | ||||
|             .Include(e => e.Profile.Picture) | ||||
|             .Include(e => e.Profile.Background) | ||||
|             .Where(a => a.Name == name) | ||||
|             .FirstOrDefaultAsync(); | ||||
|         return account is null ? new NotFoundResult() : account; | ||||
| @@ -114,8 +112,6 @@ public class AccountController( | ||||
|  | ||||
|         var account = await db.Accounts | ||||
|             .Include(e => e.Profile) | ||||
|             .Include(e => e.Profile.Picture) | ||||
|             .Include(e => e.Profile.Background) | ||||
|             .Where(e => e.Id == userId) | ||||
|             .FirstOrDefaultAsync(); | ||||
|  | ||||
| @@ -202,4 +198,17 @@ public class AccountController( | ||||
|  | ||||
|         return profile; | ||||
|     } | ||||
|  | ||||
|     [HttpGet("search")] | ||||
|     public async Task<List<Account>> Search([FromQuery] string query, [FromQuery] int take = 20) | ||||
|     { | ||||
|         if (string.IsNullOrWhiteSpace(query)) | ||||
|             return []; | ||||
|         return await db.Accounts | ||||
|             .Include(e => e.Profile) | ||||
|             .Where(a => EF.Functions.ILike(a.Name, $"%{query}%") || | ||||
|                         EF.Functions.ILike(a.Nick, $"%{query}%")) | ||||
|             .Take(take) | ||||
|             .ToListAsync(); | ||||
|     } | ||||
| } | ||||
| @@ -1,5 +1,6 @@ | ||||
| using CorePush.Apple; | ||||
| using CorePush.Firebase; | ||||
| using DysonNetwork.Sphere.Connection; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using NodaTime; | ||||
|  | ||||
| @@ -8,18 +9,21 @@ namespace DysonNetwork.Sphere.Account; | ||||
| public class NotificationService | ||||
| { | ||||
|     private readonly AppDatabase _db; | ||||
|     private readonly WebSocketService _ws; | ||||
|     private readonly ILogger<NotificationService> _logger; | ||||
|     private readonly FirebaseSender? _fcm; | ||||
|     private readonly ApnSender? _apns; | ||||
|  | ||||
|     public NotificationService( | ||||
|         AppDatabase db, | ||||
|         WebSocketService ws, | ||||
|         IConfiguration cfg, | ||||
|         IHttpClientFactory clientFactory, | ||||
|         ILogger<NotificationService> logger | ||||
|     ) | ||||
|     { | ||||
|         _db = db; | ||||
|         _ws = ws; | ||||
|         _logger = logger; | ||||
|  | ||||
|         var cfgSection = cfg.GetSection("Notifications:Push"); | ||||
| @@ -83,6 +87,7 @@ public class NotificationService | ||||
|  | ||||
|     public async Task<Notification> SendNotification( | ||||
|         Account account, | ||||
|         string topic, | ||||
|         string? title = null, | ||||
|         string? subtitle = null, | ||||
|         string? content = null, | ||||
| @@ -97,6 +102,7 @@ public class NotificationService | ||||
|  | ||||
|         var notification = new Notification | ||||
|         { | ||||
|             Topic = topic, | ||||
|             Title = title, | ||||
|             Subtitle = subtitle, | ||||
|             Content = content, | ||||
| @@ -114,7 +120,11 @@ public class NotificationService | ||||
|  | ||||
|     public async Task DeliveryNotification(Notification notification) | ||||
|     { | ||||
|         // TODO send websocket | ||||
|         _ws.SendPacketToAccount(notification.AccountId, new WebSocketPacket | ||||
|         { | ||||
|             Type = "notifications.new", | ||||
|             Data = notification | ||||
|         }); | ||||
|  | ||||
|         // Pushing the notification | ||||
|         var subscribers = await _db.NotificationPushSubscriptions | ||||
|   | ||||
		Reference in New Issue
	
	Block a user