about summary refs log tree commit diff
path: root/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs
blob: 349c8a70fe348faff9b5f6f9db2169da32787c7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Text.Json.Serialization;

namespace LibMatrix.EventTypes.Spec.State;

[MatrixEvent(EventName = EventId)]
public class RoomJoinRulesEventContent : EventContent {
    public const string EventId = "m.room.join_rules";

    /// <summary>
    /// one of ["public", "invite", "knock", "restricted", "knock_restricted"]
    /// "private" is reserved without implementation!
    /// unknown values are treated as "private"
    /// </summary>
    [JsonPropertyName("join_rule")]
    public string JoinRuleValue { get; set; }

    [JsonIgnore]
    public JoinRules JoinRule {
        get => JoinRuleValue switch {
            "public" => JoinRules.Public,
            "invite" => JoinRules.Invite,
            "knock" => JoinRules.Knock,
            "restricted" => JoinRules.Restricted,
            "knock_restricted" => JoinRules.KnockRestricted,
            _ => JoinRules.Private
        };
        set => JoinRuleValue = value switch {
            JoinRules.Public => "public",
            JoinRules.Invite => "invite",
            JoinRules.Knock => "knock",
            JoinRules.Restricted => "restricted",
            JoinRules.KnockRestricted => "knock_restricted",
            _ => "private"
        };
    }

    [JsonPropertyName("allow")]
    public List<AllowEntry>? Allow { get; set; }

    public class AllowEntry {
        [JsonPropertyName("type")]
        public required string Type { get; set; }

        [JsonPropertyName("room_id")]
        public required string RoomId { get; set; }

        public static class Types {
            public const string RoomMembership = "m.room_membership";
        }
    }

    public enum JoinRules {
        Public,
        Invite,
        Knock,
        Restricted,
        KnockRestricted,
        Private // reserved without implementation!
    }
}