@@ -79,6 +79,72 @@ async fn test_subscribe_thread() {
79
79
assert_matches ! ( subscription, None ) ;
80
80
}
81
81
82
+ #[ async_test]
83
+ async fn test_subscribe_thread_if_needed ( ) {
84
+ let server = MatrixMockServer :: new ( ) . await ;
85
+ let client = server. client_builder ( ) . build ( ) . await ;
86
+
87
+ let room_id = room_id ! ( "!test:example.org" ) ;
88
+ let room = server. sync_joined_room ( & client, room_id) . await ;
89
+
90
+ // The function `subscribe_thread_if_needed` will automatically subscribe to the
91
+ // thread, if there's no prior manual subscription, whether the new
92
+ // subscription is automatic or not.
93
+ for ( root_id, automatic) in [
94
+ ( owned_event_id ! ( "$root" ) , None ) ,
95
+ ( owned_event_id ! ( "$woot" ) , Some ( owned_event_id ! ( "$woot" ) ) ) ,
96
+ ] {
97
+ server
98
+ . mock_put_thread_subscription ( )
99
+ . match_room_id ( room_id. to_owned ( ) )
100
+ . match_thread_id ( root_id. clone ( ) )
101
+ . ok ( )
102
+ . mock_once ( )
103
+ . mount ( )
104
+ . await ;
105
+
106
+ room. subscribe_thread_if_needed ( & root_id, automatic) . await . unwrap ( ) ;
107
+ }
108
+
109
+ // The function `subscribe_thread_if_needed` is a no-op, if there's a previous
110
+ // automatic subscription, whether the new subscription is automatic or not.
111
+ for ( root_id, automatic) in [
112
+ ( owned_event_id ! ( "$foot" ) , None ) ,
113
+ ( owned_event_id ! ( "$toot" ) , Some ( owned_event_id ! ( "$toot" ) ) ) ,
114
+ ] {
115
+ server
116
+ . mock_get_thread_subscription ( )
117
+ . match_room_id ( room_id. to_owned ( ) )
118
+ . match_thread_id ( root_id. clone ( ) )
119
+ . ok ( true )
120
+ . mock_once ( )
121
+ . mount ( )
122
+ . await ;
123
+
124
+ room. subscribe_thread_if_needed ( & root_id, automatic) . await . unwrap ( ) ;
125
+ }
126
+
127
+ // The function `subscribe_thread_if_needed` is a no-op if there's a prior
128
+ // manual subscription, whether the new subscription is automatic or not.
129
+ for ( root_id, automatic) in [
130
+ ( owned_event_id ! ( "$root" ) , None ) ,
131
+ ( owned_event_id ! ( "$woot" ) , Some ( owned_event_id ! ( "$woot" ) ) ) ,
132
+ ] {
133
+ server
134
+ . mock_get_thread_subscription ( )
135
+ . match_room_id ( room_id. to_owned ( ) )
136
+ . match_thread_id ( root_id. clone ( ) )
137
+ . ok ( false )
138
+ . mock_once ( )
139
+ . mount ( )
140
+ . await ;
141
+
142
+ // No-op! (The PUT endpoint hasn't been mocked, so this would result in a 404 if
143
+ // it were trying to hit it.)
144
+ room. subscribe_thread_if_needed ( & root_id, automatic) . await . unwrap ( ) ;
145
+ }
146
+ }
147
+
82
148
#[ async_test]
83
149
async fn test_thread_push_rule_is_triggered_for_subscribed_threads ( ) {
84
150
// This test checks that the evaluation of push rules for threads will correctly
0 commit comments