Private
Public Access
1
0

daemon: incorporate update monitor in daemon activities

This commit is contained in:
2025-05-01 20:36:43 -07:00
parent 1c2f09e81b
commit 2314713bb4
8 changed files with 196 additions and 5 deletions

View File

@@ -127,6 +127,9 @@ impl<'a> Repository<'a> {
))
.execute(self.connection)?;
// Update conversation date
self.update_conversation_metadata(conversation_guid, &db_message)?;
Ok(())
}
@@ -174,6 +177,9 @@ impl<'a> Repository<'a> {
.values(&conv_msg_records)
.execute(self.connection)?;
// Update conversation date
self.update_conversation_metadata(conversation_guid, &db_messages.last().unwrap())?;
Ok(())
}
@@ -234,6 +240,17 @@ impl<'a> Repository<'a> {
Ok(())
}
fn update_conversation_metadata(&mut self, conversation_guid: &str, last_message: &MessageRecord) -> Result<()> {
let conversation = self.get_conversation_by_guid(conversation_guid)?;
if let Some(mut conversation) = conversation {
conversation.date = last_message.date;
conversation.last_message_preview = Some(last_message.text.clone());
self.insert_conversation(conversation)?;
}
Ok(())
}
// Helper function to get the last inserted row ID
// This is a workaround since the Sqlite backend doesn't support `RETURNING`
// Huge caveat with this is that it depends on whatever the last insert was, prevents concurrent inserts.