Skip to content

Commit

Permalink
More comment addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelrobert committed Oct 29, 2024
1 parent 1c6683a commit 26b124f
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions applogic/src/api/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,37 +206,37 @@ pub(crate) fn group_messages(messages: Vec<ConversationMessage>) -> Vec<UiConver

while let Some(conversation_message) = iter.next() {
let mut timestamp = conversation_message.timestamp();
if let Message::Content(content_message) = conversation_message.message() {
let mut current_flight = vec![content_message.clone().into()];
let current_sender = content_message.sender().to_string();

// Keep collecting messages from the same sender
while let Some(next_message) = iter.peek() {
let temp_timestamp = next_message.timestamp();
if let Message::Content(next_content_message) = next_message.message() {
if next_content_message.sender() != current_sender {
break;
}
let next_content_message = next_content_message.clone();
// Consume the next message and add it to the current flight
let _ = iter.next();
timestamp = temp_timestamp;
current_flight.push(next_content_message.into());
} else {
break;
}
}

// Add the grouped messages to the result
grouped_messages.push(UiConversationMessage {
message: UiMessage::ContentFlight(current_flight),
timestamp: timestamp.to_rfc3339(),
..conversation_message.into()
});
} else {
let Message::Content(content_message) = conversation_message.message() else {
// Directly add non-content messages
grouped_messages.push(conversation_message.into());
continue;
};

let mut current_flight = vec![content_message.clone().into()];
let current_sender = content_message.sender().to_string();

// Keep collecting messages from the same sender
while let Some(next_message) = iter.peek() {
let temp_timestamp = next_message.timestamp();
let Message::Content(next_content_message) = next_message.message() else {
break;
};
if next_content_message.sender() != current_sender {
break;
}
let next_content_message = next_content_message.clone();
// Consume the next message and add it to the current flight
let _ = iter.next();
timestamp = temp_timestamp;
current_flight.push(next_content_message.into());
}

// Add the grouped messages to the result
grouped_messages.push(UiConversationMessage {
message: UiMessage::ContentFlight(current_flight),
timestamp: timestamp.to_rfc3339(),
..conversation_message.into()
});
}

grouped_messages
Expand Down

0 comments on commit 26b124f

Please sign in to comment.