about summary refs log tree commit diff
path: root/LibMatrix/RoomTypes/PolicyRoom.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix/RoomTypes/PolicyRoom.cs')
-rw-r--r--LibMatrix/RoomTypes/PolicyRoom.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/LibMatrix/RoomTypes/PolicyRoom.cs b/LibMatrix/RoomTypes/PolicyRoom.cs
new file mode 100644

index 0000000..c6eec63 --- /dev/null +++ b/LibMatrix/RoomTypes/PolicyRoom.cs
@@ -0,0 +1,51 @@ +using System.Collections.Frozen; +using LibMatrix.EventTypes; +using LibMatrix.EventTypes.Spec.State.Policy; +using LibMatrix.Homeservers; + +namespace LibMatrix.RoomTypes; + +public class PolicyRoom(AuthenticatedHomeserverGeneric homeserver, string roomId) : GenericRoom(homeserver, roomId) { + public const string TypeName = "support.feline.policy.lists.msc.v1"; + + public static readonly FrozenSet<string> UserPolicyEventTypes = EventContent.GetMatchingEventTypes<UserPolicyRuleEventContent>().ToFrozenSet(); + public static readonly FrozenSet<string> ServerPolicyEventTypes = EventContent.GetMatchingEventTypes<ServerPolicyRuleEventContent>().ToFrozenSet(); + public static readonly FrozenSet<string> RoomPolicyEventTypes = EventContent.GetMatchingEventTypes<RoomPolicyRuleEventContent>().ToFrozenSet(); + public static readonly FrozenSet<string> SpecPolicyEventTypes = [..UserPolicyEventTypes, ..ServerPolicyEventTypes, ..RoomPolicyEventTypes]; + + public async IAsyncEnumerable<StateEventResponse> GetPoliciesAsync() { + var fullRoomState = GetFullStateAsync(); + await foreach (var eventResponse in fullRoomState) { + if (SpecPolicyEventTypes.Contains(eventResponse!.Type)) { + yield return eventResponse; + } + } + } + + public async IAsyncEnumerable<StateEventResponse> GetUserPoliciesAsync() { + var fullRoomState = GetPoliciesAsync(); + await foreach (var eventResponse in fullRoomState) { + if (UserPolicyEventTypes.Contains(eventResponse!.Type)) { + yield return eventResponse; + } + } + } + + public async IAsyncEnumerable<StateEventResponse> GetServerPoliciesAsync() { + var fullRoomState = GetPoliciesAsync(); + await foreach (var eventResponse in fullRoomState) { + if (ServerPolicyEventTypes.Contains(eventResponse!.Type)) { + yield return eventResponse; + } + } + } + + public async IAsyncEnumerable<StateEventResponse> GetRoomPoliciesAsync() { + var fullRoomState = GetPoliciesAsync(); + await foreach (var eventResponse in fullRoomState) { + if (RoomPolicyEventTypes.Contains(eventResponse!.Type)) { + yield return eventResponse; + } + } + } +} \ No newline at end of file