From 03313562d21d5db9bf6a14ebbeab80e06c883d3a Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 24 Jan 2024 02:31:56 +0100 Subject: MRU->RMU, fixes, cleanup --- .../Components/NavigationStack.axaml | 12 ---- .../Components/NavigationStack.axaml.cs | 72 --------------------- .../Components/Pages/RoomList.axaml | 21 ------ .../Components/Pages/RoomList.axaml.cs | 15 ----- .../Components/RoomListEntry.axaml | 16 ----- .../Components/RoomListEntry.axaml.cs | 74 ---------------------- 6 files changed, 210 deletions(-) delete mode 100644 MatrixRoomUtils.Desktop/Components/NavigationStack.axaml delete mode 100644 MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs delete mode 100644 MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml delete mode 100644 MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml.cs delete mode 100644 MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml delete mode 100644 MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs (limited to 'MatrixRoomUtils.Desktop/Components') diff --git a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml deleted file mode 100644 index bc6b75d..0000000 --- a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs deleted file mode 100644 index 92c617b..0000000 --- a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs +++ /dev/null @@ -1,72 +0,0 @@ -using Avalonia.Controls; -using Avalonia.Interactivity; -using Avalonia.Markup.Xaml; - -namespace MatrixRoomUtils.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 _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/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml b/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml deleted file mode 100644 index 0e43d99..0000000 --- a/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - diff --git a/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml.cs b/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml.cs deleted file mode 100644 index 53c3063..0000000 --- a/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.ObjectModel; -using Avalonia; -using Avalonia.Controls; -using Avalonia.Markup.Xaml; -using MatrixRoomUtils.Abstractions; - -namespace MatrixRoomUtils.Desktop.Components.Pages; - -public partial class RoomList : UserControl { - private ObservableCollection Rooms { get; set; } = new(); - - public RoomList() { - InitializeComponent(); - } -} \ No newline at end of file diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml deleted file mode 100644 index db22ccc..0000000 --- a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs deleted file mode 100644 index 73115a2..0000000 --- a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs +++ /dev/null @@ -1,74 +0,0 @@ -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 MatrixRoomUtils.Abstractions; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace MatrixRoomUtils.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()?.GetCurrentSessionOrPrompt()!; - // var hsResolver = svc.ServiceProvider.GetService(); - // var storage = svc.ServiceProvider.GetService()?.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; - } - } -} -- cgit 1.5.1