@@ -43,7 +43,10 @@ use super::{
4343use crate :: {
4444 RoomInfo , RoomMemberships , RoomState , StateChanges , StateStoreDataKey , StateStoreDataValue ,
4545 deserialized_responses:: MemberEvent ,
46- store:: { ChildTransactionId , QueueWedgeError , Result , SerializableEventContent , StateStoreExt } ,
46+ store:: {
47+ ChildTransactionId , QueueWedgeError , Result , SerializableEventContent , StateStoreExt ,
48+ ThreadStatus ,
49+ } ,
4750} ;
4851
4952/// `StateStore` integration tests.
@@ -98,6 +101,8 @@ pub trait StateStoreIntegrationTests {
98101 async fn test_server_info_saving ( & self ) ;
99102 /// Test fetching room infos based on [`RoomLoadSettings`].
100103 async fn test_get_room_infos ( & self ) ;
104+ /// Test loading thread subscriptions.
105+ async fn test_thread_subscriptions ( & self ) ;
101106}
102107
103108impl StateStoreIntegrationTests for DynStateStore {
@@ -1767,6 +1772,53 @@ impl StateStoreIntegrationTests for DynStateStore {
17671772 assert_eq ! ( all_rooms. len( ) , 0 ) ;
17681773 }
17691774 }
1775+
1776+ async fn test_thread_subscriptions ( & self ) {
1777+ let first_thread = event_id ! ( "$t1" ) ;
1778+ let second_thread = event_id ! ( "$t2" ) ;
1779+
1780+ // At first, there is no thread subscription.
1781+ let maybe_status = self . load_thread_subscription ( room_id ( ) , first_thread) . await . unwrap ( ) ;
1782+ assert ! ( maybe_status. is_none( ) ) ;
1783+
1784+ let maybe_status = self . load_thread_subscription ( room_id ( ) , second_thread) . await . unwrap ( ) ;
1785+ assert ! ( maybe_status. is_none( ) ) ;
1786+
1787+ // Setting the thread subscription works.
1788+ self . upsert_thread_subscription (
1789+ room_id ( ) ,
1790+ first_thread,
1791+ ThreadStatus :: Subscribed { automatic : true } ,
1792+ )
1793+ . await
1794+ . unwrap ( ) ;
1795+
1796+ self . upsert_thread_subscription (
1797+ room_id ( ) ,
1798+ second_thread,
1799+ ThreadStatus :: Subscribed { automatic : false } ,
1800+ )
1801+ . await
1802+ . unwrap ( ) ;
1803+
1804+ // Now, reading the thread subscription returns the expected status.
1805+ let maybe_status = self . load_thread_subscription ( room_id ( ) , first_thread) . await . unwrap ( ) ;
1806+ assert_eq ! ( maybe_status, Some ( ThreadStatus :: Subscribed { automatic: true } ) ) ;
1807+ let maybe_status = self . load_thread_subscription ( room_id ( ) , second_thread) . await . unwrap ( ) ;
1808+ assert_eq ! ( maybe_status, Some ( ThreadStatus :: Subscribed { automatic: false } ) ) ;
1809+
1810+ // We can override the thread subscription status.
1811+ self . upsert_thread_subscription ( room_id ( ) , first_thread, ThreadStatus :: Unsubscribed )
1812+ . await
1813+ . unwrap ( ) ;
1814+
1815+ // And it's correctly reflected.
1816+ let maybe_status = self . load_thread_subscription ( room_id ( ) , first_thread) . await . unwrap ( ) ;
1817+ assert_eq ! ( maybe_status, Some ( ThreadStatus :: Unsubscribed ) ) ;
1818+ // And the second thread is still subscribed.
1819+ let maybe_status = self . load_thread_subscription ( room_id ( ) , second_thread) . await . unwrap ( ) ;
1820+ assert_eq ! ( maybe_status, Some ( ThreadStatus :: Subscribed { automatic: false } ) ) ;
1821+ }
17701822}
17711823
17721824/// Macro building to allow your StateStore implementation to run the entire
@@ -1937,6 +1989,12 @@ macro_rules! statestore_integration_tests {
19371989 let store = get_store( ) . await . expect( "creating store failed" ) . into_state_store( ) ;
19381990 store. test_get_room_infos( ) . await ;
19391991 }
1992+
1993+ #[ async_test]
1994+ async fn test_thread_subscriptions( ) {
1995+ let store = get_store( ) . await . expect( "creating store failed" ) . into_state_store( ) ;
1996+ store. test_thread_subscriptions( ) . await ;
1997+ }
19401998 }
19411999 } ;
19422000}
0 commit comments