Skip to content

Commit 8e198b0

Browse files
committed
group messages after sending
1 parent 69573ef commit 8e198b0

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

applogic/src/api/message_cubit.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<S: Store + Send + Sync + 'static> MessageContext<S> {
135135

136136
async fn load_and_emit_state(&self) {
137137
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");
139139
match conversation_message {
140140
Ok(cm) => {
141141
self.state_tx
@@ -168,13 +168,39 @@ impl<S: Store + Send + Sync + 'static> MessageContext<S> {
168168
}
169169

170170
async fn process_store_notification(&self, notification: &StoreNotification) {
171-
// TODO: Handle updated of the neighbors
172171
match notification.ops.get(&self.message_id.into()) {
173172
Some(StoreOperation::Add | StoreOperation::Update) => self.load_and_emit_state().await,
174173
Some(StoreOperation::Remove) => {
175174
self.state_tx.send_modify(|state| state.message = None);
176175
}
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+
}
178204
}
179205
}
180206
}

0 commit comments

Comments
 (0)