@@ -135,7 +135,7 @@ impl<S: Store + Send + Sync + 'static> MessageContext<S> {
135
135
136
136
async fn load_and_emit_state ( & self ) {
137
137
let conversation_message = self . store . message_with_neighbors ( self . message_id ) . await ;
138
- debug ! ( ?conversation_message, "load_and_emit_state" ) ;
138
+ tracing :: info !( ?conversation_message, "load_and_emit_state" ) ;
139
139
match conversation_message {
140
140
Ok ( cm) => {
141
141
self . state_tx
@@ -168,13 +168,39 @@ impl<S: Store + Send + Sync + 'static> MessageContext<S> {
168
168
}
169
169
170
170
async fn process_store_notification ( & self , notification : & StoreNotification ) {
171
- // TODO: Handle updated of the neighbors
172
171
match notification. ops . get ( & self . message_id . into ( ) ) {
173
172
Some ( StoreOperation :: Add | StoreOperation :: Update ) => self . load_and_emit_state ( ) . await ,
174
173
Some ( StoreOperation :: Remove ) => {
175
174
self . state_tx . send_modify ( |state| state. message = None ) ;
176
175
}
177
- None => ( ) ,
176
+ None => {
177
+ // reload on added message when there is no next neighbor
178
+ // TODO: We could better short-circuit this logic, if we knew the conversation id
179
+ // of the added message.
180
+ let has_next_neighbor = self
181
+ . state_tx
182
+ . borrow ( )
183
+ . message
184
+ . as_ref ( )
185
+ . map ( |message| message. neighbors . next . is_some ( ) )
186
+ . unwrap_or ( true ) ;
187
+ let message_id = self . message_id . to_uuid ( ) ;
188
+ tracing:: info!( has_next_neighbor, %message_id, ?notification, "has_next_neighbor" ) ;
189
+ if !has_next_neighbor {
190
+ for item in notification. ops . iter ( ) {
191
+ // TODO: There is a bug, where Update of the message overrides the Add
192
+ // operation. To mititage this, we check also for the Update operation.
193
+ if let (
194
+ StoreEntityId :: Message ( _) ,
195
+ StoreOperation :: Add | StoreOperation :: Update ,
196
+ ) = item
197
+ {
198
+ self . load_and_emit_state ( ) . await ;
199
+ return ;
200
+ }
201
+ }
202
+ }
203
+ }
178
204
}
179
205
}
180
206
}
0 commit comments