From 1a224441228d07440f279ce4a15c9a043b8cda6d Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 12 Mar 2025 04:44:19 +0100 Subject: Part of event rendering --- ModerationClient/ViewModels/ClientViewModel.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'ModerationClient/ViewModels/ClientViewModel.cs') diff --git a/ModerationClient/ViewModels/ClientViewModel.cs b/ModerationClient/ViewModels/ClientViewModel.cs index ab4f2da..9403123 100644 --- a/ModerationClient/ViewModels/ClientViewModel.cs +++ b/ModerationClient/ViewModels/ClientViewModel.cs @@ -175,7 +175,14 @@ public partial class ClientViewModel : ViewModelBase { if (string.IsNullOrWhiteSpace(AllRooms[room.Key].Name)) { AllRooms[room.Key].Name = "Loading..."; - tasks.Add(_authService.Homeserver!.GetRoom(room.Key).GetNameOrFallbackAsync().ContinueWith(r => AllRooms[room.Key].Name = r.Result)); + tasks.Add(_authService.Homeserver!.GetRoom(room.Key).GetNameOrFallbackAsync().ContinueWith(r => { + if (r.IsFaulted) { + _logger.LogError(r.Exception, "Error getting room name for {RoomKey}", room.Key); + return AllRooms[room.Key].Name = "Error loading room name"; + } + + return AllRooms[room.Key].Name = r.Result; + })); // Status = $"Getting room name for {room.Key}..."; // AllRooms[room.Key].Name = await _authService.Homeserver!.GetRoom(room.Key).GetNameOrFallbackAsync(); } @@ -196,7 +203,8 @@ public partial class ClientViewModel : ViewModelBase { await AwaitTasks(tasks, "Waiting for {0}/{1} tasks while applying room changes..."); } - private ExpiringSemaphoreCache _profileCache = new(); + private ExpiringSemaphoreCache _profileCache = new(); + private async Task ApplyDirectMessagesChanges(StateEventResponse evt) { _logger.LogCritical("Direct messages updated!"); var dms = evt.RawContent.Deserialize>(); @@ -207,9 +215,13 @@ public partial class ClientViewModel : ViewModelBase { if (space is null) { space = new SpaceNode { Name = userId, RoomID = userId }; // tasks.Add(_authService.Homeserver!.GetProfileAsync(userId) - // .ContinueWith(r => space.Name = string.IsNullOrWhiteSpace(r.Result.DisplayName) ? userId : r.Result.DisplayName)); + // .ContinueWith(r => space.Name = string.IsNullOrWhiteSpace(r.Result.DisplayName) ? userId : r.Result.DisplayName)); tasks.Add(_profileCache.GetOrAdd(userId, async () => await _authService.Homeserver!.GetProfileAsync(userId), TimeSpan.FromMinutes(5)) - .ContinueWith(r => string.IsNullOrWhiteSpace(r.Result.DisplayName) ? userId : r.Result.DisplayName)); + .ContinueWith(r => { + if (!r.IsFaulted) + return string.IsNullOrWhiteSpace(r.Result.DisplayName) ? userId : r.Result.DisplayName; + return userId; + })); DirectMessages.ChildSpaces.Add(space); } -- cgit 1.5.1