Skip to content

Commit

Permalink
group messages after sending
Browse files Browse the repository at this point in the history
  • Loading branch information
boxdot committed Jan 7, 2025
1 parent 69573ef commit 8e198b0
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions applogic/src/api/message_cubit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<S: Store + Send + Sync + 'static> MessageContext<S> {

async fn load_and_emit_state(&self) {
let conversation_message = self.store.message_with_neighbors(self.message_id).await;
debug!(?conversation_message, "load_and_emit_state");
tracing::info!(?conversation_message, "load_and_emit_state");
match conversation_message {
Ok(cm) => {
self.state_tx
Expand Down Expand Up @@ -168,13 +168,39 @@ impl<S: Store + Send + Sync + 'static> MessageContext<S> {
}

async fn process_store_notification(&self, notification: &StoreNotification) {
// TODO: Handle updated of the neighbors
match notification.ops.get(&self.message_id.into()) {
Some(StoreOperation::Add | StoreOperation::Update) => self.load_and_emit_state().await,
Some(StoreOperation::Remove) => {
self.state_tx.send_modify(|state| state.message = None);
}
None => (),
None => {
// reload on added message when there is no next neighbor
// TODO: We could better short-circuit this logic, if we knew the conversation id
// of the added message.
let has_next_neighbor = self
.state_tx
.borrow()
.message
.as_ref()
.map(|message| message.neighbors.next.is_some())
.unwrap_or(true);
let message_id = self.message_id.to_uuid();
tracing::info!(has_next_neighbor, %message_id, ?notification, "has_next_neighbor");
if !has_next_neighbor {
for item in notification.ops.iter() {
// TODO: There is a bug, where Update of the message overrides the Add
// operation. To mititage this, we check also for the Update operation.
if let (
StoreEntityId::Message(_),
StoreOperation::Add | StoreOperation::Update,
) = item
{
self.load_and_emit_state().await;
return;
}
}
}
}
}
}
}

0 comments on commit 8e198b0

Please sign in to comment.