Private
Public Access
1
0

daemon: maintain outgoing message reference so model is consistent

This commit is contained in:
2025-05-03 21:45:53 -07:00
parent 0d61b6f2d7
commit d843127c6d
8 changed files with 124 additions and 35 deletions

View File

@@ -2,7 +2,7 @@ use diesel::prelude::*;
use chrono::NaiveDateTime;
use crate::models::{Message, Participant};
#[derive(Queryable, Selectable, Insertable, AsChangeset, Clone, Identifiable)]
#[derive(Queryable, Selectable, Insertable, AsChangeset, Clone, Identifiable, Debug)]
#[diesel(table_name = crate::schema::messages)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct Record {

View File

@@ -1,6 +1,7 @@
use chrono::{DateTime, NaiveDateTime};
use uuid::Uuid;
use crate::models::participant::Participant;
use kordophone::model::outgoing_message::OutgoingMessage;
#[derive(Clone, Debug)]
pub struct Message {
@@ -40,6 +41,17 @@ impl From<kordophone::model::Message> for Message {
}
}
impl From<&OutgoingMessage> for Message {
fn from(value: &OutgoingMessage) -> Self {
Self {
id: value.guid.to_string(),
sender: Participant::Me,
text: value.text.clone(),
date: value.date,
}
}
}
pub struct MessageBuilder {
id: Option<String>,
sender: Option<Participant>,

View File

@@ -246,6 +246,7 @@ impl<'a> Repository<'a> {
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 {
log::debug!("Updating conversation metadata: {} message: {:?}", conversation_guid, last_message);
conversation.date = last_message.date;
conversation.last_message_preview = Some(last_message.text.clone());
self.insert_conversation(conversation)?;

View File

@@ -54,7 +54,7 @@ async fn test_add_conversation() {
repository.insert_conversation(modified_conversation.clone()).unwrap();
// Make sure we still only have one conversation.
let all_conversations = repository.all_conversations().unwrap();
let all_conversations = repository.all_conversations(i32::MAX, 0).unwrap();
assert_eq!(all_conversations.len(), 1);
// And make sure the display name was updated
@@ -125,7 +125,7 @@ async fn test_all_conversations_with_participants() {
repository.insert_conversation(conversation2).unwrap();
// Get all conversations and verify the results
let all_conversations = repository.all_conversations().unwrap();
let all_conversations = repository.all_conversations(i32::MAX, 0).unwrap();
assert_eq!(all_conversations.len(), 2);
// Find and verify each conversation's participants