@page "/RoomManagerCreateRoom" @using System.Text.Json @using MatrixRoomUtils.Core.Extensions @using MatrixRoomUtils.Core.Responses @using System.Runtime.Intrinsics.X86

Room Manager - Create Room

@*
@JsonString
*@
Preset: @foreach (var createRoomRequest in Presets) { } @* *@ @* *@ @* *@
Room name:
Room alias (localpart):
Room type:
History visibility:
Guest access:
Room icon: @* *@
Initial states:
@code{ private static readonly string[] ImplementedStates = { "m.room.avatar", "m.room.history_visibility", "m.room.guest_access", }; } @creationEvent.InitialState.Count(x => !ImplementedStates.Contains(x.Type)) custom states @foreach (var initialState in creationEvent.InitialState.Where(x => !ImplementedStates.Contains(x.Type))) { }
@(initialState.Type):
@JsonSerializer.Serialize(initialState.Content, new JsonSerializerOptions { WriteIndented = true })
@creationEvent.InitialState.Count initial states @foreach (var initialState in creationEvent.InitialState.Where(x => !new[] { "m.room.avatar", "m.room.history_visibility" }.Contains(x.Type))) { }
@(initialState.Type):
@JsonSerializer.Serialize(initialState.Content, new JsonSerializerOptions { WriteIndented = true })

Creation JSON
        @creationEvent.ToJson(ignoreNull: true)
    
Creation JSON (with null values)
@code { private string JsonString { get => creationEvent.ToJson(); set { creationEvent = JsonSerializer.Deserialize(value); JsonChanged(); } } private string RoomPreset { get { if (Presets.ContainsValue(creationEvent)) { return Presets.First(x => x.Value == creationEvent).Key; } return "Not a preset"; } set { creationEvent = Presets[value]; JsonChanged(); } } private Dictionary creationEventValidationErrors { get; set; } = new(); private CreateRoomRequest creationEvent { get; set; } private Dictionary Presets { get; set; } = new(); protected override async Task OnInitializedAsync() { await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); creationEvent = Presets["Default room"] = new CreateRoomRequest { Name = "My new room", RoomAliasName = "myroom", InitialState = new() { new() { Type = "m.room.history_visibility", Content = new { history_visibility = "world_readable" } }, new() { Type = "m.room.guest_access", Content = new { guest_access = "can_join" } }, new() { Type = "m.room.join_rules", Content = new { join_rule = "public" } }, new() { Type = "m.room.server_acl", Content = new { allow = new[] { "*" }, deny = new[] { "midov.pl", "qoto.org", "matrix.kiwifarms.net", "plan9.rocks", "thisisjoes.site", "konqi.work", "austinhuang.lol", "arcticfox.ems.host", "*.thisisjoes.site", "*.abuser.eu", "*.austinhuang.lol" }, allow_ip_literals = false } }, new() { Type = "m.room.avatar", Content = new { url = "mxc://feline.support/UKNhEyrVsrAbYteVvZloZcFj" } } }, Visibility = "public", PowerLevelContentOverride = new() { UsersDefault = 0, EventsDefault = 100, StateDefault = 50, Invite = 0, Redact = 50, Kick = 50, Ban = 50, NotificationsPl = new() { Room = 50 }, Events = new() { { "im.vector.modular.widgets", 50 }, { "io.element.voice_broadcast_info", 50 }, { "m.reaction", 100 }, { "m.room.avatar", 50 }, { "m.room.canonical_alias", 50 }, { "m.room.encryption", 100 }, { "m.room.history_visibility", 100 }, { "m.room.name", 50 }, { "m.room.pinned_events", 50 }, { "m.room.power_levels", 100 }, { "m.room.redaction", 100 }, { "m.room.server_acl", 100 }, { "m.room.tombstone", 100 }, { "m.room.topic", 50 }, { "m.space.child", 50 }, { "org.matrix.msc3401.call", 50 }, { "org.matrix.msc3401.call.member", 50 } }, Users = new() { { "@alicia:rory.gay", 100 }, { "@emma:rory.gay", 100 }, { "@root:rory.gay", 100 }, { "@rory:rory.gay", 100 } }, }, CreationContent = new() { { "type", null } } }; await base.OnInitializedAsync(); } private void JsonChanged() { Console.WriteLine(JsonString); } private string GetStateFriendlyName(string key) => key switch { "m.room.history_visibility" => "History visibility", "m.room.guest_access" => "Guest access", "m.room.join_rules" => "Join rules", "m.room.server_acl" => "Server ACL", "m.room.avatar" => "Avatar", _ => key }; }