diff options
Diffstat (limited to 'makima/src/server/handlers/mesh_supervisor.rs')
| -rw-r--r-- | makima/src/server/handlers/mesh_supervisor.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/makima/src/server/handlers/mesh_supervisor.rs b/makima/src/server/handlers/mesh_supervisor.rs index b45dda5..3fc7dd7 100644 --- a/makima/src/server/handlers/mesh_supervisor.rs +++ b/makima/src/server/handlers/mesh_supervisor.rs @@ -1839,9 +1839,14 @@ pub async fn rewind_conversation( // Determine how many messages to keep let new_count = if let Some(by_count) = req.by_message_count { (original_count - by_count).max(0) - } else if let Some(to_index) = req.to_message_index { - // Keep messages up to and including the specified index - (to_index + 1).min(original_count).max(0) + } else if let Some(ref to_id) = req.to_message_id { + // Find message by ID and keep up to and including it + let index = conversation + .iter() + .position(|msg| msg.get("id").and_then(|v| v.as_str()) == Some(to_id.as_str())) + .map(|i| i as i32) + .unwrap_or(original_count - 1); + (index + 1).min(original_count).max(0) } else { // Default to removing last message (original_count - 1).max(0) |
