From 2f957927d44250e93acc17e3314fb440ed509594 Mon Sep 17 00:00:00 2001 From: Emilia <emilia@jumpsca.re> Date: Mon, 3 Mar 2025 17:48:58 +0200 Subject: [PATCH] Make the thing slightly cleaner --- Blacklight/Views/MainWindow.axaml | 2 +- Lightquark.NET/ClientMethods/Message.cs | 60 ++++++++++++------------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/Blacklight/Views/MainWindow.axaml b/Blacklight/Views/MainWindow.axaml index f835523..6b12f56 100644 --- a/Blacklight/Views/MainWindow.axaml +++ b/Blacklight/Views/MainWindow.axaml @@ -7,7 +7,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:login="clr-namespace:Blacklight.Views.Login" xmlns:util="clr-namespace:Blacklight.Util" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" d:DesignWidth="1100" d:DesignHeight="700" x:Class="Blacklight.Views.MainWindow" x:DataType="vm:MainWindowViewModel" Icon="/Assets/avalonia-logo.ico" diff --git a/Lightquark.NET/ClientMethods/Message.cs b/Lightquark.NET/ClientMethods/Message.cs index ef3fd7c..c35945b 100644 --- a/Lightquark.NET/ClientMethods/Message.cs +++ b/Lightquark.NET/ClientMethods/Message.cs @@ -79,47 +79,43 @@ public partial class Client foreach (var msg in res.Response.Messages) { var replyAttribute = msg.SpecialAttributes.FirstOrDefault(a => a["type"]?.ToString() == "reply"); - if (replyAttribute != null) + if (replyAttribute == null) continue; + if (!ObjectId.TryParse(replyAttribute["replyTo"]?.ToString(), out var replyToId)) continue; + var replyToMsg = res.Response.Messages.FirstOrDefault(m => m.Id == replyToId); + if (replyToMsg == null) { - if (ObjectId.TryParse(replyAttribute["replyTo"]?.ToString(), out var replyToId)) + replyToMsg = Messages[channelId].FirstOrDefault(m => m.Id == replyToId); + if (replyToMsg == null) { - var replyToMsg = res.Response.Messages.FirstOrDefault(m => m.Id == replyToId); - if (replyToMsg == null) + var replyRes = await CallRpc<GetMessageResponse>("GET", $"{Version}/channel/{channelId}/messages/{replyToId}"); + if (replyRes.Request.Success) { - replyToMsg = Messages[channelId].FirstOrDefault(m => m.Id == replyToId); - if (replyToMsg == null) - { - var replyRes = await CallRpc<GetMessageResponse>("GET", $"{Version}/channel/{channelId}/messages/{replyToId}"); - if (replyRes.Request.Success) - { - Log.Information("Reply message found via API"); - replyToMsg = replyRes.Response.Data; - } - else - { - Log.Error("Couldn't fetch reply message {ReplyMsgId} due to {Reason}", replyToId, replyRes.Response.Message); - replyToMsg = new Message - { - Id = replyToId, - Author = CurrentUser, - Content = "Message couldn't be loaded", - Status = MessageStatus.Fail - }; - } - } - else - { - Log.Information("Reply message found in cache"); - } + Log.Information("Reply message found via API"); + replyToMsg = replyRes.Response.Data; } else { - Log.Information("Reply message found in fetched messages"); + Log.Error("Couldn't fetch reply message {ReplyMsgId} due to {Reason}", replyToId, replyRes.Response.Message); + replyToMsg = new Message + { + Id = replyToId, + Author = CurrentUser, + Content = "Message couldn't be loaded", + Status = MessageStatus.Fail + }; } - - msg.ReplyToMessage = replyToMsg; + } + else + { + Log.Information("Reply message found in cache"); } } + else + { + Log.Information("Reply message found in fetched messages"); + } + + msg.ReplyToMessage = replyToMsg; } return res.Response.Messages; -- GitLab