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

Commit

Permalink
Implement MSC4069: Inhibit profile propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Nov 15, 2023
1 parent 4dd18bd commit a69a199
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
4 changes: 4 additions & 0 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,7 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
self.msc4028_push_encrypted_events = experimental.get(
"msc4028_push_encrypted_events", False
)

self.msc4069_profile_inhibit_propagation = experimental.get(
"msc4069_profile_inhibit_propagation", False
)
10 changes: 8 additions & 2 deletions synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ async def set_displayname(
new_displayname: str,
by_admin: bool = False,
deactivation: bool = False,
propagate: bool = True,
) -> None:
"""Set the displayname of a user
Expand All @@ -138,6 +139,7 @@ async def set_displayname(
new_displayname: The displayname to give this user.
by_admin: Whether this change was made by an administrator.
deactivation: Whether this change was made while deactivating the user.
propagate: Whether this change also applies to the user's membership events.
"""
if not self.hs.is_mine(target_user):
raise SynapseError(400, "User is not hosted on this homeserver")
Expand Down Expand Up @@ -188,7 +190,8 @@ async def set_displayname(
target_user.to_string(), profile, by_admin, deactivation
)

await self._update_join_states(requester, target_user)
if propagate:
await self._update_join_states(requester, target_user)

async def get_avatar_url(self, target_user: UserID) -> Optional[str]:
if self.hs.is_mine(target_user):
Expand Down Expand Up @@ -221,6 +224,7 @@ async def set_avatar_url(
new_avatar_url: str,
by_admin: bool = False,
deactivation: bool = False,
propagate: bool = True,
) -> None:
"""Set a new avatar URL for a user.
Expand All @@ -230,6 +234,7 @@ async def set_avatar_url(
new_avatar_url: The avatar URL to give this user.
by_admin: Whether this change was made by an administrator.
deactivation: Whether this change was made while deactivating the user.
propagate: Whether this change also applies to the user's membership events.
"""
if not self.hs.is_mine(target_user):
raise SynapseError(400, "User is not hosted on this homeserver")
Expand Down Expand Up @@ -278,7 +283,8 @@ async def set_avatar_url(
target_user.to_string(), profile, by_admin, deactivation
)

await self._update_join_states(requester, target_user)
if propagate:
await self._update_join_states(requester, target_user)

@cached()
async def check_avatar_size_and_mime_type(self, mxc: str) -> bool:
Expand Down
28 changes: 26 additions & 2 deletions synapse/rest/client/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

""" This module contains REST servlets to do with profile: /profile/<paths> """

from http import HTTPStatus
from typing import TYPE_CHECKING, Tuple

Expand All @@ -27,6 +28,23 @@
from synapse.server import HomeServer


def _read_propagate(hs: "HomeServer", request: SynapseRequest)->bool:
propagate = True
if hs.config.experimental.msc4069_profile_inhibit_propagation:
do_propagate = request.args.get(b"org.matrix.msc4069.propagate")
if do_propagate is not None:
do_propagate = do_propagate[0].lower()
if do_propagate not in [b'true', b'false']:
raise SynapseError(
400,
"'propagate' is malformed",
errcode=Codes.INVALID_PARAM
)
else:
propagate = do_propagate == b'true'
return propagate


class ProfileDisplaynameRestServlet(RestServlet):
PATTERNS = client_patterns("/profile/(?P<user_id>[^/]*)/displayname", v1=True)
CATEGORY = "Event sending requests"
Expand Down Expand Up @@ -80,7 +98,11 @@ async def on_PUT(
errcode=Codes.BAD_JSON,
)

await self.profile_handler.set_displayname(user, requester, new_name, is_admin)
propagate = _read_propagate(self.hs, request)

await self.profile_handler.set_displayname(
user, requester, new_name, is_admin, propagate=propagate
)

return 200, {}

Expand Down Expand Up @@ -135,8 +157,10 @@ async def on_PUT(
400, "Missing key 'avatar_url'", errcode=Codes.MISSING_PARAM
)

propagate = _read_propagate(self.hs, request)

await self.profile_handler.set_avatar_url(
user, requester, new_avatar_url, is_admin
user, requester, new_avatar_url, is_admin, propagate=propagate
)

return 200, {}
Expand Down
2 changes: 2 additions & 0 deletions synapse/rest/client/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def on_GET(self, request: Request) -> Tuple[int, JsonDict]:
"org.matrix.msc3981": self.config.experimental.msc3981_recurse_relations,
# Adds support for deleting account data.
"org.matrix.msc3391": self.config.experimental.msc3391_enabled,
# Allows clients to inhibit profile update propagation.
"org.matrix.msc4069": self.config.experimental.msc4069_profile_inhibit_propagation,
},
},
)
Expand Down

0 comments on commit a69a199

Please sign in to comment.