summary refs log tree commit diff
path: root/packages/overlays/matrix-synapse/patches/0034-Expose-tombstone-in-room-admin-api.patch
blob: 06a5789848be5aea65fd9e9eba8271de370a87a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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