Improve multiline message handling, timestamp formatting, and UI layout

This commit is contained in:
Stone_Red
2026-02-27 01:39:49 +01:00
parent c783e9fb9c
commit 63c4e9b640
6 changed files with 68 additions and 38 deletions
+13 -6
View File
@@ -61,7 +61,7 @@ public sealed class MainWindowViewModel : ViewModelBase
{
new("message-1", alex, DateTimeOffset.Now.AddMinutes(-30), "This is a message."),
new("message-2", sam, DateTimeOffset.Now.AddMinutes(-25), "Another message for the channel."),
new("message-3", alex, DateTimeOffset.Now.AddMinutes(-10), "We should test the new layout."),
new("message-3", alex, DateTimeOffset.Now.AddMinutes(-10), "We should test the \nnew layout."),
});
var random = new ChannelModel(
@@ -69,7 +69,14 @@ public sealed class MainWindowViewModel : ViewModelBase
"random",
new ObservableCollection<MessageModel>
{
new("message-4", sam, DateTimeOffset.Now.AddMinutes(-5), "Random chat keeps the vibe light."),
new("message-4", sam, DateTimeOffset.Now.AddMinutes(-5), @"Random chat keeps the vibe light.
rwerwerw
rw
er
wer
w
r
ztr5z56j7u5"),
});
var music = new ChannelModel(
@@ -78,13 +85,13 @@ public sealed class MainWindowViewModel : ViewModelBase
new ObservableCollection<MessageModel>());
var server = new ServerModel(
"server-1",
"Server",
"echo.voidcube.cloud",
"echo.voidcube.cloud",
new ObservableCollection<ChannelModel> { general, random });
var anotherServer = new ServerModel(
"server-2",
"Another Server",
"echo.stone-red.net",
"echo.stone-red.net",
new ObservableCollection<ChannelModel>() { general, music});
return new[] { server, anotherServer };
+17 -1
View File
@@ -1,5 +1,7 @@
using Decho.Models;
using System;
namespace Decho.ViewModels;
public sealed class MessageViewModel : ViewModelBase
@@ -15,5 +17,19 @@ public sealed class MessageViewModel : ViewModelBase
public string Content => Model.Content;
public string TimeText => Model.SentAt.ToLocalTime().ToString("h:mm tt");
public string TimeText
{
get
{
// If today, show time only; otherwise, show date and time.
var now = DateTimeOffset.Now;
if (Model.SentAt.Date == now.Date)
{
return Model.SentAt.ToLocalTime().ToString("t");
}
return now.ToString("g");
}
}
}
+3 -3
View File
@@ -17,16 +17,16 @@
</Design.DataContext>
<Grid RowDefinitions="Auto, *" ColumnDefinitions="Auto, *">
<TextBlock Grid.ColumnSpan="2"
FontSize="20"
<TextBlock FontSize="20"
FontWeight="Bold"
Margin="0 5"
HorizontalAlignment="Center"
Text="{Binding Title}" />
<views:SidebarView Grid.Row="1"
Grid.Column="0"
DataContext="{Binding Sidebar}"
SelectedChannel="{Binding SelectedChannel, Mode=TwoWay}" />
<views:ChatView Grid.Row="1"
<views:ChatView Grid.RowSpan="2"
Grid.Column="1"
DataContext="{Binding Chat}" />
</Grid>
+5 -1
View File
@@ -7,7 +7,11 @@
<Grid ColumnDefinitions="*, Auto, Auto" Margin="5">
<TextBox HorizontalAlignment="Stretch"
Margin="0 0 5 0"
Text="{Binding Draft, Mode=TwoWay}" />
Text="{Binding Draft, Mode=TwoWay}">
<TextBox.KeyBindings>
<KeyBinding Command="{Binding SendCommand}" Gesture="Enter" />
</TextBox.KeyBindings>
</TextBox>
<Button Grid.Column="1"
Height="33"
Width="33"
+27 -25
View File
@@ -1,27 +1,29 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:Decho.ViewModels"
x:Class="Decho.Views.MessageItemView"
x:DataType="vm:MessageViewModel">
<Grid Margin="5" ColumnDefinitions="Auto, Auto, *" RowDefinitions="Auto, Auto">
<Ellipse Grid.RowSpan="2"
Width="40"
Height="40"
Fill="{DynamicResource UiTheme00}"
Margin="0 0 5 0" />
<TextBlock Grid.Column="1"
VerticalAlignment="Bottom"
Text="{Binding AuthorName}"
FontWeight="Bold" />
<TextBlock Grid.Column="1"
Grid.Row="1"
Text="{Binding TimeText}"
FontSize="10" />
<TextBlock Grid.Column="2"
Grid.RowSpan="1"
VerticalAlignment="Center"
Text="{Binding Content}"
TextWrapping="Wrap"
Margin="10 5 0 0" />
</Grid>
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:Decho.ViewModels"
x:Class="Decho.Views.MessageItemView"
x:DataType="vm:MessageViewModel">
<Grid Margin="5" ColumnDefinitions="Auto, Auto, *">
<Ellipse Grid.RowSpan="2"
VerticalAlignment="Top"
Width="40"
Height="40"
Fill="{DynamicResource UiTheme00}"
Margin="0 0 8 0" />
<StackPanel Grid.Column="1" VerticalAlignment="Top">
<StackPanel Orientation="Horizontal" Margin="0 5 0 0">
<TextBlock VerticalAlignment="Top"
Text="{Binding AuthorName}"
FontWeight="Bold" />
<TextBlock VerticalAlignment="Top"
Text="{Binding TimeText}"
FontSize="10"
Margin="5 0 0 0" />
</StackPanel>
<TextBlock VerticalAlignment="Top"
Text="{Binding Content}"
TextWrapping="Wrap" />
</StackPanel>
</Grid>
</UserControl>
+3 -2
View File
@@ -4,12 +4,13 @@
xmlns:views="using:Decho.Views"
x:Class="Decho.Views.SidebarView"
x:DataType="vm:SidebarViewModel">
<Panel Background="{DynamicResource UiTheme00}" Width="250">
<Border Background="{DynamicResource UiTheme00}" Width="250" CornerRadius="0 6 0 0">
<ScrollViewer Padding="5">
<ItemsControl ItemsSource="{Binding Servers}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:ServerViewModel">
<Expander Padding="0"
Margin="0 0 0 6"
HorizontalAlignment="Stretch"
IsExpanded="{Binding IsExpanded}">
<Expander.Header>
@@ -25,5 +26,5 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Panel>
</Border>
</UserControl>