Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(soup): comms filter 2 (#948)
Sean Aye9ea7faa43863
diff --git a/rust/cloud-storage/comms/src/domain/models.rs b/rust/cloud-storage/comms/src/domain/models.rsindex 98b85f9987..4cd5fe5362 100644--- a/rust/cloud-storage/comms/src/domain/models.rs+++ b/rust/cloud-storage/comms/src/domain/models.rs@@ -38,8 +38,41 @@ impl UserName {}}+#[derive(Debug)]pub struct GetChannelsRequest {pub macro_id: MacroUserIdStr<'static>,pub limit: Option<u32>,pub query: Query<Uuid, SimpleSortMethod, LiteralTree<ChannelLiteral>>,}++impl GetChannelsRequest {+ pub fn into_params(self) -> GetChannelsParams {+ let GetChannelsRequest {+ macro_id,+ limit,+ query,+ } = self;++ // make sure the limit for page size exists within a reasonable range+ let limit = limit.unwrap_or(20).clamp(20, 100);++ GetChannelsParams {+ macro_id,+ limit,+ query,+ }+ }+}++#[expect(dead_code, reason = "This is used in a later PR")]+pub struct GetChannelsParams {+ macro_id: MacroUserIdStr<'static>,+ limit: u32,+ query: Query<Uuid, SimpleSortMethod, LiteralTree<ChannelLiteral>>,+}++impl GetChannelsParams {+ pub fn user(&self) -> &MacroUserIdStr<'static> {+ &self.macro_id+ }+}diff --git a/rust/cloud-storage/comms/src/domain/ports.rs b/rust/cloud-storage/comms/src/domain/ports.rsindex a46cfb7276..47602b0c41 100644--- a/rust/cloud-storage/comms/src/domain/ports.rs+++ b/rust/cloud-storage/comms/src/domain/ports.rs@@ -6,12 +6,12 @@ use models_comms::channel::{};use rootcause::Report;-use crate::domain::models::UserName;+use crate::domain::models::{GetChannelsParams, GetChannelsRequest, UserName};pub trait CommsRepo: Send + Sync + 'static {fn get_user_channels_with_participants(&self,- user_id: MacroUserIdStr<'_>,+ req: GetChannelsParams,) -> impl Future<Output = Result<Vec<ChannelWithParticipants>, Report>> + Send;fn get_latest_channel_messages_batch(@@ -35,7 +35,7 @@ pub trait UserRepo: Send + Sync + 'static {pub trait ChannelsService: Send + Sync + 'static {fn get_channels(&self,- user: MacroUserIdStr<'_>,+ req: GetChannelsRequest,) -> impl Future<Output = Result<Vec<ChannelWithLatest>, Report>> + Send;fn get_activities(diff --git a/rust/cloud-storage/comms/src/domain/service.rs b/rust/cloud-storage/comms/src/domain/service.rsindex 9bb448dde7..1398355f53 100644--- a/rust/cloud-storage/comms/src/domain/service.rs+++ b/rust/cloud-storage/comms/src/domain/service.rs@@ -10,7 +10,7 @@ use models_comms::channel::{Activity, ChannelId, ChannelWithLatest};use uuid::Uuid;use crate::domain::{- models::channel_name::resolve_channel_name,+ models::{GetChannelsRequest, channel_name::resolve_channel_name},ports::{ChannelsService, CommsRepo, UserRepo},};@@ -44,11 +44,14 @@ where#[tracing::instrument(err, skip(self))]async fn get_channels(&self,- user: macro_user_id::user_id::MacroUserIdStr<'_>,+ req: GetChannelsRequest,) -> Result<Vec<models_comms::channel::ChannelWithLatest>, rootcause::Report> {+ let params = req.into_params();+ let user = params.user().clone();+let channels = self.comms- .get_user_channels_with_participants(user.copied())+ .get_user_channels_with_participants(params).await?;let channel_entities: Vec<_> = channelsdiff --git a/rust/cloud-storage/comms/src/inbound.rs b/rust/cloud-storage/comms/src/inbound.rsindex c9ee16742e..4f6fd92213 100644--- a/rust/cloud-storage/comms/src/inbound.rs+++ b/rust/cloud-storage/comms/src/inbound.rs@@ -10,7 +10,7 @@ use thiserror::Error;use utoipa::ToSchema;use uuid::Uuid;-use crate::domain::ports::ChannelsService;+use crate::domain::{models::GetChannelsRequest, ports::ChannelsService};pub struct CommsRouterState<S> {pub inner: Arc<S>,@@ -73,7 +73,14 @@ async fn get_channels_handler<S: ChannelsService>() -> Result<Json<Vec<ApiChannelWithLatest>>, CommsErr> {let res = service.inner- .get_channels(macro_user_id)+ .get_channels(GetChannelsRequest {+ macro_id: macro_user_id,+ limit: None,+ query: models_pagination::Query::Sort(+ models_pagination::SimpleSortMethod::UpdatedAt,+ None,+ ),+ }).await.map_err(|_| CommsErr::Internal)?;diff --git a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rsindex 274a615c72..96fdc202bc 100644--- a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs+++ b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs@@ -1,3 +1,4 @@+use crate::domain::models::GetChannelsParams;use crate::domain::ports::CommsRepo;use chrono::DateTime;use chrono::Utc;@@ -318,9 +319,9 @@ pub struct PgCommsRepo {impl CommsRepo for PgCommsRepo {async fn get_user_channels_with_participants(&self,- user_id: MacroUserIdStr<'_>,+ req: GetChannelsParams,) -> Result<Vec<ChannelWithParticipants>, rootcause::Report> {- Ok(get_user_channels_with_participants(&self.pool, user_id.as_ref()).await?)+ Ok(get_user_channels_with_participants(&self.pool, req.user().as_ref()).await?)}async fn get_latest_channel_messages_batch(diff --git a/rust/cloud-storage/soup/src/domain/models.rs b/rust/cloud-storage/soup/src/domain/models.rsindex d629536553..04769a2801 100644--- a/rust/cloud-storage/soup/src/domain/models.rs+++ b/rust/cloud-storage/soup/src/domain/models.rs@@ -1,3 +1,4 @@+use comms::domain::models::GetChannelsRequest;use email::domain::models::{GetEmailsRequest, PreviewView};use frecency::domain::models::{AggregateFrecency, FrecencyQueryErr};use item_filters::ast::EntityFilterAst;@@ -146,6 +147,32 @@ impl SoupRequest {}?,})}++ pub(crate) fn build_comms_request(&self) -> Option<GetChannelsRequest> {+ Some(GetChannelsRequest {+ macro_id: self.user.clone(),+ limit: Some(self.limit as u32),+ query: match &self.cursor {+ SoupQuery::Simple(Query::Sort(t, f)) => Some(Query::Sort(+ *t,+ f.as_ref().and_then(|f| f.channel_filter.clone()),+ )),+ SoupQuery::Simple(Query::Cursor(CursorWithValAndFilter {+ id,+ limit,+ val,+ filter,+ })) => Some(Query::Cursor(CursorWithValAndFilter {+ id: *id,+ limit: *limit,+ val: val.clone(),+ filter: filter.as_ref().and_then(|f| f.channel_filter.clone()),+ })),+ // query by frecency not yet implemented for channels+ SoupQuery::Frecency(_) => None,+ }?,+ })+ }}/// a [SoupItem] with an associated frecency scorediff --git a/rust/cloud-storage/soup/src/domain/service.rs b/rust/cloud-storage/soup/src/domain/service.rsindex dd32ec3c50..0f0785bd1b 100644--- a/rust/cloud-storage/soup/src/domain/service.rs+++ b/rust/cloud-storage/soup/src/domain/service.rs@@ -5,7 +5,7 @@ use crate::domain::{},ports::{SoupOutput, SoupRepo, SoupService},};-use comms::domain::ports::ChannelsService;+use comms::domain::{models::GetChannelsRequest, ports::ChannelsService};use doppleganger::Mirror;use either::Either;use email::domain::{models::GetEmailsRequest, ports::EmailService};@@ -272,22 +272,28 @@ whereasync fn handle_comms_request(&self,- req: MacroUserIdStr<'_>,+ req: Option<GetChannelsRequest>,) -> Result<impl Iterator<Item = FrecencySoupItem>, SoupErr> {- self.comms_service- .get_channels(req)- .await- .map_err(|_| SoupErr::CommsErr)- .map(|r| {- r.into_iter().map(|mut c| {- let frecency_score = c.frecency_score.take();- let soup_channel = SoupChannel::mirror(c);- FrecencySoupItem {- item: SoupItem::Channel(soup_channel),- frecency_score,- }- })- })+ let Some(req) = req else {+ return Ok(Either::Left(None.into_iter()));+ };++ Ok(Either::Right(+ self.comms_service+ .get_channels(req)+ .await+ .map_err(|_| SoupErr::CommsErr)+ .map(|r| {+ r.into_iter().map(|mut c| {+ let frecency_score = c.frecency_score.take();+ let soup_channel = SoupChannel::mirror(c);+ FrecencySoupItem {+ item: SoupItem::Channel(soup_channel),+ frecency_score,+ }+ })+ })?,+ ))}}@@ -305,6 +311,7 @@ wherelet paginate_filter = req.cursor.filter().cloned();let email_request = req.build_email_request();+ let comms_request = req.build_comms_request();match req.cursor {SoupQuery::Simple(cursor) => {@@ -321,7 +328,7 @@ wherelet email_soup_fut = self.handle_email_request(email_request);- let comms_soup_fut = self.handle_comms_request(req.user.copied());+ let comms_soup_fut = self.handle_comms_request(comms_request);let (main_soup, email_soup, _comms_soup) =tokio::join!(main_soup_fut, email_soup_fut, comms_soup_fut);diff --git a/rust/cloud-storage/soup/src/domain/service/tests.rs b/rust/cloud-storage/soup/src/domain/service/tests.rsindex d2d79b3870..11cacfa2f3 100644--- a/rust/cloud-storage/soup/src/domain/service/tests.rs+++ b/rust/cloud-storage/soup/src/domain/service/tests.rs@@ -1,6 +1,7 @@use crate::domain::models::FrecencySoupItem;use crate::domain::ports::MockSoupRepo;use chrono::Days;+use comms::domain::models::GetChannelsRequest;use cool_asserts::assert_matches;use email::domain::models::{EmailErr, EnrichedEmailThreadPreview, PreviewView};use frecency::domain::models::{FrecencyPageRequest, FrecencyPageResponse};@@ -49,7 +50,7 @@ struct NoopCommsService;impl ChannelsService for NoopCommsService {async fn get_channels(&self,- _user: MacroUserIdStr<'_>,+ req: GetChannelsRequest,) -> Result<Vec<comms::domain::models::channel::ChannelWithLatest>, Report> {Ok(Vec::new())}