Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(call): send connection gateway message on channel creation/end (#2415)

Will Hutchinson27a9849cdc88
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 0554411826..b8b1654b86 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -1726,6 +1726,7 @@ dependencies = [
"anyhow",
"axum",
"chrono",
+ "connection",
"entity_access",
"livekit-api",
"livekit-protocol",
@@ -1736,6 +1737,7 @@ dependencies = [
"model_user",
"models_permissions",
"serde",
+ "serde_json",
"sqlx",
"thiserror 2.0.17",
"tokio",
diff --git a/rust/cloud-storage/ai_tools/src/tool_context.rs b/rust/cloud-storage/ai_tools/src/tool_context.rs
index f565d707e0..7a2eecd75f 100644
--- a/rust/cloud-storage/ai_tools/src/tool_context.rs
+++ b/rust/cloud-storage/ai_tools/src/tool_context.rs
@@ -78,6 +78,16 @@ impl ConnectionService for NoOpConnectionService {
) -> Result<(), connection::domain::models::ConnectionError> {
Ok(())
}
+
+ async fn send_channel_message(
+ &self,
+ _channel_id: &str,
+ _message_type: &str,
+ _message: serde_json::Value,
+ _triggered_by: connection::domain::models::EntityAccessAuth,
+ ) -> Result<(), connection::domain::models::ConnectionError> {
+ Ok(())
+ }
}
/// Type alias for the document service implementation used by AI tools
diff --git a/rust/cloud-storage/call/Cargo.toml b/rust/cloud-storage/call/Cargo.toml
index 45e3357c22..9bd48ec5bd 100644
--- a/rust/cloud-storage/call/Cargo.toml
+++ b/rust/cloud-storage/call/Cargo.toml
@@ -26,6 +26,9 @@ ports = ["dep:tokio"]
[dependencies]
anyhow = { workspace = true }
+connection = { path = "../connection", default-features = false, features = [
+ "ports",
+] }
axum = { workspace = true, optional = true }
chrono = { workspace = true }
entity_access = { path = "../entity_access", optional = true, default-features = false, features = [
@@ -38,6 +41,7 @@ model-error-response = { path = "../model-error-response", optional = true }
model_user = { path = "../model_user", optional = true, features = ["axum"] }
models_permissions = { path = "../models_permissions", optional = true }
serde = { workspace = true }
+serde_json = { workspace = true }
sqlx = { workspace = true, optional = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["macros"], optional = true }
diff --git a/rust/cloud-storage/call/src/domain/service.rs b/rust/cloud-storage/call/src/domain/service.rs
index 7dd11929b8..b8ac568de5 100644
--- a/rust/cloud-storage/call/src/domain/service.rs
+++ b/rust/cloud-storage/call/src/domain/service.rs
@@ -1,5 +1,7 @@
//! Call service implementation.
+use connection::domain::models::EntityAccessAuth;
+use connection::domain::ports::ConnectionService;
use uuid::Uuid;
use super::models::{
@@ -8,20 +10,27 @@ use super::models::{
use super::ports::{CallRepository, CallRtcClient, CallService};
/// The concrete call service implementation.
-pub struct CallServiceImpl<R: CallRepository, C: CallRtcClient> {
+pub struct CallServiceImpl<R: CallRepository, C: CallRtcClient, Cn: ConnectionService> {
repo: R,
rtc_client: C,
+ connection_service: Cn,
server_url: String,
egress_s3_config: Option<EgressS3Config>,
internal_call_secret: Option<String>,
}
-impl<R: CallRepository, C: CallRtcClient> CallServiceImpl<R, C> {
+impl<R: CallRepository, C: CallRtcClient, Cn: ConnectionService> CallServiceImpl<R, C, Cn> {
/// Create a new call service.
- pub fn new(repo: R, rtc_client: C, server_url: impl Into<String>) -> Self {
+ pub fn new(
+ repo: R,
+ rtc_client: C,
+ connection_service: Cn,
+ server_url: impl Into<String>,
+ ) -> Self {
Self {
repo,
rtc_client,
+ connection_service,
server_url: server_url.into(),
egress_s3_config: None,
internal_call_secret: None,
@@ -39,9 +48,40 @@ impl<R: CallRepository, C: CallRtcClient> CallServiceImpl<R, C> {
self.internal_call_secret = Some(secret);
self
}
+
+ /// Send a call event to all channel members (best-effort).
+ async fn send_call_event(
+ &self,
+ channel_id: &Uuid,
+ message_type: &str,
+ message: &serde_json::Value,
+ triggered_by_user_id: Option<&str>,
+ ) {
+ let triggered_by = match triggered_by_user_id {
+ Some(uid) => uid
+ .to_string()
+ .try_into()
+ .map(EntityAccessAuth::Authenticated)
+ .unwrap_or(EntityAccessAuth::Internal),
+ None => EntityAccessAuth::Internal,
+ };
+
+ let _ = self
+ .connection_service
+ .send_channel_message(
+ &channel_id.to_string(),
+ message_type,
+ message.clone(),
+ triggered_by,
+ )
+ .await
+ .inspect_err(|e| tracing::error!(error=?e, message_type, "failed to send call event"));
+ }
}
-impl<R: CallRepository, C: CallRtcClient> CallService for CallServiceImpl<R, C> {
+impl<R: CallRepository, C: CallRtcClient, Cn: ConnectionService> CallService
+ for CallServiceImpl<R, C, Cn>
+{
fn validate_internal_call(&self, token: &str) -> bool {
self.internal_call_secret
.as_deref()
@@ -108,6 +148,19 @@ impl<R: CallRepository, C: CallRtcClient> CallService for CallServiceImpl<R, C>
}
}
+ // Notify channel members about the new call (best-effort).
+ self.send_call_event(
+ channel_id,
+ "call_started",
+ &serde_json::json!({
+ "channel_id": channel_id,
+ "call_id": call.id,
+ "created_by": user_id,
+ }),
+ Some(user_id),
+ )
+ .await;
+
call
}
None => {
@@ -206,10 +259,22 @@ impl<R: CallRepository, C: CallRtcClient> CallService for CallServiceImpl<R, C>
.map_err(|e| CallError::Internal(e.into()))?
{
tracing::info!(call_id = %call.id, room_name, "archiving call on room_finished");
+ let channel_id = call.channel_id;
self.repo
.archive_call(&call.id)
.await
.map_err(|e| CallError::Internal(e.into()))?;
+
+ self.send_call_event(
+ &channel_id,
+ "call_ended",
+ &serde_json::json!({
+ "channel_id": channel_id,
+ "call_id": call.id,
+ }),
+ None,
+ )
+ .await;
}
}
"participant_joined" => {
@@ -277,6 +342,7 @@ impl<R: CallRepository, C: CallRtcClient> CallService for CallServiceImpl<R, C>
if remaining == 0 {
tracing::info!(call_id = %call.id, room_name, "last participant left, archiving call");
+ let channel_id = call.channel_id;
self.repo
.archive_call(&call.id)
.await
@@ -287,6 +353,17 @@ impl<R: CallRepository, C: CallRtcClient> CallService for CallServiceImpl<R, C>
.await
.inspect_err(|e| tracing::error!(error=?e, "failed to delete RTC room"))
.ok();
+
+ self.send_call_event(
+ &channel_id,
+ "call_ended",
+ &serde_json::json!({
+ "channel_id": channel_id,
+ "call_id": call.id,
+ }),
+ None,
+ )
+ .await;
}
}
"egress_started" | "egress_updated" => {
diff --git a/rust/cloud-storage/connection/src/domain/models.rs b/rust/cloud-storage/connection/src/domain/models.rs
index 8778ed789f..fb39c71d1a 100644
--- a/rust/cloud-storage/connection/src/domain/models.rs
+++ b/rust/cloud-storage/connection/src/domain/models.rs
@@ -2,7 +2,7 @@
use std::borrow::Cow;
-use entity_access::domain::models::{EntityAccessAuth, EntityType};
+pub use entity_access::domain::models::{EntityAccessAuth, EntityType};
/// The invalidation message type
pub const INVALIDATION_MESSAGE_TYPE: &str = "invalidation";
diff --git a/rust/cloud-storage/connection/src/domain/ports.rs b/rust/cloud-storage/connection/src/domain/ports.rs
index 9bff03c90f..744690eb38 100644
--- a/rust/cloud-storage/connection/src/domain/ports.rs
+++ b/rust/cloud-storage/connection/src/domain/ports.rs
@@ -5,6 +5,7 @@
use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
use crate::domain::models::{ConnectionError, InvalidationEvent};
+use entity_access::domain::models::EntityAccessAuth;
/// Repository for handling github oauth related actions.
pub trait ConnectionGateway: Send + Sync + 'static {
@@ -17,6 +18,14 @@ pub trait ConnectionGateway: Send + Sync + 'static {
users: &[MacroUserId<Lowercase<'a>>],
invalidation_event: InvalidationEvent<'a, T>,
) -> impl Future<Output = Result<(), Self::Err>> + Send;
+
+ /// Sends an arbitrary message to a list of users.
+ fn batch_send_message<'a>(
+ &self,
+ users: &[MacroUserId<Lowercase<'a>>],
+ message_type: &str,
+ message: serde_json::Value,
+ ) -> impl Future<Output = Result<(), Self::Err>> + Send;
}
/// Service interface for connection operations
@@ -26,4 +35,16 @@ pub trait ConnectionService: Send + Sync + 'static {
&self,
invalidation_event: InvalidationEvent<'a, T>,
) -> impl Future<Output = Result<(), ConnectionError>> + Send;
+
+ /// Sends an arbitrary message to all users in a channel.
+ ///
+ /// Resolves channel members internally, filters out the triggering user,
+ /// and sends via the connection gateway.
+ fn send_channel_message(
+ &self,
+ channel_id: &str,
+ message_type: &str,
+ message: serde_json::Value,
+ triggered_by: EntityAccessAuth,
+ ) -> impl Future<Output = Result<(), ConnectionError>> + Send;
}
diff --git a/rust/cloud-storage/connection/src/domain/service.rs b/rust/cloud-storage/connection/src/domain/service.rs
index fabded4ebe..ccd9837123 100644
--- a/rust/cloud-storage/connection/src/domain/service.rs
+++ b/rust/cloud-storage/connection/src/domain/service.rs
@@ -5,6 +5,8 @@ use std::sync::Arc;
use entity_access::domain::ports::EntityAccessService;
use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
+use entity_access::domain::models::EntityType;
+
use crate::domain::{
models::{ConnectionError, InvalidationEvent},
ports::{ConnectionGateway, ConnectionService},
@@ -78,4 +80,50 @@ impl<E: EntityAccessService, Cgw: ConnectionGateway> ConnectionService
Ok(())
}
+
+ #[tracing::instrument(skip(self), err)]
+ async fn send_channel_message(
+ &self,
+ channel_id: &str,
+ message_type: &str,
+ message: serde_json::Value,
+ triggered_by: entity_access::domain::models::EntityAccessAuth,
+ ) -> Result<(), ConnectionError> {
+ let users = self
+ .entity_access_service
+ .get_users_by_entity(channel_id, EntityType::Channel)
+ .await
+ .map_err(|e| ConnectionError::Internal(e.into()))?;
+
+ let users = match &triggered_by {
+ entity_access::domain::models::EntityAccessAuth::Authenticated(macro_user_id_str) => {
+ users
+ .into_iter()
+ .filter_map(|p| {
+ if p.as_ref() != macro_user_id_str.as_ref() {
+ Some(p.0)
+ } else {
+ None
+ }
+ })
+ .collect::<Vec<MacroUserId<Lowercase<'_>>>>()
+ }
+ entity_access::domain::models::EntityAccessAuth::Unauthenticated
+ | entity_access::domain::models::EntityAccessAuth::Internal => {
+ users.into_iter().map(|s| s.0.to_owned()).collect()
+ }
+ };
+
+ if users.is_empty() {
+ tracing::trace!("no users to send channel message to");
+ return Ok(());
+ }
+
+ self.connection_gateway
+ .batch_send_message(&users, message_type, message)
+ .await
+ .map_err(|e| ConnectionError::Internal(e.into()))?;
+
+ Ok(())
+ }
}
diff --git a/rust/cloud-storage/connection/src/outbound/connection_gateway_client.rs b/rust/cloud-storage/connection/src/outbound/connection_gateway_client.rs
index 82a960487d..3bdaeabfc7 100644
--- a/rust/cloud-storage/connection/src/outbound/connection_gateway_client.rs
+++ b/rust/cloud-storage/connection/src/outbound/connection_gateway_client.rs
@@ -47,4 +47,26 @@ impl ConnectionGateway for ConnectionGatewayImpl {
Ok(())
}
+
+ #[tracing::instrument(skip(self), err)]
+ async fn batch_send_message<'a>(
+ &self,
+ users: &[MacroUserId<Lowercase<'a>>],
+ message_type: &str,
+ message: serde_json::Value,
+ ) -> Result<(), Self::Err> {
+ let entities = users
+ .iter()
+ .map(|u| model_entity::EntityType::User.with_entity_str(u.as_ref()))
+ .collect();
+
+ let result = self
+ .client
+ .batch_send_message(message_type.to_string(), message, entities)
+ .await?;
+
+ tracing::trace!(result=?result, "batch send message");
+
+ Ok(())
+ }
}
diff --git a/rust/cloud-storage/document_storage_service/src/api/context.rs b/rust/cloud-storage/document_storage_service/src/api/context.rs
index 5c404cab11..d665049434 100644
--- a/rust/cloud-storage/document_storage_service/src/api/context.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/context.rs
@@ -158,8 +158,13 @@ pub(crate) type CommsState = CommsRouterState<CommsChannelService>;
pub(crate) type DssChannelsState =
ChannelsRouterState<ChannelMessagesServiceImpl<PgChannelMessagesRepo>, EntityAccessService>;
+/// Type alias for the call connection service.
+pub(crate) type CallConnectionService =
+ ConnectionServiceImpl<EntityAccessService, ConnectionGatewayImpl>;
+
/// Type alias for the call service.
-pub(crate) type DssCallService = CallServiceImpl<PgCallRepo, LivekitRtcClient>;
+pub(crate) type DssCallService =
+ CallServiceImpl<PgCallRepo, LivekitRtcClient, CallConnectionService>;
/// Type alias for the call router state.
pub(crate) type DssCallState = CallRouterState<DssCallService, EntityAccessService>;
diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rs
index 79cd7c0f3b..b4a36bb552 100644
--- a/rust/cloud-storage/document_storage_service/src/main.rs
+++ b/rust/cloud-storage/document_storage_service/src/main.rs
@@ -313,10 +313,10 @@ async fn main() -> anyhow::Result<()> {
config.vars.docx_document_upload_bucket.as_ref(),
);
- let connection_service = ConnectionServiceImpl::new(
- entity_access_service.clone(),
- Arc::new(ConnectionGatewayImpl::new(conn_gateway_client.clone())),
- );
+ let connection_gateway = Arc::new(ConnectionGatewayImpl::new(conn_gateway_client.clone()));
+
+ let connection_service =
+ ConnectionServiceImpl::new(entity_access_service.clone(), connection_gateway.clone());
let document_service = Arc::new(DocumentServiceImpl::new(
document_repo,
@@ -365,10 +365,13 @@ async fn main() -> anyhow::Result<()> {
config.vars.livekit_api_secret.as_ref(),
transcription_agent_name,
);
+ let call_connection_service =
+ ConnectionServiceImpl::new(entity_access_service.clone(), connection_gateway.clone());
let call_repo = PgCallRepo::new(db.clone());
let mut call_service_builder = CallServiceImpl::new(
call_repo,
livekit_rtc_client,
+ call_connection_service,
config.vars.livekit_server_url.as_ref(),
);
if let Some(secret) = internal_call_secret {
diff --git a/rust/cloud-storage/documents/examples/documents_toolset.rs b/rust/cloud-storage/documents/examples/documents_toolset.rs
index ffec378d01..df119bd1d7 100644
--- a/rust/cloud-storage/documents/examples/documents_toolset.rs
+++ b/rust/cloud-storage/documents/examples/documents_toolset.rs
@@ -47,6 +47,16 @@ impl ConnectionService for NoOpConnectionService {
) -> Result<(), connection::domain::models::ConnectionError> {
Ok(())
}
+
+ async fn send_channel_message(
+ &self,
+ _channel_id: &str,
+ _message_type: &str,
+ _message: serde_json::Value,
+ _triggered_by: connection::domain::models::EntityAccessAuth,
+ ) -> Result<(), connection::domain::models::ConnectionError> {
+ Ok(())
+ }
}
/// No-op task properties service (not needed for toolset example).
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json b/rust/cloud-storage/entity_access/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
new file mode 100644
index 0000000000..a110bb67c6
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT cp.user_id\n FROM comms_channel_participants cp\n WHERE cp.channel_id = $1 AND cp.left_at IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8"
+}
diff --git a/rust/cloud-storage/entity_access/src/domain/ports.rs b/rust/cloud-storage/entity_access/src/domain/ports.rs
index 2919a33a08..f7d939abaa 100644
--- a/rust/cloud-storage/entity_access/src/domain/ports.rs
+++ b/rust/cloud-storage/entity_access/src/domain/ports.rs
@@ -110,6 +110,12 @@ pub trait AccessRepository: Clone + Send + Sync + 'static {
thread_id: &str,
) -> impl Future<Output = Result<Vec<MacroUserIdStr<'static>>, AccessError>> + Send;
+ /// Get all active participant user IDs in a channel.
+ fn get_channel_users(
+ &self,
+ channel_id: &Uuid,
+ ) -> impl Future<Output = Result<Vec<MacroUserIdStr<'static>>, AccessError>> + Send;
+
/// Resolve a call ID to its channel ID and share permission ID.
///
/// Checks both the `calls` table (active calls) and the `call_records` table
@@ -192,14 +198,12 @@ pub trait EntityAccessService: Clone + Send + Sync + 'static {
user_org_id: Option<i64>,
) -> impl Future<Output = Result<EntityPermission, AccessError>> + Send;
- /// Get all user IDs that have access to a given entity via `UserItemAccess`.
- ///
- /// Returns user IDs with direct access to the entity or inherited access
- /// through the project hierarchy. Only considers `UserItemAccess` grants,
- /// not public share permissions.
+ /// Get all user IDs that have access to a given entity.
///
- /// Supported entity types: Document, Chat, Project, EmailThread.
- /// Returns `AccessError::BadRequest` for unsupported types (Channel, Team, User).
+ /// For Document, Chat, Project, and EmailThread: returns user IDs with direct
+ /// access or inherited access through the project hierarchy via `UserItemAccess`.
+ /// For Channel: returns active channel participants.
+ /// Returns `AccessError::BadRequest` for unsupported types (Team, User).
fn get_users_by_entity(
&self,
entity_id: &str,
diff --git a/rust/cloud-storage/entity_access/src/domain/service.rs b/rust/cloud-storage/entity_access/src/domain/service.rs
index 8025e51865..97de4d272a 100644
--- a/rust/cloud-storage/entity_access/src/domain/service.rs
+++ b/rust/cloud-storage/entity_access/src/domain/service.rs
@@ -214,8 +214,14 @@ where
EntityType::Chat => self.repo.get_chat_users(entity_id).await,
EntityType::Project => self.repo.get_project_users(entity_id).await,
EntityType::EmailThread => self.repo.get_thread_users(entity_id).await,
+ EntityType::Channel => {
+ let channel_id = Uuid::parse_str(entity_id).map_err(|_| {
+ AccessError::BadRequest("invalid channel_id for get_users_by_entity")
+ })?;
+ self.repo.get_channel_users(&channel_id).await
+ }
_ => Err(AccessError::BadRequest(
- "get_users_by_entity only supports Document, Chat, Project, and EmailThread",
+ "get_users_by_entity does not support this entity type",
)),
}
}
diff --git a/rust/cloud-storage/entity_access/src/domain/service/test.rs b/rust/cloud-storage/entity_access/src/domain/service/test.rs
index c0127fc24d..74644b5464 100644
--- a/rust/cloud-storage/entity_access/src/domain/service/test.rs
+++ b/rust/cloud-storage/entity_access/src/domain/service/test.rs
@@ -23,6 +23,7 @@ struct MockRepo {
chat_users: Arc<Mutex<Vec<MacroUserIdStr<'static>>>>,
project_users: Arc<Mutex<Vec<MacroUserIdStr<'static>>>>,
thread_users: Arc<Mutex<Vec<MacroUserIdStr<'static>>>>,
+ channel_users: Arc<Mutex<Vec<MacroUserIdStr<'static>>>>,
call_channel: Arc<Mutex<Option<CallChannelInfo>>>,
}
@@ -39,6 +40,7 @@ impl MockRepo {
chat_users: Arc::new(Mutex::new(vec![])),
project_users: Arc::new(Mutex::new(vec![])),
thread_users: Arc::new(Mutex::new(vec![])),
+ channel_users: Arc::new(Mutex::new(vec![])),
call_channel: Arc::new(Mutex::new(None)),
}
}
@@ -172,6 +174,13 @@ impl AccessRepository for MockRepo {
Ok(self.thread_users.lock().await.clone())
}
+ async fn get_channel_users(
+ &self,
+ _channel_id: &Uuid,
+ ) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
+ Ok(self.channel_users.lock().await.clone())
+ }
+
async fn get_call_channel(
&self,
_call_id: &Uuid,
@@ -1032,7 +1041,7 @@ async fn test_get_users_by_entity_thread_returns_empty_when_no_users() {
}
#[tokio::test]
-async fn test_get_users_by_entity_channel_returns_bad_request() {
+async fn test_get_users_by_entity_channel_returns_users() {
let repo = MockRepo::new();
let service = EntityAccessServiceImpl::new(repo);
@@ -1040,7 +1049,8 @@ async fn test_get_users_by_entity_channel_returns_bad_request() {
.get_users_by_entity("11111111-1111-1111-1111-111111111111", EntityType::Channel)
.await;
- assert!(matches!(result, Err(AccessError::BadRequest(_))));
+ assert!(result.is_ok());
+ assert!(result.unwrap().is_empty());
}
#[tokio::test]
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/mod.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/mod.rs
index 8e42d63b3c..2813ee71b8 100644
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/mod.rs
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/mod.rs
@@ -138,6 +138,15 @@ impl AccessRepository for PgAccessRepository {
Ok(parse_user_ids(raw))
}
+ #[tracing::instrument(err, skip(self))]
+ async fn get_channel_users(
+ &self,
+ channel_id: &Uuid,
+ ) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
+ let raw = queries::channel_users::get_channel_users(&self.pool, channel_id).await?;
+ Ok(parse_user_ids(raw))
+ }
+
#[tracing::instrument(err, skip(self))]
async fn get_call_channel(
&self,
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs
new file mode 100644
index 0000000000..88fad7b790
--- /dev/null
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs
@@ -0,0 +1,24 @@
+//! Query for users in a channel via comms_channel_participants.
+
+use sqlx::PgPool;
+use uuid::Uuid;
+
+/// Get all user IDs that are active participants in a channel.
+#[tracing::instrument(err, skip(pool))]
+pub async fn get_channel_users(
+ pool: &PgPool,
+ channel_id: &Uuid,
+) -> Result<Vec<String>, sqlx::Error> {
+ let users: Vec<String> = sqlx::query_scalar!(
+ r#"
+ SELECT DISTINCT cp.user_id
+ FROM comms_channel_participants cp
+ WHERE cp.channel_id = $1 AND cp.left_at IS NULL
+ "#,
+ channel_id
+ )
+ .fetch_all(pool)
+ .await?;
+
+ Ok(users)
+}
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/mod.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/mod.rs
index e22060b488..caa2cf31fd 100644
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/mod.rs
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/mod.rs
@@ -5,6 +5,7 @@
pub mod call_channel;
pub mod channel_membership;
pub mod channel_role;
+pub mod channel_users;
pub mod chat_access;
pub mod chat_users;
pub mod document_access;