From 7fdb7cfecb4e41d253638a22ad53368aea5e706e Mon Sep 17 00:00:00 2001 From: Nicolas Peugnet Date: Wed, 11 Oct 2023 12:00:25 +0200 Subject: [PATCH] Add --force-purge option to room delete command --- synadm/api.py | 8 ++++++-- synadm/cli/room.py | 13 ++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/synadm/api.py b/synadm/api.py index 75c0cb3d..1a843a33 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -843,7 +843,7 @@ def room_power_levels(self, from_, limit, name, order_by, reverse, return rooms def room_delete(self, room_id, new_room_user_id, room_name, message, - block, no_purge): + block, no_purge, force_purge): """ Delete a room and purge it if requested """ data = { @@ -857,11 +857,13 @@ def room_delete(self, room_id, new_room_user_id, room_name, message, data.update({"room_name": room_name}) if message: data.update({"message": message}) + if force_purge: + data.update({"force_purge": force_purge}) return self.query("delete", "v1/rooms/{room_id}", data=data, room_id=room_id) def room_delete_v2(self, room_id, new_room_user_id, room_name, message, - block, purge): + block, purge, force_purge): """ Delete a room asynchronously and purge it if requested """ data = { @@ -875,6 +877,8 @@ def room_delete_v2(self, room_id, new_room_user_id, room_name, message, data.update({"room_name": room_name}) if message: data.update({"message": message}) + if force_purge: + data.update({"force_purge": force_purge}) return self.query("delete", "v2/rooms/{room_id}", data=data, room_id=room_id) diff --git a/synadm/cli/room.py b/synadm/cli/room.py index dd3099a6..d22a178e 100644 --- a/synadm/cli/room.py +++ b/synadm/cli/room.py @@ -246,15 +246,22 @@ def members(helper, room_id): "--no-purge", is_flag=True, default=False, show_default=True, help="""Prevent removing of all traces of the room from your database.""") +@click.option( + "--force-purge", is_flag=True, default=False, show_default=True, + help="""Force a purge to go ahead even if there are local users still + in the room. Do not use this unless a regular purge operation fails, + as it could leave those users' clients in a confused state.""") @click.option( "--v1", is_flag=True, default=False, show_default=True, help="""Use version 1 of the room delete API instead of version 2""") @click.pass_obj @click.pass_context def delete(ctx, helper, room_id, new_room_user_id, room_name, message, block, - no_purge, v1): + no_purge, force_purge, v1): """ Delete and possibly purge a room. """ + if no_purge and force_purge: + click.echo("--force-purge will be ignored as --no-purge is set") room_details = helper.api.room_details(room_id) if "errcode" in room_details.keys(): if room_details["errcode"] == "M_NOT_FOUND": @@ -276,11 +283,11 @@ def delete(ctx, helper, room_id, new_room_user_id, room_name, message, block, if v1: room_del = helper.api.room_delete( room_id, mxid, room_name, - message, block, no_purge) + message, block, no_purge, force_purge) else: room_del = helper.api.room_delete_v2( room_id, mxid, room_name, - message, block, not bool(no_purge)) + message, block, not bool(no_purge), force_purge) if room_del is None: click.echo("Room not deleted.") raise SystemExit(1)