constants.py 7.9 KB

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