diff options
Diffstat (limited to 'MatrixRoomUtils.Web/Classes')
-rw-r--r-- | MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs | 4 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Classes/RoomInfo.cs | 54 |
2 files changed, 53 insertions, 5 deletions
diff --git a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs b/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs index 8ea85e9..0947bbe 100644 --- a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs +++ b/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs @@ -1,6 +1,5 @@ using LibMatrix; using LibMatrix.Homeservers; -using LibMatrix.Responses; using LibMatrix.Services; using Microsoft.AspNetCore.Components; @@ -22,6 +21,9 @@ public class MRUStorageWrapper { } public async Task<List<UserAuth>?> GetAllTokens() { + if (!await _storageService.DataStorageProvider.ObjectExistsAsync("mru.tokens")) { + + } return await _storageService.DataStorageProvider.LoadObjectAsync<List<UserAuth>>("mru.tokens") ?? new List<UserAuth>(); } diff --git a/MatrixRoomUtils.Web/Classes/RoomInfo.cs b/MatrixRoomUtils.Web/Classes/RoomInfo.cs index 0e21871..31943dc 100644 --- a/MatrixRoomUtils.Web/Classes/RoomInfo.cs +++ b/MatrixRoomUtils.Web/Classes/RoomInfo.cs @@ -1,13 +1,15 @@ +using System.Collections.ObjectModel; +using ArcaneLibs; using LibMatrix; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Interfaces; -using LibMatrix.Responses; using LibMatrix.RoomTypes; namespace MatrixRoomUtils.Web.Classes; -public class RoomInfo { +public class RoomInfo : NotifyPropertyChanged { public GenericRoom Room { get; set; } - public List<StateEventResponse?> StateEvents { get; init; } = new(); + public ObservableCollection<StateEventResponse?> StateEvents { get; } = new(); public async Task<StateEventResponse?> GetStateEvent(string type, string stateKey = "") { var @event = StateEvents.FirstOrDefault(x => x.Type == type && x.StateKey == stateKey); @@ -28,4 +30,48 @@ public class RoomInfo { StateEvents.Add(@event); return @event; } -} + + public string? RoomIcon { + get => _roomIcon ?? "https://api.dicebear.com/6.x/identicon/svg?seed=" + Room.RoomId; + set => SetField(ref _roomIcon, value); + } + + public string? RoomName { + get => _roomName ?? Room.RoomId; + set => SetField(ref _roomName, value); + } + + public RoomCreateEventContent? CreationEventContent { + get => _creationEventContent; + set => SetField(ref _creationEventContent, value); + } + + public string? RoomCreator { + get => _roomCreator; + set => SetField(ref _roomCreator, value); + } + + // public string? GetRoomIcon() => (StateEvents.FirstOrDefault(x => x?.Type == RoomAvatarEventContent.EventId)?.TypedContent as RoomAvatarEventContent)?.Url ?? + // "mxc://rory.gay/dgP0YPjJEWaBwzhnbyLLwGGv"; + + private string? _roomIcon; + private string? _roomName; + private RoomCreateEventContent? _creationEventContent; + private string? _roomCreator; + + public RoomInfo() { + StateEvents.CollectionChanged += (_, args) => { + if (args.NewItems is { Count: > 0 }) + foreach (StateEventResponse newState in args.NewItems) { + if (newState.TypedContent is RoomNameEventContent roomNameContent) + RoomName = roomNameContent.Name; + else if (newState.TypedContent is RoomAvatarEventContent roomAvatarContent) + RoomIcon = roomAvatarContent.Url; + else if (newState.TypedContent is RoomCreateEventContent roomCreateContent) { + CreationEventContent = roomCreateContent; + RoomCreator = newState.Sender; + } + } + }; + } +} \ No newline at end of file |