about summary refs log tree commit diff
path: root/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs
blob: e300b5dc9cda5d19aa95c8c54a802baab2b7a5b3 (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
using System.Text.Json.Serialization;

namespace LibMatrix.EventTypes.Spec.State;

[MatrixEvent(EventName = "m.room.join_rules")]
public class RoomJoinRulesEventContent : TimelineEventContent {
    /// <summary>
    /// one of ["public", "invite", "knock", "restricted", "knock_restricted"]
    /// "private" is reserved without implementation!
    /// </summary>
    [JsonPropertyName("join_rule")]
    public string JoinRuleValue { get; set; }
    
    [JsonIgnore]
    public required JoinRules JoinRule {
        get => JoinRuleValue switch {
            "public" => JoinRules.Public,
            "invite" => JoinRules.Invite,
            "knock" => JoinRules.Knock,
            "restricted" => JoinRules.Restricted,
            "knock_restricted" => JoinRules.KnockRestricted,
            _ => throw new ArgumentOutOfRangeException()
        };
        set => JoinRuleValue = value switch {
            JoinRules.Public => "public",
            JoinRules.Invite => "invite",
            JoinRules.Knock => "knock",
            JoinRules.Restricted => "restricted",
            JoinRules.KnockRestricted => "knock_restricted",
            _ => throw new ArgumentOutOfRangeException(nameof(value), value, null)
        };
    }

    [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
    }
}