Reformatted typing code

This commit is contained in:
Marcel Baumgartner 2023-02-23 11:45:46 +01:00
parent d02781b13a
commit 871281f86c
4 changed files with 60 additions and 41 deletions

View file

@ -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<SupportMessage[]> 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);

View file

@ -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<SupportMessage[]> 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()
{

View file

@ -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
}

View file

@ -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
}