Merge pull request #91 from Moonlight-Panel/ImproveSupportChat
Removed useless logging. Switched to cache mode for support chat
This commit is contained in:
commit
2a20665717
|
@ -116,6 +116,8 @@ public class EventSystem
|
||||||
{
|
{
|
||||||
Task.WaitAll(tasks.ToArray());
|
Task.WaitAll(tasks.ToArray());
|
||||||
Storage.Remove(hashCode);
|
Storage.Remove(hashCode);
|
||||||
|
|
||||||
|
if(Debug)
|
||||||
Logger.Debug($"Completed all event tasks for '{id}' and removed object from storage");
|
Logger.Debug($"Completed all event tasks for '{id}' and removed object from storage");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -85,8 +85,6 @@ public class DiscordNotificationService
|
||||||
|
|
||||||
private async Task SendNotification(string content, Action<EmbedBuilder>? embed = null)
|
private async Task SendNotification(string content, Action<EmbedBuilder>? embed = null)
|
||||||
{
|
{
|
||||||
Logger.Debug(Client);
|
|
||||||
|
|
||||||
var e = new EmbedBuilder();
|
var e = new EmbedBuilder();
|
||||||
embed?.Invoke(e);
|
embed?.Invoke(e);
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,14 @@ public class SupportChatAdminService
|
||||||
return await ServerService.GetMessages(Recipient);
|
return await ServerService.GetMessages(Recipient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendMessage(string content)
|
public async Task<SupportChatMessage> SendMessage(string content)
|
||||||
{
|
{
|
||||||
if (User != null)
|
if (User != null)
|
||||||
{
|
{
|
||||||
await ServerService.SendMessage(Recipient, content, User);
|
return await ServerService.SendMessage(Recipient, content, User);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task HandleTyping(User user)
|
private Task HandleTyping(User user)
|
||||||
|
|
|
@ -54,12 +54,14 @@ public class SupportChatClientService : IDisposable
|
||||||
return await ServerService.GetMessages(User);
|
return await ServerService.GetMessages(User);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendMessage(string content)
|
public async Task<SupportChatMessage> SendMessage(string content)
|
||||||
{
|
{
|
||||||
if (User != null)
|
if (User != null)
|
||||||
{
|
{
|
||||||
await ServerService.SendMessage(User, content, User);
|
return await ServerService.SendMessage(User, content, User);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task HandleTyping(User user)
|
private Task HandleTyping(User user)
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class SupportChatServerService
|
||||||
return Task.FromResult(messages);
|
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();
|
using var scope = ServiceScopeFactory.CreateScope();
|
||||||
var msgRepo = scope.ServiceProvider.GetRequiredService<Repository<SupportChatMessage>>();
|
var msgRepo = scope.ServiceProvider.GetRequiredService<Repository<SupportChatMessage>>();
|
||||||
|
@ -86,6 +86,8 @@ public class SupportChatServerService
|
||||||
await Event.Emit("supportChat.message", ticketStartFinal);
|
await Event.Emit("supportChat.message", ticketStartFinal);
|
||||||
await Event.Emit("supportChat.new", recipient);
|
await Event.Emit("supportChat.new", recipient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return finalMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Dictionary<User, SupportChatMessage?>> GetOpenChats()
|
public Task<Dictionary<User, SupportChatMessage?>> GetOpenChats()
|
||||||
|
|
|
@ -180,7 +180,7 @@
|
||||||
|
|
||||||
private User? User;
|
private User? User;
|
||||||
|
|
||||||
private SupportChatMessage[] Messages = Array.Empty<SupportChatMessage>();
|
private List<SupportChatMessage> Messages = new();
|
||||||
private string[] Typing = Array.Empty<string>();
|
private string[] Typing = Array.Empty<string>();
|
||||||
|
|
||||||
private string Content = "";
|
private string Content = "";
|
||||||
|
@ -203,7 +203,7 @@
|
||||||
|
|
||||||
private async Task LoadMessages(LazyLoader arg)
|
private async Task LoadMessages(LazyLoader arg)
|
||||||
{
|
{
|
||||||
Messages = await AdminService.GetMessages();
|
Messages = (await AdminService.GetMessages()).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnTypingChanged(string[] typing)
|
private async Task OnTypingChanged(string[] typing)
|
||||||
|
@ -215,7 +215,7 @@
|
||||||
|
|
||||||
private async Task OnMessage(SupportChatMessage arg)
|
private async Task OnMessage(SupportChatMessage arg)
|
||||||
{
|
{
|
||||||
Messages = await AdminService.GetMessages();
|
Messages.Insert(0, arg);
|
||||||
|
|
||||||
//TODO: Sound when message from system or admin
|
//TODO: Sound when message from system or admin
|
||||||
|
|
||||||
|
@ -224,9 +224,14 @@
|
||||||
|
|
||||||
private async Task Send()
|
private async Task Send()
|
||||||
{
|
{
|
||||||
await AdminService.SendMessage(Content);
|
if(string.IsNullOrEmpty(Content))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var message = await AdminService.SendMessage(Content);
|
||||||
Content = "";
|
Content = "";
|
||||||
|
|
||||||
|
Messages.Insert(0, message);
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
@using Moonlight.App.Database.Entities
|
@using Moonlight.App.Database.Entities
|
||||||
@using Moonlight.App.Helpers
|
@using Moonlight.App.Helpers
|
||||||
@using Moonlight.App.Services.SupportChat
|
@using Moonlight.App.Services.SupportChat
|
||||||
|
@using Logging.Net
|
||||||
|
|
||||||
@inject ResourceService ResourceService
|
@inject ResourceService ResourceService
|
||||||
@inject SupportChatClientService ClientService
|
@inject SupportChatClientService ClientService
|
||||||
|
@ -148,7 +149,7 @@
|
||||||
[CascadingParameter]
|
[CascadingParameter]
|
||||||
public User User { get; set; }
|
public User User { get; set; }
|
||||||
|
|
||||||
private SupportChatMessage[] Messages = Array.Empty<SupportChatMessage>();
|
private List<SupportChatMessage> Messages = new();
|
||||||
private string[] Typing = Array.Empty<string>();
|
private string[] Typing = Array.Empty<string>();
|
||||||
|
|
||||||
private string Content = "";
|
private string Content = "";
|
||||||
|
@ -166,7 +167,7 @@
|
||||||
|
|
||||||
private async Task LoadMessages(LazyLoader arg)
|
private async Task LoadMessages(LazyLoader arg)
|
||||||
{
|
{
|
||||||
Messages = await ClientService.GetMessages();
|
Messages = (await ClientService.GetMessages()).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnTypingChanged(string[] typing)
|
private async Task OnTypingChanged(string[] typing)
|
||||||
|
@ -178,7 +179,7 @@
|
||||||
|
|
||||||
private async Task OnMessage(SupportChatMessage message)
|
private async Task OnMessage(SupportChatMessage message)
|
||||||
{
|
{
|
||||||
Messages = await ClientService.GetMessages();
|
Messages.Insert(0, message);
|
||||||
|
|
||||||
//TODO: Sound when message from system or admin
|
//TODO: Sound when message from system or admin
|
||||||
|
|
||||||
|
@ -187,9 +188,14 @@
|
||||||
|
|
||||||
private async Task Send()
|
private async Task Send()
|
||||||
{
|
{
|
||||||
await ClientService.SendMessage(Content);
|
if(string.IsNullOrEmpty(Content))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var message = await ClientService.SendMessage(Content);
|
||||||
Content = "";
|
Content = "";
|
||||||
|
|
||||||
|
Messages.Insert(0, message);
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue