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.
 
 
 
 
 
 

291 lines
8.1 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 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. Reaction: Final = "m.reaction"
  94. class ToDeviceEventTypes:
  95. RoomKeyRequest: Final = "m.room_key_request"
  96. class DeviceKeyAlgorithms:
  97. """Spec'd algorithms for the generation of per-device keys"""
  98. ED25519: Final = "ed25519"
  99. CURVE25519: Final = "curve25519"
  100. SIGNED_CURVE25519: Final = "signed_curve25519"
  101. class EduTypes:
  102. PRESENCE: Final = "m.presence"
  103. TYPING: Final = "m.typing"
  104. RECEIPT: Final = "m.receipt"
  105. DEVICE_LIST_UPDATE: Final = "m.device_list_update"
  106. SIGNING_KEY_UPDATE: Final = "m.signing_key_update"
  107. UNSTABLE_SIGNING_KEY_UPDATE: Final = "org.matrix.signing_key_update"
  108. DIRECT_TO_DEVICE: Final = "m.direct_to_device"
  109. class RejectedReason:
  110. AUTH_ERROR: Final = "auth_error"
  111. OVERSIZED_EVENT: Final = "oversized_event"
  112. class RoomCreationPreset:
  113. PRIVATE_CHAT: Final = "private_chat"
  114. PUBLIC_CHAT: Final = "public_chat"
  115. TRUSTED_PRIVATE_CHAT: Final = "trusted_private_chat"
  116. class ThirdPartyEntityKind:
  117. USER: Final = "user"
  118. LOCATION: Final = "location"
  119. ServerNoticeMsgType: Final = "m.server_notice"
  120. ServerNoticeLimitReached: Final = "m.server_notice.usage_limit_reached"
  121. class UserTypes:
  122. """Allows for user type specific behaviour. With the benefit of hindsight
  123. 'admin' and 'guest' users should also be UserTypes. Normal users are type None
  124. """
  125. SUPPORT: Final = "support"
  126. BOT: Final = "bot"
  127. ALL_USER_TYPES: Final = (SUPPORT, BOT)
  128. class RelationTypes:
  129. """The types of relations known to this server."""
  130. ANNOTATION: Final = "m.annotation"
  131. REPLACE: Final = "m.replace"
  132. REFERENCE: Final = "m.reference"
  133. THREAD: Final = "m.thread"
  134. class LimitBlockingTypes:
  135. """Reasons that a server may be blocked"""
  136. MONTHLY_ACTIVE_USER: Final = "monthly_active_user"
  137. HS_DISABLED: Final = "hs_disabled"
  138. class EventContentFields:
  139. """Fields found in events' content, regardless of type."""
  140. # Labels for the event, cf https://github.com/matrix-org/matrix-doc/pull/2326
  141. LABELS: Final = "org.matrix.labels"
  142. # Timestamp to delete the event after
  143. # cf https://github.com/matrix-org/matrix-doc/pull/2228
  144. SELF_DESTRUCT_AFTER: Final = "org.matrix.self_destruct_after"
  145. # cf https://github.com/matrix-org/matrix-doc/pull/1772
  146. ROOM_TYPE: Final = "type"
  147. # Whether a room can federate.
  148. FEDERATE: Final = "m.federate"
  149. # The creator of the room, as used in `m.room.create` events.
  150. #
  151. # This is deprecated in MSC2175.
  152. ROOM_CREATOR: Final = "creator"
  153. # Used in m.room.guest_access events.
  154. GUEST_ACCESS: Final = "guest_access"
  155. # The authorising user for joining a restricted room.
  156. AUTHORISING_USER: Final = "join_authorised_via_users_server"
  157. # Use for mentioning users.
  158. MENTIONS: Final = "m.mentions"
  159. # an unspecced field added to to-device messages to identify them uniquely-ish
  160. TO_DEVICE_MSGID: Final = "org.matrix.msgid"
  161. class RoomTypes:
  162. """Understood values of the room_type field of m.room.create events."""
  163. SPACE: Final = "m.space"
  164. class RoomEncryptionAlgorithms:
  165. MEGOLM_V1_AES_SHA2: Final = "m.megolm.v1.aes-sha2"
  166. DEFAULT: Final = MEGOLM_V1_AES_SHA2
  167. class AccountDataTypes:
  168. DIRECT: Final = "m.direct"
  169. IGNORED_USER_LIST: Final = "m.ignored_user_list"
  170. TAG: Final = "m.tag"
  171. PUSH_RULES: Final = "m.push_rules"
  172. class HistoryVisibility:
  173. INVITED: Final = "invited"
  174. JOINED: Final = "joined"
  175. SHARED: Final = "shared"
  176. WORLD_READABLE: Final = "world_readable"
  177. class GuestAccess:
  178. CAN_JOIN: Final = "can_join"
  179. # anything that is not "can_join" is considered "forbidden", but for completeness:
  180. FORBIDDEN: Final = "forbidden"
  181. class ReceiptTypes:
  182. READ: Final = "m.read"
  183. READ_PRIVATE: Final = "m.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"
  191. class ApprovalNoticeMedium:
  192. """Identifier for the medium this server will use to serve notice of approval for a
  193. specific user's registration.
  194. As defined in https://github.com/matrix-org/matrix-spec-proposals/blob/babolivier/m_not_approved/proposals/3866-user-not-approved-error.md
  195. """
  196. NONE = "org.matrix.msc3866.none"
  197. EMAIL = "org.matrix.msc3866.email"
  198. class Direction(enum.Enum):
  199. BACKWARDS = "b"
  200. FORWARDS = "f"