constants.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. """Contains constants from the specification."""
  18. from typing_extensions import Final
  19. # the max size of a (canonical-json-encoded) event
  20. MAX_PDU_SIZE = 65536
  21. # the "depth" field on events is limited to 2**63 - 1
  22. MAX_DEPTH = 2**63 - 1
  23. # the maximum length for a room alias is 255 characters
  24. MAX_ALIAS_LENGTH = 255
  25. # the maximum length for a user id is 255 characters
  26. MAX_USERID_LENGTH = 255
  27. # Constant value used for the pseudo-thread which is the main timeline.
  28. MAIN_TIMELINE: Final = "main"
  29. class Membership:
  30. """Represents the membership states of a user in a room."""
  31. INVITE: Final = "invite"
  32. JOIN: Final = "join"
  33. KNOCK: Final = "knock"
  34. LEAVE: Final = "leave"
  35. BAN: Final = "ban"
  36. LIST: Final = (INVITE, JOIN, KNOCK, LEAVE, BAN)
  37. class PresenceState:
  38. """Represents the presence state of a user."""
  39. OFFLINE: Final = "offline"
  40. UNAVAILABLE: Final = "unavailable"
  41. ONLINE: Final = "online"
  42. BUSY: Final = "org.matrix.msc3026.busy"
  43. class JoinRules:
  44. PUBLIC: Final = "public"
  45. KNOCK: Final = "knock"
  46. INVITE: Final = "invite"
  47. PRIVATE: Final = "private"
  48. # As defined for MSC3083.
  49. RESTRICTED: Final = "restricted"
  50. # As defined for MSC3787.
  51. KNOCK_RESTRICTED: Final = "knock_restricted"
  52. class RestrictedJoinRuleTypes:
  53. """Understood types for the allow rules in restricted join rules."""
  54. ROOM_MEMBERSHIP: Final = "m.room_membership"
  55. class LoginType:
  56. PASSWORD: Final = "m.login.password"
  57. EMAIL_IDENTITY: Final = "m.login.email.identity"
  58. MSISDN: Final = "m.login.msisdn"
  59. RECAPTCHA: Final = "m.login.recaptcha"
  60. TERMS: Final = "m.login.terms"
  61. SSO: Final = "m.login.sso"
  62. DUMMY: Final = "m.login.dummy"
  63. REGISTRATION_TOKEN: Final = "m.login.registration_token"
  64. # This is used in the `type` parameter for /register when called by
  65. # an appservice to register a new user.
  66. APP_SERVICE_REGISTRATION_TYPE: Final = "m.login.application_service"
  67. class EventTypes:
  68. Member: Final = "m.room.member"
  69. Create: Final = "m.room.create"
  70. Tombstone: Final = "m.room.tombstone"
  71. JoinRules: Final = "m.room.join_rules"
  72. PowerLevels: Final = "m.room.power_levels"
  73. Aliases: Final = "m.room.aliases"
  74. Redaction: Final = "m.room.redaction"
  75. ThirdPartyInvite: Final = "m.room.third_party_invite"
  76. RoomHistoryVisibility: Final = "m.room.history_visibility"
  77. CanonicalAlias: Final = "m.room.canonical_alias"
  78. Encrypted: Final = "m.room.encrypted"
  79. RoomAvatar: Final = "m.room.avatar"
  80. RoomEncryption: Final = "m.room.encryption"
  81. GuestAccess: Final = "m.room.guest_access"
  82. # These are used for validation
  83. Message: Final = "m.room.message"
  84. Topic: Final = "m.room.topic"
  85. Name: Final = "m.room.name"
  86. ServerACL: Final = "m.room.server_acl"
  87. Pinned: Final = "m.room.pinned_events"
  88. Retention: Final = "m.room.retention"
  89. Dummy: Final = "org.matrix.dummy_event"
  90. SpaceChild: Final = "m.space.child"
  91. SpaceParent: Final = "m.space.parent"
  92. MSC2716_INSERTION: Final = "org.matrix.msc2716.insertion"
  93. MSC2716_BATCH: Final = "org.matrix.msc2716.batch"
  94. MSC2716_MARKER: Final = "org.matrix.msc2716.marker"
  95. Reaction: Final = "m.reaction"
  96. class ToDeviceEventTypes:
  97. RoomKeyRequest: Final = "m.room_key_request"
  98. class DeviceKeyAlgorithms:
  99. """Spec'd algorithms for the generation of per-device keys"""
  100. ED25519: Final = "ed25519"
  101. CURVE25519: Final = "curve25519"
  102. SIGNED_CURVE25519: Final = "signed_curve25519"
  103. class EduTypes:
  104. PRESENCE: Final = "m.presence"
  105. TYPING: Final = "m.typing"
  106. RECEIPT: Final = "m.receipt"
  107. DEVICE_LIST_UPDATE: Final = "m.device_list_update"
  108. SIGNING_KEY_UPDATE: Final = "m.signing_key_update"
  109. UNSTABLE_SIGNING_KEY_UPDATE: Final = "org.matrix.signing_key_update"
  110. DIRECT_TO_DEVICE: Final = "m.direct_to_device"
  111. class RejectedReason:
  112. AUTH_ERROR: Final = "auth_error"
  113. class RoomCreationPreset:
  114. PRIVATE_CHAT: Final = "private_chat"
  115. PUBLIC_CHAT: Final = "public_chat"
  116. TRUSTED_PRIVATE_CHAT: Final = "trusted_private_chat"
  117. class ThirdPartyEntityKind:
  118. USER: Final = "user"
  119. LOCATION: Final = "location"
  120. ServerNoticeMsgType: Final = "m.server_notice"
  121. ServerNoticeLimitReached: Final = "m.server_notice.usage_limit_reached"
  122. class UserTypes:
  123. """Allows for user type specific behaviour. With the benefit of hindsight
  124. 'admin' and 'guest' users should also be UserTypes. Normal users are type None
  125. """
  126. SUPPORT: Final = "support"
  127. BOT: Final = "bot"
  128. ALL_USER_TYPES: Final = (SUPPORT, BOT)
  129. class RelationTypes:
  130. """The types of relations known to this server."""
  131. ANNOTATION: Final = "m.annotation"
  132. REPLACE: Final = "m.replace"
  133. REFERENCE: Final = "m.reference"
  134. THREAD: Final = "m.thread"
  135. class LimitBlockingTypes:
  136. """Reasons that a server may be blocked"""
  137. MONTHLY_ACTIVE_USER: Final = "monthly_active_user"
  138. HS_DISABLED: Final = "hs_disabled"
  139. class EventContentFields:
  140. """Fields found in events' content, regardless of type."""
  141. # Labels for the event, cf https://github.com/matrix-org/matrix-doc/pull/2326
  142. LABELS: Final = "org.matrix.labels"
  143. # Timestamp to delete the event after
  144. # cf https://github.com/matrix-org/matrix-doc/pull/2228
  145. SELF_DESTRUCT_AFTER: Final = "org.matrix.self_destruct_after"
  146. # cf https://github.com/matrix-org/matrix-doc/pull/1772
  147. ROOM_TYPE: Final = "type"
  148. # Whether a room can federate.
  149. FEDERATE: Final = "m.federate"
  150. # The creator of the room, as used in `m.room.create` events.
  151. ROOM_CREATOR: Final = "creator"
  152. # Used in m.room.guest_access events.
  153. GUEST_ACCESS: Final = "guest_access"
  154. # Used on normal messages to indicate they were historically imported after the fact
  155. MSC2716_HISTORICAL: Final = "org.matrix.msc2716.historical"
  156. # For "insertion" events to indicate what the next batch ID should be in
  157. # order to connect to it
  158. MSC2716_NEXT_BATCH_ID: Final = "next_batch_id"
  159. # Used on "batch" events to indicate which insertion event it connects to
  160. MSC2716_BATCH_ID: Final = "batch_id"
  161. # For "marker" events
  162. MSC2716_INSERTION_EVENT_REFERENCE: Final = "insertion_event_reference"
  163. # The authorising user for joining a restricted room.
  164. AUTHORISING_USER: Final = "join_authorised_via_users_server"
  165. class RoomTypes:
  166. """Understood values of the room_type field of m.room.create events."""
  167. SPACE: Final = "m.space"
  168. class RoomEncryptionAlgorithms:
  169. MEGOLM_V1_AES_SHA2: Final = "m.megolm.v1.aes-sha2"
  170. DEFAULT: Final = MEGOLM_V1_AES_SHA2
  171. class AccountDataTypes:
  172. DIRECT: Final = "m.direct"
  173. IGNORED_USER_LIST: Final = "m.ignored_user_list"
  174. class HistoryVisibility:
  175. INVITED: Final = "invited"
  176. JOINED: Final = "joined"
  177. SHARED: Final = "shared"
  178. WORLD_READABLE: Final = "world_readable"
  179. class GuestAccess:
  180. CAN_JOIN: Final = "can_join"
  181. # anything that is not "can_join" is considered "forbidden", but for completeness:
  182. FORBIDDEN: Final = "forbidden"
  183. class ReceiptTypes:
  184. READ: Final = "m.read"
  185. READ_PRIVATE: Final = "m.read.private"
  186. FULLY_READ: Final = "m.fully_read"
  187. class PublicRoomsFilterFields:
  188. """Fields in the search filter for `/publicRooms` that we understand.
  189. As defined in https://spec.matrix.org/v1.3/client-server-api/#post_matrixclientv3publicrooms
  190. """
  191. GENERIC_SEARCH_TERM: Final = "generic_search_term"
  192. ROOM_TYPES: Final = "room_types"
  193. class ApprovalNoticeMedium:
  194. """Identifier for the medium this server will use to serve notice of approval for a
  195. specific user's registration.
  196. As defined in https://github.com/matrix-org/matrix-spec-proposals/blob/babolivier/m_not_approved/proposals/3866-user-not-approved-error.md
  197. """
  198. NONE = "org.matrix.msc3866.none"
  199. EMAIL = "org.matrix.msc3866.email"