Skip to content

Commit

Permalink
Merge pull request #167 from ianmacd/pr8
Browse files Browse the repository at this point in the history
Add `/rooms/all/<SessionID:sid>` for server-wide message deletion.
  • Loading branch information
jagerman authored Jan 20, 2023
2 parents e912f4c + cc59aa5 commit 2c8e4f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions sogs/routes/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,33 @@ def delete_all_posts(room, sid):
if not deleted:
abort(http.NOT_FOUND)
return jsonify({})


@rooms.delete("/rooms/all/<SessionID:sid>")
def delete_user_posts_from_all_rooms(sid):
"""
Deletes all posts from all rooms by a given user.
# URL Parameters
- `sid` — the session id of the user to ban
# Return value
A JSON dict with the keys:
- `total` — The total number of posts deleted across all rooms.
- `rooms` — A dict of room tokens and their deletion counts.
"""
deletions = {}
total = 0
user = muser.User(session_id=sid, autovivify=False)
for room in mroom.get_accessible_rooms(g.user):
try:
count, _ = room.delete_all_posts(user, deleter=g.user)
total += count
deletions[room.token] = count
except exc.BadPermission:
pass

return jsonify({"total": total, "rooms": deletions})
2 changes: 1 addition & 1 deletion sogs/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def ban_user(sid):
The user's messages are not deleted by this request. In order to ban and delete all messages
use the [`/sequence`](#post-sequence) endpoint to bundle a `/user/.../ban` with a
[`/user/.../deleteMessages`](#post-usersiddeleteMessages) request.
[`/rooms/all/...`](#delete-roomsallsid) request.
# Return value
Expand Down

0 comments on commit 2c8e4f1

Please sign in to comment.