diff --git a/MatrixUtils.Desktop/Components/NavigationStack.axaml b/MatrixUtils.Desktop/Components/NavigationStack.axaml
new file mode 100644
index 0000000..b24895d
--- /dev/null
+++ b/MatrixUtils.Desktop/Components/NavigationStack.axaml
@@ -0,0 +1,12 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+ x:Class="MatrixUtils.Desktop.Components.NavigationStack">
+ <StackPanel x:Name="dock">
+ <Label>NagivationStack</Label>
+ <StackPanel x:Name="navPanel" Orientation="Horizontal"></StackPanel>
+ <ContentControl x:Name="content"></ContentControl>
+ </StackPanel>
+</UserControl>
\ No newline at end of file
diff --git a/MatrixUtils.Desktop/Components/NavigationStack.axaml.cs b/MatrixUtils.Desktop/Components/NavigationStack.axaml.cs
new file mode 100644
index 0000000..632ae3c
--- /dev/null
+++ b/MatrixUtils.Desktop/Components/NavigationStack.axaml.cs
@@ -0,0 +1,72 @@
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Markup.Xaml;
+
+namespace MatrixUtils.Desktop.Components;
+
+public partial class NavigationStack : UserControl {
+ public NavigationStack() {
+ InitializeComponent();
+ }
+
+ // private void InitializeComponent() {
+ // AvaloniaXamlLoader.Load(this);
+ // buildView();
+ // }
+
+ protected override void OnLoaded(RoutedEventArgs e) {
+ base.OnLoaded(e);
+ buildView();
+ }
+
+ private void buildView() {
+ if (navPanel is null) {
+ Console.WriteLine("NavigationStack buildView called while navpanel is null!");
+ // await Task.Delay(100);
+ // if (navPanel is null)
+ // await buildView();
+ // else Console.WriteLine("navpanel is not null!");
+ }
+ navPanel.Children.Clear();
+ foreach (var item in _stack) {
+ Button btn = new() {
+ Content = item.Name
+ };
+ btn.Click += (_, _) => {
+ PopTo(_stack.IndexOf(item));
+ buildView();
+ };
+ navPanel.Children.Add(btn);
+ }
+ content.Content = Current?.View ?? new UserControl();
+ }
+
+
+ public class NavigationStackItem {
+ public string Name { get; set; }
+ public string Description { get; set; } = "";
+ public UserControl View { get; set; }
+ }
+
+ private List<NavigationStackItem> _stack = new();
+
+ public NavigationStackItem? Current => _stack.LastOrDefault();
+
+ public void Push(string name, UserControl view) {
+ _stack.Add(new NavigationStackItem {
+ Name = name,
+ View = view
+ });
+ buildView();
+ }
+
+ public void Pop() {
+ _stack.RemoveAt(_stack.Count - 1);
+ buildView();
+ }
+
+ public void PopTo(int index) {
+ _stack.RemoveRange(index, _stack.Count - index);
+ buildView();
+ }
+}
diff --git a/MatrixUtils.Desktop/Components/Pages/RoomList.axaml b/MatrixUtils.Desktop/Components/Pages/RoomList.axaml
new file mode 100644
index 0000000..45778f3
--- /dev/null
+++ b/MatrixUtils.Desktop/Components/Pages/RoomList.axaml
@@ -0,0 +1,21 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:components="clr-namespace:MatrixUtils.Desktop.Components.Pages"
+ xmlns:components1="clr-namespace:MatrixUtils.Desktop.Components"
+ xmlns:abstractions="clr-namespace:MatrixUtils.Abstractions;assembly=MatrixUtils.Abstractions"
+
+ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+ x:Class="MatrixUtils.Desktop.Components.Pages.RoomList"
+ x:DataType="components:RoomList"
+ DataContext="{Binding $self}"
+ >
+ <ListBox ItemsSource="{Binding Rooms}">
+ <ListBox.ItemTemplate>
+ <DataTemplate DataType="abstractions:RoomInfo">
+ <components1:RoomListEntry Room="{Binding Path=.}"/>
+ </DataTemplate>
+ </ListBox.ItemTemplate>
+ </ListBox>
+</UserControl>
diff --git a/MatrixUtils.Desktop/Components/Pages/RoomList.axaml.cs b/MatrixUtils.Desktop/Components/Pages/RoomList.axaml.cs
new file mode 100644
index 0000000..a0c9fcc
--- /dev/null
+++ b/MatrixUtils.Desktop/Components/Pages/RoomList.axaml.cs
@@ -0,0 +1,15 @@
+using System.Collections.ObjectModel;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using MatrixUtils.Abstractions;
+
+namespace MatrixUtils.Desktop.Components.Pages;
+
+public partial class RoomList : UserControl {
+ private ObservableCollection<RoomInfo> Rooms { get; set; } = new();
+
+ public RoomList() {
+ InitializeComponent();
+ }
+}
\ No newline at end of file
diff --git a/MatrixUtils.Desktop/Components/RoomListEntry.axaml b/MatrixUtils.Desktop/Components/RoomListEntry.axaml
new file mode 100644
index 0000000..97e6fdc
--- /dev/null
+++ b/MatrixUtils.Desktop/Components/RoomListEntry.axaml
@@ -0,0 +1,16 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:components="clr-namespace:MatrixUtils.Desktop.Components"
+ mc:Ignorable="d" d:DesignWidth="250" d:DesignHeight="32"
+ x:Class="MatrixUtils.Desktop.Components.RoomListEntry"
+
+ x:DataType="components:RoomListEntry"
+ DataContext="{Binding $self}"
+ >
+ <StackPanel Orientation="Horizontal">
+ <Image MaxWidth="64" x:Name="RoomIcon"></Image>
+ <Label x:Name="RoomName" Content="{Binding Room.RoomName}"></Label>
+ </StackPanel>
+</UserControl>
diff --git a/MatrixUtils.Desktop/Components/RoomListEntry.axaml.cs b/MatrixUtils.Desktop/Components/RoomListEntry.axaml.cs
new file mode 100644
index 0000000..1e4a127
--- /dev/null
+++ b/MatrixUtils.Desktop/Components/RoomListEntry.axaml.cs
@@ -0,0 +1,74 @@
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Media.Imaging;
+using LibMatrix;
+using LibMatrix.EventTypes.Spec.State;
+using LibMatrix.EventTypes.Spec.State.RoomInfo;
+using LibMatrix.Helpers;
+using LibMatrix.Interfaces.Services;
+using LibMatrix.Services;
+using MatrixUtils.Abstractions;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+
+namespace MatrixUtils.Desktop.Components;
+
+public partial class RoomListEntry : UserControl {
+ public RoomInfo Room { get; set; }
+
+ public RoomListEntry() {
+ InitializeComponent();
+ }
+
+ protected override void OnLoaded(RoutedEventArgs e) {
+ base.OnLoaded(e);
+ RoomName.Content = Room.Room.RoomId;
+ Task.WhenAll(GetRoomName(), GetRoomIcon());
+ }
+
+ private async Task GetRoomName() {
+ try {
+ var nameEvent = await Room.GetStateEvent("m.room.name");
+ if (nameEvent?.TypedContent is RoomNameEventContent nameData)
+ RoomName.Content = nameData.Name;
+ }
+ catch (MatrixException e) {
+ if (e.ErrorCode != "M_NOT_FOUND")
+ throw;
+ }
+ }
+
+ private async Task GetRoomIcon() {
+ try {
+ using var hc = new HttpClient();
+ var avatarEvent = await Room.GetStateEvent("m.room.avatar");
+ if (avatarEvent?.TypedContent is RoomAvatarEventContent avatarData) {
+ var mxcUrl = avatarData.Url;
+ var resolvedUrl = await Room.Room.GetResolvedRoomAvatarUrlAsync();
+
+ // await using var svc = _serviceScopeFactory.CreateAsyncScope();
+ // var hs = await svc.ServiceProvider.GetService<RMUStorageWrapper>()?.GetCurrentSessionOrPrompt()!;
+ // var hsResolver = svc.ServiceProvider.GetService<HomeserverResolverService>();
+ // var storage = svc.ServiceProvider.GetService<TieredStorageService>()?.CacheStorageProvider;
+ // var resolvedUrl = await hsResolver.ResolveMediaUri(hs.ServerName, mxcUrl);
+ var storage = new FileStorageProvider("cache");
+ var storageKey = $"media/{mxcUrl.Replace("mxc://", "").Replace("/", ".")}";
+ try {
+ if (!await storage.ObjectExistsAsync(storageKey))
+ await storage.SaveStreamAsync(storageKey, await hc.GetStreamAsync(resolvedUrl));
+
+ RoomIcon.Source = new Bitmap(await storage.LoadStreamAsync(storageKey) ?? throw new NullReferenceException());
+ }
+ catch (IOException) { }
+ catch (MatrixException e) {
+ if (e.ErrorCode != "M_UNKNOWN")
+ throw;
+ }
+ }
+ }
+ catch (MatrixException e) {
+ if (e.ErrorCode != "M_NOT_FOUND")
+ throw;
+ }
+ }
+}
|