You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

303 lines
8.8 KiB

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