1# Copyright 2014-2016 OpenMarket Ltd
2# Copyright 2017 Vector Creations Ltd
3# Copyright 2018-2019 New Vector Ltd
4# Copyright 2019 The Matrix.org Foundation C.I.C.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18"""Contains constants from the specification."""
19
20from typing_extensions import Final
21
22# the max size of a (canonical-json-encoded) event
23MAX_PDU_SIZE = 65536
24
25# the "depth" field on events is limited to 2**63 - 1
26MAX_DEPTH = 2 ** 63 - 1
27
28# the maximum length for a room alias is 255 characters
29MAX_ALIAS_LENGTH = 255
30
31# the maximum length for a user id is 255 characters
32MAX_USERID_LENGTH = 255
33
34# The maximum length for a group id is 255 characters
35MAX_GROUPID_LENGTH = 255
36MAX_GROUP_CATEGORYID_LENGTH = 255
37MAX_GROUP_ROLEID_LENGTH = 255
38
39
40class Membership:
41
42    """Represents the membership states of a user in a room."""
43
44    INVITE: Final = "invite"
45    JOIN: Final = "join"
46    KNOCK: Final = "knock"
47    LEAVE: Final = "leave"
48    BAN: Final = "ban"
49    LIST: Final = (INVITE, JOIN, KNOCK, LEAVE, BAN)
50
51
52class PresenceState:
53    """Represents the presence state of a user."""
54
55    OFFLINE: Final = "offline"
56    UNAVAILABLE: Final = "unavailable"
57    ONLINE: Final = "online"
58    BUSY: Final = "org.matrix.msc3026.busy"
59
60
61class JoinRules:
62    PUBLIC: Final = "public"
63    KNOCK: Final = "knock"
64    INVITE: Final = "invite"
65    PRIVATE: Final = "private"
66    # As defined for MSC3083.
67    RESTRICTED: Final = "restricted"
68
69
70class RestrictedJoinRuleTypes:
71    """Understood types for the allow rules in restricted join rules."""
72
73    ROOM_MEMBERSHIP: Final = "m.room_membership"
74
75
76class LoginType:
77    PASSWORD: Final = "m.login.password"
78    EMAIL_IDENTITY: Final = "m.login.email.identity"
79    MSISDN: Final = "m.login.msisdn"
80    RECAPTCHA: Final = "m.login.recaptcha"
81    TERMS: Final = "m.login.terms"
82    SSO: Final = "m.login.sso"
83    DUMMY: Final = "m.login.dummy"
84    REGISTRATION_TOKEN: Final = "org.matrix.msc3231.login.registration_token"
85
86
87# This is used in the `type` parameter for /register when called by
88# an appservice to register a new user.
89APP_SERVICE_REGISTRATION_TYPE: Final = "m.login.application_service"
90
91
92class EventTypes:
93    Member: Final = "m.room.member"
94    Create: Final = "m.room.create"
95    Tombstone: Final = "m.room.tombstone"
96    JoinRules: Final = "m.room.join_rules"
97    PowerLevels: Final = "m.room.power_levels"
98    Aliases: Final = "m.room.aliases"
99    Redaction: Final = "m.room.redaction"
100    ThirdPartyInvite: Final = "m.room.third_party_invite"
101    RelatedGroups: Final = "m.room.related_groups"
102
103    RoomHistoryVisibility: Final = "m.room.history_visibility"
104    CanonicalAlias: Final = "m.room.canonical_alias"
105    Encrypted: Final = "m.room.encrypted"
106    RoomAvatar: Final = "m.room.avatar"
107    RoomEncryption: Final = "m.room.encryption"
108    GuestAccess: Final = "m.room.guest_access"
109
110    # These are used for validation
111    Message: Final = "m.room.message"
112    Topic: Final = "m.room.topic"
113    Name: Final = "m.room.name"
114
115    ServerACL: Final = "m.room.server_acl"
116    Pinned: Final = "m.room.pinned_events"
117
118    Retention: Final = "m.room.retention"
119
120    Dummy: Final = "org.matrix.dummy_event"
121
122    SpaceChild: Final = "m.space.child"
123    SpaceParent: Final = "m.space.parent"
124
125    MSC2716_INSERTION: Final = "org.matrix.msc2716.insertion"
126    MSC2716_BATCH: Final = "org.matrix.msc2716.batch"
127    MSC2716_MARKER: Final = "org.matrix.msc2716.marker"
128
129
130class ToDeviceEventTypes:
131    RoomKeyRequest: Final = "m.room_key_request"
132
133
134class DeviceKeyAlgorithms:
135    """Spec'd algorithms for the generation of per-device keys"""
136
137    ED25519: Final = "ed25519"
138    CURVE25519: Final = "curve25519"
139    SIGNED_CURVE25519: Final = "signed_curve25519"
140
141
142class EduTypes:
143    Presence: Final = "m.presence"
144
145
146class RejectedReason:
147    AUTH_ERROR: Final = "auth_error"
148
149
150class RoomCreationPreset:
151    PRIVATE_CHAT: Final = "private_chat"
152    PUBLIC_CHAT: Final = "public_chat"
153    TRUSTED_PRIVATE_CHAT: Final = "trusted_private_chat"
154
155
156class ThirdPartyEntityKind:
157    USER: Final = "user"
158    LOCATION: Final = "location"
159
160
161ServerNoticeMsgType: Final = "m.server_notice"
162ServerNoticeLimitReached: Final = "m.server_notice.usage_limit_reached"
163
164
165class UserTypes:
166    """Allows for user type specific behaviour. With the benefit of hindsight
167    'admin' and 'guest' users should also be UserTypes. Normal users are type None
168    """
169
170    SUPPORT: Final = "support"
171    BOT: Final = "bot"
172    ALL_USER_TYPES: Final = (SUPPORT, BOT)
173
174
175class RelationTypes:
176    """The types of relations known to this server."""
177
178    ANNOTATION: Final = "m.annotation"
179    REPLACE: Final = "m.replace"
180    REFERENCE: Final = "m.reference"
181    THREAD: Final = "io.element.thread"
182
183
184class LimitBlockingTypes:
185    """Reasons that a server may be blocked"""
186
187    MONTHLY_ACTIVE_USER: Final = "monthly_active_user"
188    HS_DISABLED: Final = "hs_disabled"
189
190
191class EventContentFields:
192    """Fields found in events' content, regardless of type."""
193
194    # Labels for the event, cf https://github.com/matrix-org/matrix-doc/pull/2326
195    LABELS: Final = "org.matrix.labels"
196
197    # Timestamp to delete the event after
198    # cf https://github.com/matrix-org/matrix-doc/pull/2228
199    SELF_DESTRUCT_AFTER: Final = "org.matrix.self_destruct_after"
200
201    # cf https://github.com/matrix-org/matrix-doc/pull/1772
202    ROOM_TYPE: Final = "type"
203
204    # Whether a room can federate.
205    FEDERATE: Final = "m.federate"
206
207    # The creator of the room, as used in `m.room.create` events.
208    ROOM_CREATOR: Final = "creator"
209
210    # Used in m.room.guest_access events.
211    GUEST_ACCESS: Final = "guest_access"
212
213    # Used on normal messages to indicate they were historically imported after the fact
214    MSC2716_HISTORICAL: Final = "org.matrix.msc2716.historical"
215    # For "insertion" events to indicate what the next batch ID should be in
216    # order to connect to it
217    MSC2716_NEXT_BATCH_ID: Final = "org.matrix.msc2716.next_batch_id"
218    # Used on "batch" events to indicate which insertion event it connects to
219    MSC2716_BATCH_ID: Final = "org.matrix.msc2716.batch_id"
220    # For "marker" events
221    MSC2716_MARKER_INSERTION: Final = "org.matrix.msc2716.marker.insertion"
222
223    # The authorising user for joining a restricted room.
224    AUTHORISING_USER: Final = "join_authorised_via_users_server"
225
226
227class RoomTypes:
228    """Understood values of the room_type field of m.room.create events."""
229
230    SPACE: Final = "m.space"
231
232
233class RoomEncryptionAlgorithms:
234    MEGOLM_V1_AES_SHA2: Final = "m.megolm.v1.aes-sha2"
235    DEFAULT: Final = MEGOLM_V1_AES_SHA2
236
237
238class AccountDataTypes:
239    DIRECT: Final = "m.direct"
240    IGNORED_USER_LIST: Final = "m.ignored_user_list"
241
242
243class HistoryVisibility:
244    INVITED: Final = "invited"
245    JOINED: Final = "joined"
246    SHARED: Final = "shared"
247    WORLD_READABLE: Final = "world_readable"
248
249
250class GuestAccess:
251    CAN_JOIN: Final = "can_join"
252    # anything that is not "can_join" is considered "forbidden", but for completeness:
253    FORBIDDEN: Final = "forbidden"
254
255
256class ReceiptTypes:
257    READ: Final = "m.read"
258
259
260class ReadReceiptEventFields:
261    MSC2285_HIDDEN: Final = "org.matrix.msc2285.hidden"
262