Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add a constant for m.federate. (#10775)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep authored Sep 8, 2021
1 parent 66d72b7 commit 0288e60
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.d/10775.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a constant for `m.federate`.
3 changes: 3 additions & 0 deletions synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ class EventContentFields:
# cf https://github.com/matrix-org/matrix-doc/pull/1772
ROOM_TYPE = "type"

# Whether a room can federate.
FEDERATE = "m.federate"

# The creator of the room, as used in `m.room.create` events.
ROOM_CREATOR = "creator"

Expand Down
10 changes: 8 additions & 2 deletions synapse/event_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
from signedjson.sign import SignatureVerifyException, verify_signed_json
from unpaddedbase64 import decode_base64

from synapse.api.constants import MAX_PDU_SIZE, EventTypes, JoinRules, Membership
from synapse.api.constants import (
MAX_PDU_SIZE,
EventContentFields,
EventTypes,
JoinRules,
Membership,
)
from synapse.api.errors import AuthError, EventSizeError, SynapseError
from synapse.api.room_versions import (
KNOWN_ROOM_VERSIONS,
Expand Down Expand Up @@ -236,7 +242,7 @@ def _can_federate(event: EventBase, auth_events: StateMap[EventBase]) -> bool:
if not creation_event:
return False

return creation_event.content.get("m.federate", True) is True
return creation_event.content.get(EventContentFields.FEDERATE, True) is True


def _is_membership_change_allowed(
Expand Down
10 changes: 8 additions & 2 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
from typing_extensions import TypedDict

from synapse import types
from synapse.api.constants import MAX_USERID_LENGTH, EventTypes, JoinRules, LoginType
from synapse.api.constants import (
MAX_USERID_LENGTH,
EventContentFields,
EventTypes,
JoinRules,
LoginType,
)
from synapse.api.errors import AuthError, Codes, ConsentNotGivenError, SynapseError
from synapse.appservice import ApplicationService
from synapse.config.server import is_threepid_reserved
Expand Down Expand Up @@ -405,7 +411,7 @@ async def _create_and_join_rooms(self, user_id: str) -> None:

# Choose whether to federate the new room.
if not self.hs.config.registration.autocreate_auto_join_rooms_federated:
stub_config["creation_content"] = {"m.federate": False}
stub_config["creation_content"] = {EventContentFields.FEDERATE: False}

for r in self.hs.config.registration.auto_join_rooms:
logger.info("Auto-joining %s to %s", user_id, r)
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ async def clone_existing_room(
old_room_create_event = await self.store.get_create_event_for_room(old_room_id)

# Check if the create event specified a non-federatable room
if not old_room_create_event.content.get("m.federate", True):
if not old_room_create_event.content.get(EventContentFields.FEDERATE, True):
# If so, mark the new room as non-federatable as well
creation_content["m.federate"] = False
creation_content[EventContentFields.FEDERATE] = False

initial_state = {}

Expand Down
4 changes: 3 additions & 1 deletion synapse/handlers/room_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ async def generate_room_entry(

# Return whether this room is open to federation users or not
create_event = current_state[EventTypes.Create, ""]
result["m.federate"] = create_event.content.get("m.federate", True)
result["m.federate"] = create_event.content.get(
EventContentFields.FEDERATE, True
)

name_event = current_state.get((EventTypes.Name, ""))
if name_event:
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ async def _handle_deltas(

elif typ == EventTypes.Create:
room_state["is_federatable"] = (
event_content.get("m.federate", True) is True
event_content.get(EventContentFields.FEDERATE, True) is True
)
elif typ == EventTypes.JoinRules:
room_state["join_rules"] = event_content.get("join_rule")
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from twisted.internet.defer import DeferredLock

from synapse.api.constants import EventTypes, Membership
from synapse.api.constants import EventContentFields, EventTypes, Membership
from synapse.api.errors import StoreError
from synapse.storage.database import DatabasePool
from synapse.storage.databases.main.state_deltas import StateDeltasStore
Expand Down Expand Up @@ -590,7 +590,7 @@ def _fetch_current_state_stats(txn):
room_state["canonical_alias"] = event.content.get("alias")
elif event.type == EventTypes.Create:
room_state["is_federatable"] = (
event.content.get("m.federate", True) is True
event.content.get(EventContentFields.FEDERATE, True) is True
)

await self.update_room_state(room_id, room_state)
Expand Down

0 comments on commit 0288e60

Please sign in to comment.