2023-11-21 15:29:58 -05:00
|
|
|
#
|
|
|
|
# This file is licensed under the Affero General Public License (AGPL) version 3.
|
|
|
|
#
|
2024-01-23 06:26:48 -05:00
|
|
|
# Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
|
|
# Copyright 2017 Vector Creations Ltd
|
|
|
|
# Copyright 2014-2016 OpenMarket Ltd
|
2023-11-21 15:29:58 -05:00
|
|
|
# Copyright (C) 2023 New Vector, Ltd
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# See the GNU Affero General Public License for more details:
|
|
|
|
# <https://www.gnu.org/licenses/agpl-3.0.html>.
|
|
|
|
#
|
|
|
|
# Originally licensed under the Apache License, Version 2.0:
|
|
|
|
# <http://www.apache.org/licenses/LICENSE-2.0>.
|
|
|
|
#
|
|
|
|
# [This file includes modifications made by New Vector Limited]
|
|
|
|
#
|
|
|
|
#
|
2014-08-12 22:14:34 -04:00
|
|
|
|
2014-08-12 10:10:52 -04:00
|
|
|
"""Contains constants from the specification."""
|
|
|
|
|
2023-01-27 07:27:55 -05:00
|
|
|
import enum
|
2023-08-15 08:11:20 -04:00
|
|
|
from typing import Final
|
2021-11-25 11:14:23 -05:00
|
|
|
|
2021-04-23 14:20:44 -04:00
|
|
|
# the max size of a (canonical-json-encoded) event
|
|
|
|
MAX_PDU_SIZE = 65536
|
|
|
|
|
2018-05-01 11:19:39 -04:00
|
|
|
# the "depth" field on events is limited to 2**63 - 1
|
2022-03-29 06:41:19 -04:00
|
|
|
MAX_DEPTH = 2**63 - 1
|
2018-05-01 11:19:39 -04:00
|
|
|
|
2019-05-08 12:01:30 -04:00
|
|
|
# the maximum length for a room alias is 255 characters
|
|
|
|
MAX_ALIAS_LENGTH = 255
|
|
|
|
|
2019-05-20 06:20:08 -04:00
|
|
|
# the maximum length for a user id is 255 characters
|
|
|
|
MAX_USERID_LENGTH = 255
|
|
|
|
|
2022-10-04 09:47:04 -04:00
|
|
|
# Constant value used for the pseudo-thread which is the main timeline.
|
|
|
|
MAIN_TIMELINE: Final = "main"
|
|
|
|
|
2014-08-12 10:10:52 -04:00
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class Membership:
|
2014-08-12 10:10:52 -04:00
|
|
|
"""Represents the membership states of a user in a room."""
|
2019-06-20 05:32:02 -04:00
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
INVITE: Final = "invite"
|
|
|
|
JOIN: Final = "join"
|
|
|
|
KNOCK: Final = "knock"
|
|
|
|
LEAVE: Final = "leave"
|
|
|
|
BAN: Final = "ban"
|
|
|
|
LIST: Final = (INVITE, JOIN, KNOCK, LEAVE, BAN)
|
2014-08-12 10:10:52 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class PresenceState:
|
2014-08-12 10:10:52 -04:00
|
|
|
"""Represents the presence state of a user."""
|
2019-06-20 05:32:02 -04:00
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
OFFLINE: Final = "offline"
|
|
|
|
UNAVAILABLE: Final = "unavailable"
|
|
|
|
ONLINE: Final = "online"
|
|
|
|
BUSY: Final = "org.matrix.msc3026.busy"
|
2014-08-28 05:59:15 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class JoinRules:
|
2021-11-25 11:14:23 -05:00
|
|
|
PUBLIC: Final = "public"
|
|
|
|
KNOCK: Final = "knock"
|
|
|
|
INVITE: Final = "invite"
|
|
|
|
PRIVATE: Final = "private"
|
2021-03-31 16:39:08 -04:00
|
|
|
# As defined for MSC3083.
|
2021-11-25 11:14:23 -05:00
|
|
|
RESTRICTED: Final = "restricted"
|
2022-05-17 06:41:39 -04:00
|
|
|
# As defined for MSC3787.
|
|
|
|
KNOCK_RESTRICTED: Final = "knock_restricted"
|
2014-09-15 05:23:20 -04:00
|
|
|
|
|
|
|
|
2021-06-17 12:53:27 -04:00
|
|
|
class RestrictedJoinRuleTypes:
|
|
|
|
"""Understood types for the allow rules in restricted join rules."""
|
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
ROOM_MEMBERSHIP: Final = "m.room_membership"
|
2021-06-17 12:53:27 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class LoginType:
|
2021-11-25 11:14:23 -05:00
|
|
|
PASSWORD: Final = "m.login.password"
|
|
|
|
EMAIL_IDENTITY: Final = "m.login.email.identity"
|
|
|
|
MSISDN: Final = "m.login.msisdn"
|
|
|
|
RECAPTCHA: Final = "m.login.recaptcha"
|
|
|
|
TERMS: Final = "m.login.terms"
|
|
|
|
SSO: Final = "m.login.sso"
|
|
|
|
DUMMY: Final = "m.login.dummy"
|
2022-02-04 07:15:13 -05:00
|
|
|
REGISTRATION_TOKEN: Final = "m.login.registration_token"
|
2015-04-02 12:01:29 -04:00
|
|
|
|
2014-12-03 11:07:21 -05:00
|
|
|
|
2021-04-12 10:13:55 -04:00
|
|
|
# This is used in the `type` parameter for /register when called by
|
|
|
|
# an appservice to register a new user.
|
2021-11-25 11:14:23 -05:00
|
|
|
APP_SERVICE_REGISTRATION_TYPE: Final = "m.login.application_service"
|
2021-04-12 10:13:55 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class EventTypes:
|
2021-11-25 11:14:23 -05:00
|
|
|
Member: Final = "m.room.member"
|
|
|
|
Create: Final = "m.room.create"
|
|
|
|
Tombstone: Final = "m.room.tombstone"
|
|
|
|
JoinRules: Final = "m.room.join_rules"
|
|
|
|
PowerLevels: Final = "m.room.power_levels"
|
|
|
|
Aliases: Final = "m.room.aliases"
|
|
|
|
Redaction: Final = "m.room.redaction"
|
|
|
|
ThirdPartyInvite: Final = "m.room.third_party_invite"
|
|
|
|
|
|
|
|
RoomHistoryVisibility: Final = "m.room.history_visibility"
|
|
|
|
CanonicalAlias: Final = "m.room.canonical_alias"
|
|
|
|
Encrypted: Final = "m.room.encrypted"
|
|
|
|
RoomAvatar: Final = "m.room.avatar"
|
|
|
|
RoomEncryption: Final = "m.room.encryption"
|
|
|
|
GuestAccess: Final = "m.room.guest_access"
|
2015-07-02 11:20:10 -04:00
|
|
|
|
2014-12-12 05:56:14 -05:00
|
|
|
# These are used for validation
|
2021-11-25 11:14:23 -05:00
|
|
|
Message: Final = "m.room.message"
|
|
|
|
Topic: Final = "m.room.topic"
|
|
|
|
Name: Final = "m.room.name"
|
2015-01-28 11:16:53 -05:00
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
ServerACL: Final = "m.room.server_acl"
|
|
|
|
Pinned: Final = "m.room.pinned_events"
|
2018-07-04 10:31:00 -04:00
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
Retention: Final = "m.room.retention"
|
2019-11-04 12:09:22 -05:00
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
Dummy: Final = "org.matrix.dummy_event"
|
2020-12-18 04:49:18 -05:00
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
SpaceChild: Final = "m.space.child"
|
|
|
|
SpaceParent: Final = "m.space.parent"
|
2021-03-18 14:24:16 -04:00
|
|
|
|
2022-11-03 12:21:31 -04:00
|
|
|
Reaction: Final = "m.reaction"
|
|
|
|
|
2024-03-19 13:52:53 -04:00
|
|
|
CallInvite: Final = "m.call.invite"
|
|
|
|
|
2015-01-28 11:16:53 -05:00
|
|
|
|
2021-05-11 06:02:56 -04:00
|
|
|
class ToDeviceEventTypes:
|
2021-11-25 11:14:23 -05:00
|
|
|
RoomKeyRequest: Final = "m.room_key_request"
|
2021-05-11 06:02:56 -04:00
|
|
|
|
|
|
|
|
2021-07-27 09:36:38 -04:00
|
|
|
class DeviceKeyAlgorithms:
|
|
|
|
"""Spec'd algorithms for the generation of per-device keys"""
|
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
ED25519: Final = "ed25519"
|
|
|
|
CURVE25519: Final = "curve25519"
|
|
|
|
SIGNED_CURVE25519: Final = "signed_curve25519"
|
2021-07-27 09:36:38 -04:00
|
|
|
|
|
|
|
|
2021-02-19 13:20:34 -05:00
|
|
|
class EduTypes:
|
2022-05-27 07:14:36 -04:00
|
|
|
PRESENCE: Final = "m.presence"
|
|
|
|
TYPING: Final = "m.typing"
|
|
|
|
RECEIPT: Final = "m.receipt"
|
|
|
|
DEVICE_LIST_UPDATE: Final = "m.device_list_update"
|
|
|
|
SIGNING_KEY_UPDATE: Final = "m.signing_key_update"
|
|
|
|
UNSTABLE_SIGNING_KEY_UPDATE: Final = "org.matrix.signing_key_update"
|
|
|
|
DIRECT_TO_DEVICE: Final = "m.direct_to_device"
|
2021-02-19 13:20:34 -05:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class RejectedReason:
|
2021-11-25 11:14:23 -05:00
|
|
|
AUTH_ERROR: Final = "auth_error"
|
2022-12-13 08:19:19 -05:00
|
|
|
OVERSIZED_EVENT: Final = "oversized_event"
|
2015-07-13 11:48:06 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class RoomCreationPreset:
|
2021-11-25 11:14:23 -05:00
|
|
|
PRIVATE_CHAT: Final = "private_chat"
|
|
|
|
PUBLIC_CHAT: Final = "public_chat"
|
|
|
|
TRUSTED_PRIVATE_CHAT: Final = "trusted_private_chat"
|
2016-08-25 13:34:47 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class ThirdPartyEntityKind:
|
2021-11-25 11:14:23 -05:00
|
|
|
USER: Final = "user"
|
|
|
|
LOCATION: Final = "location"
|
2018-07-25 17:10:39 -04:00
|
|
|
|
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
ServerNoticeMsgType: Final = "m.server_notice"
|
|
|
|
ServerNoticeLimitReached: Final = "m.server_notice.usage_limit_reached"
|
2018-12-14 13:20:59 -05:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class UserTypes:
|
2018-12-14 13:20:59 -05:00
|
|
|
"""Allows for user type specific behaviour. With the benefit of hindsight
|
|
|
|
'admin' and 'guest' users should also be UserTypes. Normal users are type None
|
|
|
|
"""
|
2019-06-20 05:32:02 -04:00
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
SUPPORT: Final = "support"
|
|
|
|
BOT: Final = "bot"
|
|
|
|
ALL_USER_TYPES: Final = (SUPPORT, BOT)
|
2019-05-14 11:59:21 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class RelationTypes:
|
2019-05-14 11:59:21 -04:00
|
|
|
"""The types of relations known to this server."""
|
2019-06-20 05:32:02 -04:00
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
ANNOTATION: Final = "m.annotation"
|
|
|
|
REPLACE: Final = "m.replace"
|
|
|
|
REFERENCE: Final = "m.reference"
|
2022-03-10 10:36:13 -05:00
|
|
|
THREAD: Final = "m.thread"
|
2019-10-24 06:48:46 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class LimitBlockingTypes:
|
2019-10-24 06:48:46 -04:00
|
|
|
"""Reasons that a server may be blocked"""
|
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
MONTHLY_ACTIVE_USER: Final = "monthly_active_user"
|
|
|
|
HS_DISABLED: Final = "hs_disabled"
|
2019-10-29 14:35:49 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class EventContentFields:
|
2019-11-01 06:30:51 -04:00
|
|
|
"""Fields found in events' content, regardless of type."""
|
2019-11-01 06:39:14 -04:00
|
|
|
|
2019-11-01 06:30:51 -04:00
|
|
|
# Labels for the event, cf https://github.com/matrix-org/matrix-doc/pull/2326
|
2021-11-25 11:14:23 -05:00
|
|
|
LABELS: Final = "org.matrix.labels"
|
2019-12-03 14:19:45 -05:00
|
|
|
|
|
|
|
# Timestamp to delete the event after
|
|
|
|
# cf https://github.com/matrix-org/matrix-doc/pull/2228
|
2021-11-25 11:14:23 -05:00
|
|
|
SELF_DESTRUCT_AFTER: Final = "org.matrix.self_destruct_after"
|
2020-06-10 12:44:34 -04:00
|
|
|
|
2021-03-18 14:24:16 -04:00
|
|
|
# cf https://github.com/matrix-org/matrix-doc/pull/1772
|
2021-11-25 11:14:23 -05:00
|
|
|
ROOM_TYPE: Final = "type"
|
2021-03-18 14:24:16 -04:00
|
|
|
|
2021-09-08 10:00:43 -04:00
|
|
|
# Whether a room can federate.
|
2021-11-25 11:14:23 -05:00
|
|
|
FEDERATE: Final = "m.federate"
|
2021-09-08 10:00:43 -04:00
|
|
|
|
2021-09-01 11:27:58 -04:00
|
|
|
# The creator of the room, as used in `m.room.create` events.
|
2023-04-06 16:26:28 -04:00
|
|
|
#
|
|
|
|
# This is deprecated in MSC2175.
|
2021-11-25 11:14:23 -05:00
|
|
|
ROOM_CREATOR: Final = "creator"
|
2021-09-01 11:27:58 -04:00
|
|
|
|
2021-09-06 07:17:16 -04:00
|
|
|
# Used in m.room.guest_access events.
|
2021-11-25 11:14:23 -05:00
|
|
|
GUEST_ACCESS: Final = "guest_access"
|
2021-09-06 07:17:16 -04:00
|
|
|
|
2021-09-30 11:13:59 -04:00
|
|
|
# The authorising user for joining a restricted room.
|
2021-11-25 11:14:23 -05:00
|
|
|
AUTHORISING_USER: Final = "join_authorised_via_users_server"
|
2021-09-30 11:13:59 -04:00
|
|
|
|
2023-01-27 10:16:21 -05:00
|
|
|
# Use for mentioning users.
|
2023-06-06 04:11:07 -04:00
|
|
|
MENTIONS: Final = "m.mentions"
|
2023-01-27 10:16:21 -05:00
|
|
|
|
2022-12-06 04:52:55 -05:00
|
|
|
# an unspecced field added to to-device messages to identify them uniquely-ish
|
|
|
|
TO_DEVICE_MSGID: Final = "org.matrix.msgid"
|
|
|
|
|
2020-06-10 12:44:34 -04:00
|
|
|
|
2021-06-29 12:00:04 -04:00
|
|
|
class RoomTypes:
|
|
|
|
"""Understood values of the room_type field of m.room.create events."""
|
|
|
|
|
2021-11-25 11:14:23 -05:00
|
|
|
SPACE: Final = "m.space"
|
2021-06-29 12:00:04 -04:00
|
|
|
|
|
|
|
|
2020-09-04 06:54:56 -04:00
|
|
|
class RoomEncryptionAlgorithms:
|
2021-11-25 11:14:23 -05:00
|
|
|
MEGOLM_V1_AES_SHA2: Final = "m.megolm.v1.aes-sha2"
|
|
|
|
DEFAULT: Final = MEGOLM_V1_AES_SHA2
|
2020-10-05 09:28:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
class AccountDataTypes:
|
2021-11-25 11:14:23 -05:00
|
|
|
DIRECT: Final = "m.direct"
|
|
|
|
IGNORED_USER_LIST: Final = "m.ignored_user_list"
|
2023-01-13 09:57:43 -05:00
|
|
|
TAG: Final = "m.tag"
|
2023-05-09 07:23:27 -04:00
|
|
|
PUSH_RULES: Final = "m.push_rules"
|
2020-12-16 08:46:37 -05:00
|
|
|
|
|
|
|
|
|
|
|
class HistoryVisibility:
|
2021-11-25 11:14:23 -05:00
|
|
|
INVITED: Final = "invited"
|
|
|
|
JOINED: Final = "joined"
|
|
|
|
SHARED: Final = "shared"
|
|
|
|
WORLD_READABLE: Final = "world_readable"
|
2021-07-28 04:05:11 -04:00
|
|
|
|
|
|
|
|
2021-09-06 07:17:16 -04:00
|
|
|
class GuestAccess:
|
2021-11-25 11:14:23 -05:00
|
|
|
CAN_JOIN: Final = "can_join"
|
2021-09-06 07:17:16 -04:00
|
|
|
# anything that is not "can_join" is considered "forbidden", but for completeness:
|
2021-11-25 11:14:23 -05:00
|
|
|
FORBIDDEN: Final = "forbidden"
|
2021-09-06 07:17:16 -04:00
|
|
|
|
|
|
|
|
2021-12-08 12:26:29 -05:00
|
|
|
class ReceiptTypes:
|
|
|
|
READ: Final = "m.read"
|
2022-08-05 11:09:33 -04:00
|
|
|
READ_PRIVATE: Final = "m.read.private"
|
2022-05-04 11:59:22 -04:00
|
|
|
FULLY_READ: Final = "m.fully_read"
|
2022-06-29 13:12:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
class PublicRoomsFilterFields:
|
|
|
|
"""Fields in the search filter for `/publicRooms` that we understand.
|
|
|
|
|
|
|
|
As defined in https://spec.matrix.org/v1.3/client-server-api/#post_matrixclientv3publicrooms
|
|
|
|
"""
|
|
|
|
|
|
|
|
GENERIC_SEARCH_TERM: Final = "generic_search_term"
|
2022-07-27 14:46:57 -04:00
|
|
|
ROOM_TYPES: Final = "room_types"
|
2022-09-29 09:23:24 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ApprovalNoticeMedium:
|
|
|
|
"""Identifier for the medium this server will use to serve notice of approval for a
|
|
|
|
specific user's registration.
|
|
|
|
|
|
|
|
As defined in https://github.com/matrix-org/matrix-spec-proposals/blob/babolivier/m_not_approved/proposals/3866-user-not-approved-error.md
|
|
|
|
"""
|
|
|
|
|
|
|
|
NONE = "org.matrix.msc3866.none"
|
|
|
|
EMAIL = "org.matrix.msc3866.email"
|
2023-01-27 07:27:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
class Direction(enum.Enum):
|
|
|
|
BACKWARDS = "b"
|
|
|
|
FORWARDS = "f"
|