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"; private static readonly FrozenSet UserPolicyEventTypes = EventContent.GetMatchingEventTypes().ToFrozenSet(); private static readonly FrozenSet ServerPolicyEventTypes = EventContent.GetMatchingEventTypes().ToFrozenSet(); private static readonly FrozenSet RoomPolicyEventTypes = EventContent.GetMatchingEventTypes().ToFrozenSet(); private static readonly FrozenSet SpecPolicyEventTypes = [..UserPolicyEventTypes, ..ServerPolicyEventTypes, ..RoomPolicyEventTypes]; public async IAsyncEnumerable GetPoliciesAsync() { var fullRoomState = GetFullStateAsync(); await foreach (var eventResponse in fullRoomState) { if (SpecPolicyEventTypes.Contains(eventResponse!.Type)) { yield return eventResponse; } } } public async IAsyncEnumerable GetUserPoliciesAsync() { var fullRoomState = GetPoliciesAsync(); await foreach (var eventResponse in fullRoomState) { if (UserPolicyEventTypes.Contains(eventResponse!.Type)) { yield return eventResponse; } } } public async IAsyncEnumerable GetServerPoliciesAsync() { var fullRoomState = GetPoliciesAsync(); await foreach (var eventResponse in fullRoomState) { if (ServerPolicyEventTypes.Contains(eventResponse!.Type)) { yield return eventResponse; } } } public async IAsyncEnumerable GetRoomPoliciesAsync() { var fullRoomState = GetPoliciesAsync(); await foreach (var eventResponse in fullRoomState) { if (RoomPolicyEventTypes.Contains(eventResponse!.Type)) { yield return eventResponse; } } } }