From 5a0ff2ddfe516651e7b7267a0956eda6f4eebfa7 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 16 Jul 2026 19:57:23 +0200 Subject: [PATCH] Switch MessageModel to use attachments list and update related UI logic --- src/Decho/Models/MessageModel.cs | 12 ++--- src/Decho/Services/ConnectionService.cs | 25 +--------- src/Decho/ViewModels/MessageViewModel.cs | 18 ++----- src/Decho/Views/MessageItemView.axaml | 40 +++++++++------- src/Decho/Views/MessageItemView.axaml.cs | 61 ++++++++++++++---------- 5 files changed, 70 insertions(+), 86 deletions(-) diff --git a/src/Decho/Models/MessageModel.cs b/src/Decho/Models/MessageModel.cs index 8a96d06..b86f9dc 100644 --- a/src/Decho/Models/MessageModel.cs +++ b/src/Decho/Models/MessageModel.cs @@ -1,8 +1,8 @@ -using EchoHub.Core.Models; +using EchoHub.Core.DTOs; namespace Decho.Models; -public sealed class MessageModel(string id, UserModel author, DateTimeOffset sentAt, string content, string channelName, string? serverUrl = null, MessageType type = MessageType.Text, string? attachmentUrl = null, string? attachmentFileName = null, long? attachmentFileSize = null) +public sealed class MessageModel(string id, UserModel author, DateTimeOffset sentAt, string content, string channelName, string? serverUrl = null, List? attachments = null) { public string Id { get; } = id; @@ -16,11 +16,5 @@ public sealed class MessageModel(string id, UserModel author, DateTimeOffset sen public string? ServerUrl { get; } = serverUrl; - public MessageType Type { get; } = type; - - public string? AttachmentUrl { get; } = attachmentUrl; - - public string? AttachmentFileName { get; } = attachmentFileName; - - public long? AttachmentFileSize { get; } = attachmentFileSize; + public List Attachments { get; } = attachments ?? []; } \ No newline at end of file diff --git a/src/Decho/Services/ConnectionService.cs b/src/Decho/Services/ConnectionService.cs index eb8eb41..7f8331b 100644 --- a/src/Decho/Services/ConnectionService.cs +++ b/src/Decho/Services/ConnectionService.cs @@ -574,25 +574,7 @@ public sealed class ConnectionService : IDisposable dto.SenderUsername, dto.SenderNicknameColor); - MessageType type = MessageType.Text; - string? attachmentUrl = null; - string? attachmentFileName = null; - long? attachmentFileSize = null; - - if (dto.Attachments is { Count: > 0 }) - { - AttachmentDto first = dto.Attachments[0]; - type = first.Kind switch - { - AttachmentKind.Image => MessageType.Image, - AttachmentKind.Audio => MessageType.Audio, - AttachmentKind.File => MessageType.File, - _ => MessageType.File - }; - attachmentUrl = first.Url; - attachmentFileName = first.FileName; - attachmentFileSize = first.FileSize; - } + List attachments = dto.Attachments ?? []; return new MessageModel( dto.Id.ToString("N"), @@ -601,10 +583,7 @@ public sealed class ConnectionService : IDisposable dto.Content, dto.ChannelName, entry.Server.ServerUrl, - type, - attachmentUrl, - attachmentFileName, - attachmentFileSize); + attachments); } internal ServerConnection? GetConnection(string serverUrl) diff --git a/src/Decho/ViewModels/MessageViewModel.cs b/src/Decho/ViewModels/MessageViewModel.cs index 2eeaf35..41b20ae 100644 --- a/src/Decho/ViewModels/MessageViewModel.cs +++ b/src/Decho/ViewModels/MessageViewModel.cs @@ -3,7 +3,7 @@ using Avalonia.Media.Imaging; using Decho.Models; -using EchoHub.Core.Models; +using EchoHub.Core.DTOs; namespace Decho.ViewModels; @@ -11,8 +11,6 @@ public sealed class MessageViewModel(MessageModel model) : ViewModelBase { public MessageModel Model { get; } = model; - public Bitmap? CachedImage { get; set; } - public string AuthorName => Model.Author.DisplayName; public IBrush? AuthorColor @@ -40,22 +38,14 @@ public sealed class MessageViewModel(MessageModel model) : ViewModelBase public string? ServerUrl => Model.ServerUrl; - public MessageType Type => Model.Type; + public Dictionary ImageCache { get; } = []; - public bool HasAttachment => Model.AttachmentUrl is not null; + public IReadOnlyList Attachments => Model.Attachments; - public string? AttachmentFileName => Model.AttachmentFileName; - - public string? AttachmentUrl => Model.AttachmentUrl; - - public bool IsImage => Type == MessageType.Image; + public bool HasAttachments => Attachments.Count > 0; public bool ShowContent => !string.IsNullOrEmpty(Content); - public bool IsAudio => Type == MessageType.Audio; - - public bool IsFile => Type == MessageType.File; - public string TimeText { get diff --git a/src/Decho/Views/MessageItemView.axaml b/src/Decho/Views/MessageItemView.axaml index 1d4e5a9..791c2de 100644 --- a/src/Decho/Views/MessageItemView.axaml +++ b/src/Decho/Views/MessageItemView.axaml @@ -1,6 +1,7 @@ @@ -27,22 +28,29 @@ VerticalAlignment="Top" TextWrapping="Wrap" IsVisible="{Binding ShowContent}" /> - - - -