From 871281f86c1ab39a5627b351353390ea2d993e23 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Thu, 23 Feb 2023 11:45:46 +0100 Subject: [PATCH] Reformatted typing code --- .../Services/Support/SupportAdminService.cs | 24 +++++++------ .../Services/Support/SupportClientService.cs | 24 +++++++------ .../Shared/Views/Admin/Support/View.razor | 18 +++++++--- Moonlight/Shared/Views/Support.razor | 35 ++++++++++--------- 4 files changed, 60 insertions(+), 41 deletions(-) diff --git a/Moonlight/App/Services/Support/SupportAdminService.cs b/Moonlight/App/Services/Support/SupportAdminService.cs index 682ddf61..2dabdef1 100644 --- a/Moonlight/App/Services/Support/SupportAdminService.cs +++ b/Moonlight/App/Services/Support/SupportAdminService.cs @@ -52,6 +52,8 @@ public class SupportAdminService }); } + #region Typing + private void HandleTyping(User user) { var name = $"{user.FirstName} {user.LastName}"; @@ -84,6 +86,18 @@ public class SupportAdminService return TypingUsers.ToArray(); } } + + public Task TriggerTyping() + { + Task.Run(async () => + { + await MessageService.Emit($"support.{Recipient.Id}.admintyping", Self); + }); + + return Task.CompletedTask; + } + + #endregion public async Task GetMessages() { @@ -110,16 +124,6 @@ public class SupportAdminService await SupportServerService.Close(Recipient); } - public Task TriggerTyping() - { - Task.Run(async () => - { - await MessageService.Emit($"support.{Recipient.Id}.admintyping", Self); - }); - - return Task.CompletedTask; - } - public void Dispose() { MessageService.Unsubscribe($"support.{Recipient.Id}.message", this); diff --git a/Moonlight/App/Services/Support/SupportClientService.cs b/Moonlight/App/Services/Support/SupportClientService.cs index 328b3a9e..5b4f54dc 100644 --- a/Moonlight/App/Services/Support/SupportClientService.cs +++ b/Moonlight/App/Services/Support/SupportClientService.cs @@ -49,6 +49,8 @@ public class SupportClientService : IDisposable return Task.CompletedTask; }); } + + #region Typing private void HandleTyping(User user) { @@ -82,7 +84,19 @@ public class SupportClientService : IDisposable return TypingUsers.ToArray(); } } + + public Task TriggerTyping() + { + Task.Run(async () => + { + await MessageService.Emit($"support.{Self.Id}.typing", Self); + }); + return Task.CompletedTask; + } + + #endregion + public async Task GetMessages() { return await SupportServerService.GetMessages(Self); @@ -101,16 +115,6 @@ public class SupportClientService : IDisposable Self ); } - - public Task TriggerTyping() - { - Task.Run(async () => - { - await MessageService.Emit($"support.{Self.Id}.typing", Self); - }); - - return Task.CompletedTask; - } public void Dispose() { diff --git a/Moonlight/Shared/Views/Admin/Support/View.razor b/Moonlight/Shared/Views/Admin/Support/View.razor index e81ede75..fcf77c66 100644 --- a/Moonlight/Shared/Views/Admin/Support/View.razor +++ b/Moonlight/Shared/Views/Admin/Support/View.razor @@ -198,11 +198,8 @@ await SupportAdminService.Start(User); } } - - private async void OnUpdateTyping(object? sender, EventArgs e) - { - await InvokeAsync(StateHasChanged); - } + + #region Message handling private async void OnNewMessage(object? sender, SupportMessage e) { @@ -214,6 +211,8 @@ { Messages = (await SupportAdminService.GetMessages()).Reverse().ToArray(); } + + #endregion private async Task Send() { @@ -225,6 +224,8 @@ { await SupportAdminService.Close(); } + + #region Typing private async Task OnTyping() { @@ -235,4 +236,11 @@ await SupportAdminService.TriggerTyping(); } } + + private async void OnUpdateTyping(object? sender, EventArgs e) + { + await InvokeAsync(StateHasChanged); + } + + #endregion } \ No newline at end of file diff --git a/Moonlight/Shared/Views/Support.razor b/Moonlight/Shared/Views/Support.razor index 3bd8e490..68bdf0db 100644 --- a/Moonlight/Shared/Views/Support.razor +++ b/Moonlight/Shared/Views/Support.razor @@ -6,7 +6,6 @@ @using Moonlight.App.Services.Support @inject ResourceService ResourceService -@inject IdentityService IdentityService @inject SupportClientService SupportClientService @inject SmartTranslateService SmartTranslateService @@ -143,8 +142,6 @@ @code { - private User User; - private SupportMessage[] Messages; private string Content = ""; @@ -152,8 +149,6 @@ private async Task Load(LazyLoader lazyLoader) { - User = (await IdentityService.Get())!; - await lazyLoader.SetText("Starting chat client"); SupportClientService.OnNewMessage += OnNewMessage; @@ -162,28 +157,34 @@ await SupportClientService.Start(); } - private async void OnUpdateTyping(object? sender, EventArgs e) - { - await InvokeAsync(StateHasChanged); - } - - private async void OnNewMessage(object? sender, SupportMessage e) - { - Messages = (await SupportClientService.GetMessages()).Reverse().ToArray(); - await InvokeAsync(StateHasChanged); - } - private async Task Send() { await SupportClientService.SendMessage(Content); Content = ""; await InvokeAsync(StateHasChanged); } + + #region Message handling + + private async void OnNewMessage(object? sender, SupportMessage e) + { + Messages = (await SupportClientService.GetMessages()).Reverse().ToArray(); + await InvokeAsync(StateHasChanged); + } private async Task LoadMessages(LazyLoader arg) { Messages = (await SupportClientService.GetMessages()).Reverse().ToArray(); } + + #endregion + + #region Typing + + private async void OnUpdateTyping(object? sender, EventArgs e) + { + await InvokeAsync(StateHasChanged); + } private async void OnTyping() { @@ -194,4 +195,6 @@ await SupportClientService.TriggerTyping(); } } + + #endregion } \ No newline at end of file