diff options
author | Emma@Rory& <root@rory.gay> | 2023-07-26 21:02:50 +0200 |
---|---|---|
committer | Emma@Rory& <root@rory.gay> | 2023-07-26 21:02:50 +0200 |
commit | 2e89a0717a60598904c92499adb7e01b2075fbb9 (patch) | |
tree | 56b9b7f07180154d9d98dafa91d7c16a0a872100 /MatrixRoomUtils.Desktop/RoomInfo.cs | |
parent | Start of nix flake (diff) | |
download | MatrixUtils-2e89a0717a60598904c92499adb7e01b2075fbb9.tar.xz |
MRU desktop start
Diffstat (limited to 'MatrixRoomUtils.Desktop/RoomInfo.cs')
-rw-r--r-- | MatrixRoomUtils.Desktop/RoomInfo.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Desktop/RoomInfo.cs b/MatrixRoomUtils.Desktop/RoomInfo.cs new file mode 100644 index 0000000..a31d67a --- /dev/null +++ b/MatrixRoomUtils.Desktop/RoomInfo.cs @@ -0,0 +1,37 @@ +using MatrixRoomUtils.Core; +using MatrixRoomUtils.Core.Interfaces; +using MatrixRoomUtils.Core.Responses; +using MatrixRoomUtils.Core.RoomTypes; + +namespace MatrixRoomUtils.Web.Classes; + +public class RoomInfo { + public RoomInfo() { } + + public RoomInfo(GenericRoom room) { + Room = room; + } + + public GenericRoom Room { get; set; } + public List<StateEventResponse?> StateEvents { get; init; } = new(); + + public async Task<StateEventResponse?> GetStateEvent(string type, string stateKey = "") { + var @event = StateEvents.FirstOrDefault(x => x.Type == type && x.StateKey == stateKey); + if (@event is not null) return @event; + @event = new StateEventResponse() { + RoomId = Room.RoomId, + Type = type, + StateKey = stateKey, + }; + try { + @event.TypedContent = await Room.GetStateAsync<object>(type, stateKey); + } + catch (MatrixException e) { + if (e is { ErrorCode: "M_NOT_FOUND" }) @event.TypedContent = default!; + else throw; + } + + StateEvents.Add(@event); + return @event; + } +} |