diff --git a/packages/overlays/matrix-synapse/patches/0034-Expose-tombstone-in-room-admin-api.patch b/packages/overlays/matrix-synapse/patches/0034-Expose-tombstone-in-room-admin-api.patch
new file mode 100644
index 0000000..06a5789
--- /dev/null
+++ b/packages/overlays/matrix-synapse/patches/0034-Expose-tombstone-in-room-admin-api.patch
@@ -0,0 +1,139 @@
+From 8da5632efc85ad4043fd81e49b4a68fd8bab226e Mon Sep 17 00:00:00 2001
+From: Rory& <root@rory.gay>
+Date: Tue, 27 May 2025 06:37:52 +0200
+Subject: [PATCH 34/34] Expose tombstone in room admin api
+
+---
+ synapse/rest/admin/rooms.py | 1 +
+ synapse/rest/client/room.py | 1 -
+ synapse/storage/databases/main/room.py | 68 +++++++++++++++++++-------
+ 3 files changed, 50 insertions(+), 20 deletions(-)
+
+diff --git a/synapse/rest/admin/rooms.py b/synapse/rest/admin/rooms.py
+index f8c5bf18d4..60a28abd18 100644
+--- a/synapse/rest/admin/rooms.py
++++ b/synapse/rest/admin/rooms.py
+@@ -260,6 +260,7 @@ class ListRoomRestServlet(RestServlet):
+ search_term,
+ public_rooms,
+ empty_rooms,
++ emma_include_tombstone = True
+ )
+
+ response = {
+diff --git a/synapse/rest/client/room.py b/synapse/rest/client/room.py
+index 725b2162fd..8408c687cc 100644
+--- a/synapse/rest/client/room.py
++++ b/synapse/rest/client/room.py
+@@ -898,7 +898,6 @@ class RoomEventServlet(RestServlet):
+ request,
+ "fi.mau.msc2815.include_unredacted_content"
+ )
+- == "true"
+ )
+ if include_unredacted_content and not await self.auth.is_server_admin(
+ requester
+diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py
+index 56217fccdf..5f4d024fce 100644
+--- a/synapse/storage/databases/main/room.py
++++ b/synapse/storage/databases/main/room.py
+@@ -608,6 +608,7 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
+ search_term: Optional[str],
+ public_rooms: Optional[bool],
+ empty_rooms: Optional[bool],
++ emma_include_tombstone: bool = False,
+ ) -> Tuple[List[Dict[str, Any]], int]:
+ """Function to retrieve a paginated list of rooms as json.
+
+@@ -627,6 +628,7 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
+ If true, empty rooms are queried.
+ if false, empty rooms are excluded from the query. When it is
+ none (the default), both empty rooms and none-empty rooms are queried.
++ emma_include_tombstone: If true, include tombstone events in the results.
+ Returns:
+ A list of room dicts and an integer representing the total number of
+ rooms that exist given this query
+@@ -755,6 +757,17 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
+ where=where_clause,
+ )
+
++ # Emma: we're assuming this is the same db...
++ get_current_state_event_id_sql = """
++ SELECT event_id FROM current_state_events
++ WHERE room_id = ? AND type = ? AND state_key = ?
++ """
++
++ get_event_json_sql = """
++ SELECT json FROM event_json
++ WHERE event_id = ?
++ """
++
+ def _get_rooms_paginate_txn(
+ txn: LoggingTransaction,
+ ) -> Tuple[List[Dict[str, Any]], int]:
+@@ -765,26 +778,43 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
+ # Refactor room query data into a structured dictionary
+ rooms = []
+ for room in txn:
++ roomData = {
++ "room_id": room[0],
++ "name": room[1],
++ "canonical_alias": room[2],
++ "joined_members": room[3],
++ "joined_local_members": room[4],
++ "version": room[5],
++ "creator": room[6],
++ "encryption": room[7],
++ # room_stats_state.federatable is an integer on sqlite.
++ "federatable": bool(room[8]),
++ # rooms.is_public is an integer on sqlite.
++ "public": bool(room[9]),
++ "join_rules": room[10],
++ "guest_access": room[11],
++ "history_visibility": room[12],
++ "state_events": room[13],
++ "room_type": room[14],
++ }
++
++ if emma_include_tombstone:
++ tombstone_id = self.db_pool.execute("get_tombstone_event_id", get_current_state_event_id_sql, (room[0], EventTypes.Tombstone, "")).fetchone()
++ #if tombstone_id:
++ # tombstone_event_id = tombstone_id[0]
++ # # Get the tombstone event
++ # event_json = self.db_pool.execute(
++ # "get_tombstone_event_json",
++ # get_event_json_sql,
++ # (tombstone_event_id)
++ # ).fetchone()
++#
++ # roomData["gay.rory.synapse_extensions.tombstone"] = event_json
++ #else:
++ # roomData["gay.rory.synapse_extensions.tombstone"] = None
++
+ rooms.append(
+- {
+- "room_id": room[0],
+- "name": room[1],
+- "canonical_alias": room[2],
+- "joined_members": room[3],
+- "joined_local_members": room[4],
+- "version": room[5],
+- "creator": room[6],
+- "encryption": room[7],
+- # room_stats_state.federatable is an integer on sqlite.
+- "federatable": bool(room[8]),
+- # rooms.is_public is an integer on sqlite.
+- "public": bool(room[9]),
+- "join_rules": room[10],
+- "guest_access": room[11],
+- "history_visibility": room[12],
+- "state_events": room[13],
+- "room_type": room[14],
+- }
++ roomData
+ )
+
+ # Execute the count query
+--
+2.49.0
+
|