aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/ops
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/ops')
-rw-r--r--packages/meshbay-node/src/meshbay_node/ops/__init__.py2
-rw-r--r--packages/meshbay-node/src/meshbay_node/ops/chat.py19
2 files changed, 21 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/ops/__init__.py b/packages/meshbay-node/src/meshbay_node/ops/__init__.py
index bfdfd7b..fc5b7ef 100644
--- a/packages/meshbay-node/src/meshbay_node/ops/__init__.py
+++ b/packages/meshbay-node/src/meshbay_node/ops/__init__.py
@@ -41,6 +41,7 @@ from meshbay_node.ops.chat import (
ensure_chat_epoch,
open_chat_epoch,
prune_chat,
+ purge_chat,
)
from meshbay_node.ops.core import (
OpError,
@@ -140,6 +141,7 @@ __all__ = [
"pair_operator",
"plug_root",
"prune_chat",
+ "purge_chat",
"prune_index_cache",
"read_denylist",
"read_roster",
diff --git a/packages/meshbay-node/src/meshbay_node/ops/chat.py b/packages/meshbay-node/src/meshbay_node/ops/chat.py
index 539284b..9fc7b94 100644
--- a/packages/meshbay-node/src/meshbay_node/ops/chat.py
+++ b/packages/meshbay-node/src/meshbay_node/ops/chat.py
@@ -252,3 +252,22 @@ async def prune_chat(state: dict, group_id: str, max_age_days: int) -> dict:
group_id[:8], removed)
return {"group_id": group_id, "removed": removed,
"max_age_days": max_age_days}
+
+
+async def purge_chat(state: dict, group_id: str) -> dict:
+ """
+ Delete every stored message of the group. Epoch keys are kept, as in
+ `prune_chat`, and attachments too: they are files in a shared folder.
+
+ The replay index goes with the rows, which is harmless: the node takes a
+ sealed message only from the device that signed it, so the one party able
+ to send a purged message again is its author.
+ """
+ ctx = _group_ctx(state, group_id)
+ store = ctx.get("chat_store")
+ if store is None:
+ raise OpError("This group has no chat store", status=404)
+ removed = await store.delete_all()
+ log.info("Chat purged for group %s: %d message(s) removed",
+ group_id[:8], removed)
+ return {"group_id": group_id, "removed": removed}