Private
Public Access
1
0

chatdatabase: implements all_conversations with participant zippering

This commit is contained in:
2024-12-21 16:34:47 -08:00
parent f79cbbbc85
commit c4c6e4245d
2 changed files with 53 additions and 6 deletions

View File

@@ -86,14 +86,23 @@ impl ChatDatabase {
pub fn all_conversations(&mut self) -> Result<Vec<Conversation>> {
use crate::schema::conversations::dsl::*;
use crate::schema::participants::dsl::*;
let result = conversations
.load::<DbConversation>(&mut self.db)?
.into_iter()
.map(|c| c.into())
.collect();
let db_conversations = conversations
.load::<DbConversation>(&mut self.db)?;
// TODO: Need to resolve participants here also somehow...
let mut result = Vec::new();
for db_conversation in db_conversations {
let db_participants = ConversationParticipant::belonging_to(&db_conversation)
.inner_join(participants)
.select(DbParticipant::as_select())
.load::<DbParticipant>(&mut self.db)?;
let mut model_conversation: Conversation = db_conversation.into();
model_conversation.participants = db_participants.into_iter().map(|p| p.into()).collect();
result.push(model_conversation);
}
Ok(result)
}