about summary refs log tree commit diff
path: root/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs
blob: b557e4700e1edd5b6a65dbdde5b91f10b5affa90 (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
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 enum JoinRules {
        Public,
        Invite,
        Knock,
        Restricted,
        KnockRestricted,
        Private // reserved without implementation!
    }
}