From 037b8de3faab9cfe0c068a3448739d1e94db266d Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Thu, 19 Dec 2024 11:48:00 -0500 Subject: [PATCH] update the query --- .../storage/encrypted_store/group_message.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/xmtp_mls/src/storage/encrypted_store/group_message.rs b/xmtp_mls/src/storage/encrypted_store/group_message.rs index d60983b10..a88077321 100644 --- a/xmtp_mls/src/storage/encrypted_store/group_message.rs +++ b/xmtp_mls/src/storage/encrypted_store/group_message.rs @@ -10,7 +10,10 @@ use serde::{Deserialize, Serialize}; use super::{ db_connection::DbConnection, - schema::group_messages::{self, dsl}, + schema::{ + group_messages::{self, dsl}, + groups::dsl as groups_dsl, + }, Sqlite, }; use crate::{impl_fetch, impl_store, impl_store_or_ignore, StorageError}; @@ -132,7 +135,20 @@ impl DbConnection { args: &MsgQueryArgs, ) -> Result, StorageError> { let mut query = dsl::group_messages - .filter(dsl::group_id.eq(group_id)) + .filter( + dsl::group_id.eq_any( + groups_dsl::groups + .filter( + groups_dsl::id.eq(group_id).or(groups_dsl::dm_id.eq_any( + groups_dsl::groups + .select(groups_dsl::dm_id) + .filter(groups_dsl::id.eq(group_id)) + .into_boxed(), + )), + ) + .select(groups_dsl::id), + ), + ) .into_boxed(); if let Some(sent_after) = args.sent_after_ns {