constants.py 6.6 KB

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