Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --force-purge option to room delete command #130

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions synadm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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)

Expand Down
13 changes: 10 additions & 3 deletions synadm/cli/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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)
Expand Down