@@ -1677,3 +1677,77 @@ def test_redact_parent_thread(self) -> None:
16771677 relations [RelationTypes .THREAD ]["latest_event" ]["event_id" ],
16781678 related_event_id ,
16791679 )
1680+
1681+
1682+ class ThreadsTestCase (BaseRelationsTestCase ):
1683+ @unittest .override_config ({"experimental_features" : {"msc3856_enabled" : True }})
1684+ def test_threads (self ) -> None :
1685+ """Create threads and ensure the ordering is due to their latest event."""
1686+ # Create 2 threads.
1687+ thread_1 = self .parent_id
1688+ res = self .helper .send (self .room , body = "Thread Root!" , tok = self .user_token )
1689+ thread_2 = res ["event_id" ]
1690+
1691+ self ._send_relation (RelationTypes .THREAD , "m.room.test" )
1692+ self ._send_relation (RelationTypes .THREAD , "m.room.test" , parent_id = thread_2 )
1693+
1694+ # Request the threads in the room.
1695+ channel = self .make_request (
1696+ "GET" ,
1697+ f"/_matrix/client/unstable/org.matrix.msc3856/rooms/{ self .room } /threads" ,
1698+ access_token = self .user_token ,
1699+ )
1700+ self .assertEquals (200 , channel .code , channel .json_body )
1701+ thread_roots = [ev ["event_id" ] for ev in channel .json_body ["chunk" ]]
1702+ self .assertEqual (thread_roots , [thread_2 , thread_1 ])
1703+
1704+ # Update the first thread, the ordering should swap.
1705+ self ._send_relation (RelationTypes .THREAD , "m.room.test" )
1706+
1707+ channel = self .make_request (
1708+ "GET" ,
1709+ f"/_matrix/client/unstable/org.matrix.msc3856/rooms/{ self .room } /threads" ,
1710+ access_token = self .user_token ,
1711+ )
1712+ self .assertEquals (200 , channel .code , channel .json_body )
1713+ thread_roots = [ev ["event_id" ] for ev in channel .json_body ["chunk" ]]
1714+ self .assertEqual (thread_roots , [thread_1 , thread_2 ])
1715+
1716+ @unittest .override_config ({"experimental_features" : {"msc3856_enabled" : True }})
1717+ def test_pagination (self ) -> None :
1718+ """Create threads and paginate through them."""
1719+ # Create 2 threads.
1720+ thread_1 = self .parent_id
1721+ res = self .helper .send (self .room , body = "Thread Root!" , tok = self .user_token )
1722+ thread_2 = res ["event_id" ]
1723+
1724+ self ._send_relation (RelationTypes .THREAD , "m.room.test" )
1725+ self ._send_relation (RelationTypes .THREAD , "m.room.test" , parent_id = thread_2 )
1726+
1727+ # Request the threads in the room.
1728+ channel = self .make_request (
1729+ "GET" ,
1730+ f"/_matrix/client/unstable/org.matrix.msc3856/rooms/{ self .room } /threads?limit=1" ,
1731+ access_token = self .user_token ,
1732+ )
1733+ self .assertEquals (200 , channel .code , channel .json_body )
1734+ thread_roots = [ev ["event_id" ] for ev in channel .json_body ["chunk" ]]
1735+ self .assertEqual (thread_roots , [thread_2 ])
1736+
1737+ # Make sure next_batch has something in it that looks like it could be a
1738+ # valid token.
1739+ next_batch = channel .json_body .get ("next_batch" )
1740+ self .assertIsInstance (next_batch , str , channel .json_body )
1741+
1742+ channel = self .make_request (
1743+ "GET" ,
1744+ f"/_matrix/client/unstable/org.matrix.msc3856/rooms/{ self .room } /threads?limit=1&from={ next_batch } " ,
1745+ access_token = self .user_token ,
1746+ )
1747+ self .assertEquals (200 , channel .code , channel .json_body )
1748+ thread_roots = [ev ["event_id" ] for ev in channel .json_body ["chunk" ]]
1749+ self .assertEqual (thread_roots , [thread_1 ], channel .json_body )
1750+
1751+ self .assertNotIn ("next_batch" , channel .json_body , channel .json_body )
1752+
1753+ # XXX Test ignoring users.
0 commit comments