diff --git a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml
new file mode 100644
index 0000000..e0812ec
--- /dev/null
+++ b/MatrixRoomUtils.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="MatrixRoomUtils.Desktop.NavigationStack">
+ <DockPanel x:Name="dock">
+ <StackPanel x:Name="navPanel"></StackPanel>
+ <UserControl x:Name="content"></UserControl>
+ </DockPanel>
+
+</UserControl>
diff --git a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs
new file mode 100644
index 0000000..f4e0fed
--- /dev/null
+++ b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs
@@ -0,0 +1,57 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace MatrixRoomUtils.Desktop;
+
+public partial class NavigationStack : UserControl {
+ public NavigationStack() {
+ InitializeComponent();
+ }
+
+ private void InitializeComponent() {
+ AvaloniaXamlLoader.Load(this);
+ buildView();
+ }
+
+ private void buildView() {
+ navPanel.Children.Clear();
+ foreach (var item in _stack) {
+ Button btn = new() {
+ Content = item.Name
+ };
+ btn.Click += (sender, args) => {
+ PopTo(_stack.IndexOf(item));
+ buildView();
+ };
+ navPanel.Children.Add(btn);
+ }
+ 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
+ });
+ }
+
+ public void Pop() {
+ _stack.RemoveAt(_stack.Count - 1);
+ }
+
+ public void PopTo(int index) {
+ _stack.RemoveRange(index, _stack.Count - index);
+ }
+}
diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml
new file mode 100644
index 0000000..c80ef2f
--- /dev/null
+++ b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml
@@ -0,0 +1,11 @@
+<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="250" d:DesignHeight="32"
+ x:Class="MatrixRoomUtils.Desktop.RoomListEntry">
+ <StackPanel Orientation="Horizontal">
+ <Image MaxWidth="64" x:Name="RoomIcon"></Image>
+ <Label x:Name="RoomName"></Label>
+ </StackPanel>
+</UserControl>
diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs
new file mode 100644
index 0000000..a447701
--- /dev/null
+++ b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs
@@ -0,0 +1,69 @@
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Media.Imaging;
+using MatrixRoomUtils.Core;
+using MatrixRoomUtils.Core.Helpers;
+using MatrixRoomUtils.Core.Services;
+using MatrixRoomUtils.Core.StateEventTypes.Spec;
+using MatrixRoomUtils.Web.Classes;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace MatrixRoomUtils.Desktop;
+
+public partial class RoomListEntry : UserControl {
+ private readonly IServiceScopeFactory _serviceScopeFactory;
+ private readonly RoomInfo _roomInfo;
+
+ public RoomListEntry(IServiceScopeFactory serviceScopeFactory, RoomInfo roomInfo) {
+ _serviceScopeFactory = serviceScopeFactory;
+ _roomInfo = roomInfo;
+ InitializeComponent();
+ }
+
+ protected override void OnLoaded(RoutedEventArgs e) {
+ base.OnLoaded(e);
+ RoomName.Content = _roomInfo.Room.RoomId;
+ Task.WhenAll(GetRoomName(), GetRoomIcon());
+ }
+
+ private async Task GetRoomName() {
+ try {
+ var nameEvent = await _roomInfo.GetStateEvent("m.room.name");
+ if (nameEvent is not null && nameEvent.TypedContent is RoomNameEventData nameData)
+ RoomName.Content = nameData.Name;
+ }
+ catch (MatrixException e) {
+ if (e.ErrorCode != "M_NOT_FOUND")
+ throw;
+ }
+ }
+
+ private async Task GetRoomIcon() {
+ try {
+ var avatarEvent = await _roomInfo.GetStateEvent("m.room.avatar");
+ if (avatarEvent is not null && avatarEvent.TypedContent is RoomAvatarEventData avatarData) {
+ var mxcUrl = avatarData.Url;
+ await using var svc = _serviceScopeFactory.CreateAsyncScope();
+ var hs = await svc.ServiceProvider.GetService<MRUStorageWrapper>().GetCurrentSessionOrPrompt();
+ var storage = svc.ServiceProvider.GetService<TieredStorageService>().CacheStorageProvider;
+ var resolvedUrl = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, mxcUrl);
+ var storageKey = $"media/{mxcUrl.Replace("mxc://", "").Replace("/", ".")}";
+ try {
+ if (!await storage.ObjectExistsAsync(storageKey))
+ await storage.SaveStreamAsync(storageKey, await hs._httpClient.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;
+ }
+ }
+}
|