Skip to content

Commit

Permalink
implement room blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonChen666 committed Dec 8, 2022
1 parent ad57179 commit 63fa8e5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions synadm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,23 @@ def room_delete(self, room_id, new_room_user_id, room_name, message,
data.update({"message": message})
return self.query("delete", f"v1/rooms/{room_id}", data=data)

def block_room(self, room_id, block):
""" Block or unblock a room.
Args:
room_id (string): Required.
block (boolean): Whether to block or unblock a room.
Returns:
string: JSON string containing the admin API's response or None if
an exception occurred. See Synapse admin API docs for details.
"""
# TODO prevent usage on versions before 1.48
data = {
"block": block
}
return self.query("put", f"v1/rooms/{room_id}/block", data=data)

def room_make_admin(self, room_id, user_id):
""" Grant a user room admin permission. If the user is not in the room,
and it is not publicly joinable, then invite the user.
Expand Down
14 changes: 14 additions & 0 deletions synadm/cli/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,17 @@ def make_admin(helper, room_id, user_id):
mxid = helper.generate_mxid(user_id)
out = helper.api.room_make_admin(room_id, mxid)
helper.output(out)


@room.command()
@click.argument("room_id", type=str)
@click.option(
"--block/--unblock", "-b", type=bool, default=True, show_default=True,
help="Specifies whether to block or unblock a room."
)
@click.pass_obj
def block(helper, room_id, block):
""" Block or unblock a room.
"""
out = helper.api.block_room(room_id, block)
helper.output(out)

0 comments on commit 63fa8e5

Please sign in to comment.