Skip to content

Commit a5837cf

Browse files
committed
Add subscribed and automatic to get_updated_thread_subscriptions_for_user
1 parent d1a7487 commit a5837cf

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

synapse/storage/databases/main/thread_subscriptions.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def get_updated_thread_subscriptions_txn(
352352

353353
async def get_updated_thread_subscriptions_for_user(
354354
self, user_id: str, from_id: int, to_id: int, limit: int
355-
) -> List[Tuple[int, str, str]]:
355+
) -> List[Tuple[int, str, str, bool, Optional[bool]]]:
356356
"""Get updates to thread subscriptions for a specific user.
357357
358358
Args:
@@ -362,22 +362,32 @@ async def get_updated_thread_subscriptions_for_user(
362362
limit: The maximum number of rows to return
363363
364364
Returns:
365-
A list of (stream_id, room_id, thread_root_event_id) tuples.
365+
A list of (stream_id, room_id, thread_root_event_id, subscribed, automatic) tuples.
366366
"""
367367

368368
def get_updated_thread_subscriptions_for_user_txn(
369369
txn: LoggingTransaction,
370-
) -> List[Tuple[int, str, str]]:
370+
) -> List[Tuple[int, str, str, bool, Optional[bool]]]:
371371
sql = """
372-
SELECT stream_id, room_id, event_id
372+
SELECT stream_id, room_id, event_id, subscribed, automatic
373373
FROM thread_subscriptions
374374
WHERE user_id = ? AND ? < stream_id AND stream_id <= ?
375375
ORDER BY stream_id ASC
376376
LIMIT ?
377377
"""
378378

379379
txn.execute(sql, (user_id, from_id, to_id, limit))
380-
return [(row[0], row[1], row[2]) for row in txn]
380+
return [
381+
(
382+
stream_id,
383+
room_id,
384+
event_id,
385+
# SQLite integer to boolean conversions
386+
bool(subscribed),
387+
bool(automatic) if subscribed else None,
388+
)
389+
for (stream_id, room_id, event_id, subscribed, automatic) in txn
390+
]
381391

382392
return await self.db_pool.runInteraction(
383393
"get_updated_thread_subscriptions_for_user",

tests/storage/test_thread_subscriptions.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ def test_purge_thread_subscriptions_for_user(self) -> None:
189189
limit=50,
190190
)
191191
)
192-
min_id = min(id for (id, _, _) in subscriptions)
192+
min_id = min(id for (id, _, _, _, _) in subscriptions)
193193
self.assertEqual(
194194
subscriptions,
195195
[
196-
(min_id, self.room_id, self.thread_root_id),
197-
(min_id + 1, self.room_id, self.other_thread_root_id),
196+
(min_id, self.room_id, self.thread_root_id, True, True),
197+
(min_id + 1, self.room_id, self.other_thread_root_id, True, False),
198198
],
199199
)
200200

@@ -259,7 +259,9 @@ def test_get_updated_thread_subscriptions_for_user(self) -> None:
259259
self.user_id, 0, stream_id2, 10
260260
)
261261
)
262-
self.assertEqual(updates, [(stream_id1, self.room_id, self.thread_root_id)])
262+
self.assertEqual(
263+
updates, [(stream_id1, self.room_id, self.thread_root_id, True, True)]
264+
)
263265

264266
# Get updates for other user
265267
updates = self.get_success(
@@ -268,5 +270,5 @@ def test_get_updated_thread_subscriptions_for_user(self) -> None:
268270
)
269271
)
270272
self.assertEqual(
271-
updates, [(stream_id2, self.room_id, self.other_thread_root_id)]
273+
updates, [(stream_id2, self.room_id, self.other_thread_root_id, True, True)]
272274
)

0 commit comments

Comments
 (0)