Merge pull request #91 from Moonlight-Panel/ImproveSupportChat

Removed useless logging. Switched to cache mode for support chat
This commit is contained in:
Marcel Baumgartner 2023-04-23 17:59:40 +02:00 committed by GitHub
commit 2a20665717
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 18 deletions

View file

@ -116,6 +116,8 @@ public class EventSystem
{
Task.WaitAll(tasks.ToArray());
Storage.Remove(hashCode);
if(Debug)
Logger.Debug($"Completed all event tasks for '{id}' and removed object from storage");
});

View file

@ -85,8 +85,6 @@ public class DiscordNotificationService
private async Task SendNotification(string content, Action<EmbedBuilder>? embed = null)
{
Logger.Debug(Client);
var e = new EmbedBuilder();
embed?.Invoke(e);

View file

@ -55,12 +55,14 @@ public class SupportChatAdminService
return await ServerService.GetMessages(Recipient);
}
public async Task SendMessage(string content)
public async Task<SupportChatMessage> 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)

View file

@ -54,12 +54,14 @@ public class SupportChatClientService : IDisposable
return await ServerService.GetMessages(User);
}
public async Task SendMessage(string content)
public async Task<SupportChatMessage> 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)

View file

@ -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<SupportChatMessage> SendMessage(User recipient, string content, User? sender, string? attachment = null)
{
using var scope = ServiceScopeFactory.CreateScope();
var msgRepo = scope.ServiceProvider.GetRequiredService<Repository<SupportChatMessage>>();
@ -86,6 +86,8 @@ public class SupportChatServerService
await Event.Emit("supportChat.message", ticketStartFinal);
await Event.Emit("supportChat.new", recipient);
}
return finalMessage;
}
public Task<Dictionary<User, SupportChatMessage?>> GetOpenChats()

View file

@ -180,7 +180,7 @@
private User? User;
private SupportChatMessage[] Messages = Array.Empty<SupportChatMessage>();
private List<SupportChatMessage> Messages = new();
private string[] Typing = Array.Empty<string>();
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);
}

View file

@ -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<SupportChatMessage>();
private List<SupportChatMessage> Messages = new();
private string[] Typing = Array.Empty<string>();
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,7 +179,7 @@
private async Task OnMessage(SupportChatMessage message)
{
Messages = await ClientService.GetMessages();
Messages.Insert(0, message);
//TODO: Sound when message from system or admin
@ -187,9 +188,14 @@
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);
}