summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorEmelie Graven <e.graven@famedly.com>2023-01-11 19:41:52 +0100
committerGitHub <noreply@github.com>2023-01-11 18:41:52 +0000
commitdd9e71dc7fa91b81adfaaf8669aaf7ee976ffcd7 (patch)
treee54c2a02c07813e608fee098cf4c57ced49e50e8 /synapse
parentFactor out common code in tests and fix comments. (#14819) (diff)
downloadsynapse-dd9e71dc7fa91b81adfaaf8669aaf7ee976ffcd7.tar.xz
Add `set_displayname` to the module API (#14629)
Diffstat (limited to 'synapse')
-rw-r--r--synapse/module_api/__init__.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/synapse/module_api/__init__.py b/synapse/module_api/__init__.py
index 6f4a934b05..6153a48257 100644
--- a/synapse/module_api/__init__.py
+++ b/synapse/module_api/__init__.py
@@ -1585,6 +1585,33 @@ class ModuleApi:
 
         return room_id_and_alias["room_id"], room_id_and_alias.get("room_alias", None)
 
+    async def set_displayname(
+        self,
+        user_id: UserID,
+        new_displayname: str,
+        deactivation: bool = False,
+    ) -> None:
+        """Sets a user's display name.
+
+        Added in Synapse v1.76.0.
+
+        Args:
+            user_id:
+                The user whose display name is to be changed.
+            new_displayname:
+                The new display name to give the user.
+            deactivation:
+                Whether this change was made while deactivating the user.
+        """
+        requester = create_requester(user_id)
+        await self._hs.get_profile_handler().set_displayname(
+            target_user=user_id,
+            requester=requester,
+            new_displayname=new_displayname,
+            by_admin=True,
+            deactivation=deactivation,
+        )
+
 
 class PublicRoomListManager:
     """Contains methods for adding to, removing from and querying whether a room