diff --git a/Moonlight/App/Events/EventSystem.cs b/Moonlight/App/Events/EventSystem.cs index 74c67e0b..1d0f1d40 100644 --- a/Moonlight/App/Events/EventSystem.cs +++ b/Moonlight/App/Events/EventSystem.cs @@ -116,7 +116,9 @@ public class EventSystem { Task.WaitAll(tasks.ToArray()); Storage.Remove(hashCode); - Logger.Debug($"Completed all event tasks for '{id}' and removed object from storage"); + + if(Debug) + Logger.Debug($"Completed all event tasks for '{id}' and removed object from storage"); }); if(Debug) diff --git a/Moonlight/App/Services/DiscordNotificationService.cs b/Moonlight/App/Services/DiscordNotificationService.cs index 0fc0a0c6..41ea9a0b 100644 --- a/Moonlight/App/Services/DiscordNotificationService.cs +++ b/Moonlight/App/Services/DiscordNotificationService.cs @@ -85,8 +85,6 @@ public class DiscordNotificationService private async Task SendNotification(string content, Action? embed = null) { - Logger.Debug(Client); - var e = new EmbedBuilder(); embed?.Invoke(e); diff --git a/Moonlight/App/Services/SupportChat/SupportChatAdminService.cs b/Moonlight/App/Services/SupportChat/SupportChatAdminService.cs index 2f8307d0..d613fb8f 100644 --- a/Moonlight/App/Services/SupportChat/SupportChatAdminService.cs +++ b/Moonlight/App/Services/SupportChat/SupportChatAdminService.cs @@ -55,12 +55,14 @@ public class SupportChatAdminService return await ServerService.GetMessages(Recipient); } - public async Task SendMessage(string content) + public async Task SendMessage(string content) { if (User != null) { - await ServerService.SendMessage(Recipient, content, User); + return await ServerService.SendMessage(Recipient, content, User); } + + return null!; } private Task HandleTyping(User user) diff --git a/Moonlight/App/Services/SupportChat/SupportChatClientService.cs b/Moonlight/App/Services/SupportChat/SupportChatClientService.cs index 8c3bd744..94060655 100644 --- a/Moonlight/App/Services/SupportChat/SupportChatClientService.cs +++ b/Moonlight/App/Services/SupportChat/SupportChatClientService.cs @@ -54,12 +54,14 @@ public class SupportChatClientService : IDisposable return await ServerService.GetMessages(User); } - public async Task SendMessage(string content) + public async Task SendMessage(string content) { if (User != null) { - await ServerService.SendMessage(User, content, User); + return await ServerService.SendMessage(User, content, User); } + + return null!; } private Task HandleTyping(User user) diff --git a/Moonlight/App/Services/SupportChat/SupportChatServerService.cs b/Moonlight/App/Services/SupportChat/SupportChatServerService.cs index c9bf5a4d..7fd0555c 100644 --- a/Moonlight/App/Services/SupportChat/SupportChatServerService.cs +++ b/Moonlight/App/Services/SupportChat/SupportChatServerService.cs @@ -39,7 +39,7 @@ public class SupportChatServerService return Task.FromResult(messages); } - public async Task SendMessage(User recipient, string content, User? sender, string? attachment = null) + public async Task SendMessage(User recipient, string content, User? sender, string? attachment = null) { using var scope = ServiceScopeFactory.CreateScope(); var msgRepo = scope.ServiceProvider.GetRequiredService>(); @@ -86,6 +86,8 @@ public class SupportChatServerService await Event.Emit("supportChat.message", ticketStartFinal); await Event.Emit("supportChat.new", recipient); } + + return finalMessage; } public Task> GetOpenChats() diff --git a/Moonlight/Shared/Views/Admin/Support/View.razor b/Moonlight/Shared/Views/Admin/Support/View.razor index 87c4c683..bfd7d8f3 100644 --- a/Moonlight/Shared/Views/Admin/Support/View.razor +++ b/Moonlight/Shared/Views/Admin/Support/View.razor @@ -180,7 +180,7 @@ private User? User; - private SupportChatMessage[] Messages = Array.Empty(); + private List Messages = new(); private string[] Typing = Array.Empty(); private string Content = ""; @@ -203,7 +203,7 @@ private async Task LoadMessages(LazyLoader arg) { - Messages = await AdminService.GetMessages(); + Messages = (await AdminService.GetMessages()).ToList(); } private async Task OnTypingChanged(string[] typing) @@ -215,7 +215,7 @@ private async Task OnMessage(SupportChatMessage arg) { - Messages = await AdminService.GetMessages(); + Messages.Insert(0, arg); //TODO: Sound when message from system or admin @@ -224,9 +224,14 @@ private async Task Send() { - await AdminService.SendMessage(Content); + if(string.IsNullOrEmpty(Content)) + return; + + var message = await AdminService.SendMessage(Content); Content = ""; + Messages.Insert(0, message); + await InvokeAsync(StateHasChanged); } diff --git a/Moonlight/Shared/Views/Support.razor b/Moonlight/Shared/Views/Support.razor index 1c0ee112..24a320c0 100644 --- a/Moonlight/Shared/Views/Support.razor +++ b/Moonlight/Shared/Views/Support.razor @@ -3,6 +3,7 @@ @using Moonlight.App.Database.Entities @using Moonlight.App.Helpers @using Moonlight.App.Services.SupportChat +@using Logging.Net @inject ResourceService ResourceService @inject SupportChatClientService ClientService @@ -148,7 +149,7 @@ [CascadingParameter] public User User { get; set; } - private SupportChatMessage[] Messages = Array.Empty(); + private List Messages = new(); private string[] Typing = Array.Empty(); private string Content = ""; @@ -166,7 +167,7 @@ private async Task LoadMessages(LazyLoader arg) { - Messages = await ClientService.GetMessages(); + Messages = (await ClientService.GetMessages()).ToList(); } private async Task OnTypingChanged(string[] typing) @@ -178,18 +179,23 @@ private async Task OnMessage(SupportChatMessage message) { - Messages = await ClientService.GetMessages(); - - //TODO: Sound when message from system or admin + Messages.Insert(0, message); + + //TODO: Sound when message from system or admin await InvokeAsync(StateHasChanged); } private async Task Send() { - await ClientService.SendMessage(Content); + if(string.IsNullOrEmpty(Content)) + return; + + var message = await ClientService.SendMessage(Content); Content = ""; + Messages.Insert(0, message); + await InvokeAsync(StateHasChanged); }