chatdatabase: implements all_conversations with participant zippering
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user