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.

chore remove comms service client (#1254)

Will Hutchinson7f8e130f98a5
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 27091e659d..65f046bc12 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -96,7 +96,6 @@ dependencies = [
"axum",
"chrono",
"comms",
- "comms_service_client",
"cool_asserts",
"email",
"email_service_client",
@@ -521,7 +520,7 @@ dependencies = [
"axum",
"base64 0.22.1",
"chrono",
- "comms_service_client",
+ "comms_db_client",
"cookie",
"cool_asserts",
"document_storage_service_client",
@@ -2492,7 +2491,7 @@ dependencies = [
"aws-sdk-sqs",
"axum",
"chrono",
- "comms_service_client",
+ "comms_db_client",
"futures",
"macro_aws_config",
"macro_cors",
@@ -5133,7 +5132,6 @@ name = "macro_project_utils"
version = "0.1.0"
dependencies = [
"anyhow",
- "comms_service_client",
"macro_db_client",
"macro_notify",
"model",
@@ -5176,7 +5174,6 @@ version = "0.1.0"
dependencies = [
"anyhow",
"comms_db_client",
- "comms_service_client",
"macro_db_client",
"macro_user_id",
"model",
@@ -7541,6 +7538,7 @@ dependencies = [
"base64 0.22.1",
"bytes",
"chrono",
+ "comms_db_client",
"comms_service_client",
"derive_builder",
"document_cognition_service_client",
@@ -7591,7 +7589,6 @@ dependencies = [
"axum",
"chrono",
"comms_db_client",
- "comms_service_client",
"email_db_client",
"email_service_client",
"futures",
diff --git a/rust/cloud-storage/ai_tools/Cargo.toml b/rust/cloud-storage/ai_tools/Cargo.toml
index 3aac7a7f25..792fa45bc9 100644
--- a/rust/cloud-storage/ai_tools/Cargo.toml
+++ b/rust/cloud-storage/ai_tools/Cargo.toml
@@ -12,7 +12,6 @@ async-trait.workspace = true
axum = { workspace = true, features = ["macros"] }
chrono.workspace = true
comms = { path = "../comms", features = ["outbound"] }
-comms_service_client = { path = "../comms_service_client" }
email = { path = "../email", features = ["ai_schema", "axum", "outbound"] }
email_service_client = { path = "../email_service_client" }
frecency = { path = "../frecency", features = ["outbound", "postgres"] }
diff --git a/rust/cloud-storage/authentication_service/Cargo.toml b/rust/cloud-storage/authentication_service/Cargo.toml
index c792f53391..ef36154448 100644
--- a/rust/cloud-storage/authentication_service/Cargo.toml
+++ b/rust/cloud-storage/authentication_service/Cargo.toml
@@ -41,7 +41,7 @@ aws-sdk-sqs = { workspace = true }
axum = { workspace = true, features = ["macros"] }
base64 = { workspace = true }
chrono = { workspace = true }
-comms_service_client = { path = "../comms_service_client" }
+comms_db_client = { path = "../comms_db_client" }
cookie = { workspace = true }
document_storage_service_client = { path = "../document_storage_service_client" }
doppleganger = { workspace = true }
@@ -119,4 +119,4 @@ uuid = { workspace = true }
cool_asserts = "2"
[package.metadata.cargo-machete]
-ignored = ["async-stripe", "comms_service"]
+ignored = ["async-stripe"]
diff --git a/rust/cloud-storage/authentication_service/src/api/context.rs b/rust/cloud-storage/authentication_service/src/api/context.rs
index 8f14bd78a1..92b2f8f09e 100644
--- a/rust/cloud-storage/authentication_service/src/api/context.rs
+++ b/rust/cloud-storage/authentication_service/src/api/context.rs
@@ -23,7 +23,6 @@ pub(crate) struct ApiContext {
pub auth_client: Arc<authentication_service::service::fusionauth_client::FusionAuthClient>,
pub macro_cache_client: Arc<MacroCache>,
pub stripe_client: Arc<stripe::Client>,
- pub comms_client: Arc<comms_service_client::CommsServiceClient>,
pub document_storage_service_client:
Arc<document_storage_service_client::DocumentStorageServiceClient>,
pub notification_service_client: Arc<notification_service_client::NotificationServiceClient>,
diff --git a/rust/cloud-storage/authentication_service/src/api/webhooks/user/create_user_webhook.rs b/rust/cloud-storage/authentication_service/src/api/webhooks/user/create_user_webhook.rs
index ddb2d14b02..05f74436e7 100644
--- a/rust/cloud-storage/authentication_service/src/api/webhooks/user/create_user_webhook.rs
+++ b/rust/cloud-storage/authentication_service/src/api/webhooks/user/create_user_webhook.rs
@@ -4,8 +4,14 @@ use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
+use comms_db_client::{
+ channels::get_channels::get_org_channels,
+ participants::add_participant::{AddParticipantOptions, add_participant},
+};
use macro_middleware::auth::internal_access::ValidInternalKey;
+use model::comms::ParticipantRole;
use rand::Rng;
+use sqlx::{Pool, Postgres};
use crate::api::context::ApiContext;
use authentication_service::service::{
@@ -170,14 +176,12 @@ async fn create_user_webhook(ctx: &ApiContext, req: FusionAuthUserWebhook) -> an
// If the user belongs to an organization,
// we should add them to the organization's channels
if let Some(org_id) = organization_id {
- let comms_client = ctx.comms_client.clone();
- tracing::trace!("dispatching request to comms service to add user to org channels");
+ let db = ctx.db.clone();
+ let user_id = user_id.clone();
+ tracing::trace!("adding user to org channels directly via db");
tokio::spawn(async move {
- if let Err(err) = comms_client
- .add_user_to_org_channels(&user_id, &(org_id as i64))
- .await
- {
- tracing::error!(error=?err, "failed to call comms service client to add user to org channels");
+ if let Err(err) = add_user_to_org_channels(&db, &user_id, org_id as i64).await {
+ tracing::error!(error=?err, "failed to add user to org channels");
}
});
}
@@ -258,3 +262,26 @@ async fn initialize_user_experiments(
Ok(())
}
+
+/// Adds a user to all organization channels
+async fn add_user_to_org_channels(
+ db: &Pool<Postgres>,
+ user_id: &str,
+ org_id: i64,
+) -> anyhow::Result<()> {
+ let org_channels = get_org_channels(db, &org_id).await?;
+
+ for channel in org_channels.iter() {
+ add_participant(
+ db,
+ AddParticipantOptions {
+ channel_id: &channel.id.0,
+ user_id,
+ participant_role: Some(ParticipantRole::Member),
+ },
+ )
+ .await?;
+ }
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/authentication_service/src/api/webhooks/user/delete_user_webhook.rs b/rust/cloud-storage/authentication_service/src/api/webhooks/user/delete_user_webhook.rs
index 14df99208c..6050677096 100644
--- a/rust/cloud-storage/authentication_service/src/api/webhooks/user/delete_user_webhook.rs
+++ b/rust/cloud-storage/authentication_service/src/api/webhooks/user/delete_user_webhook.rs
@@ -3,8 +3,13 @@ use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
+use comms_db_client::{
+ channels::get_channels::get_org_channels,
+ participants::remove_participant::{RemoveParticipantOptions, remove_participant},
+};
use macro_middleware::auth::internal_access::ValidInternalKey;
use model::{authentication::webhooks::FusionAuthUserWebhook, user::UserInfoWithMacroUserId};
+use sqlx::{Pool, Postgres};
use stripe::CustomerId;
use tracing::Instrument;
@@ -158,10 +163,10 @@ async fn delete_user(
.in_current_span(),
);
- // Send delete user call to comms service
+ // Remove user from organization channels
tokio::spawn(
{
- let comms_client = ctx.comms_client.clone();
+ let db = ctx.db.clone();
let user_infos = user_infos.clone();
async move {
for user_info in user_infos {
@@ -170,9 +175,8 @@ async fn delete_user(
// TODO: create delete user endpoint in comms service and handle removing this user and
// deleting all of their channels. Keep the messages for now.
if let Some(org_id) = user_info.organization_id
- && let Err(err) = comms_client
- .remove_user_from_org_channels(&user_id, &(org_id as i64))
- .await
+ && let Err(err) =
+ remove_user_from_org_channels(&db, &user_id, org_id as i64).await
{
tracing::error!(error=?err, "unable to remove user from org channels");
}
@@ -236,3 +240,25 @@ async fn delete_user(
Ok(())
}
+
+/// Removes a user from all organization channels
+async fn remove_user_from_org_channels(
+ db: &Pool<Postgres>,
+ user_id: &str,
+ org_id: i64,
+) -> anyhow::Result<()> {
+ let org_channels = get_org_channels(db, &org_id).await?;
+
+ for channel in org_channels.iter() {
+ remove_participant(
+ db,
+ RemoveParticipantOptions {
+ channel_id: &channel.id.0,
+ user_id,
+ },
+ )
+ .await?;
+ }
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/authentication_service/src/config.rs b/rust/cloud-storage/authentication_service/src/config.rs
index 658f828c2b..832bca3c15 100644
--- a/rust/cloud-storage/authentication_service/src/config.rs
+++ b/rust/cloud-storage/authentication_service/src/config.rs
@@ -47,9 +47,6 @@ pub struct Config {
/// The environment we are in
pub environment: Environment,
- /// The comms service url
- pub comms_service_url: String,
-
/// The internal auth key used by other services
pub service_internal_auth_key: String,
@@ -106,8 +103,6 @@ impl Config {
.context("should be valid port number")?;
let environment = Environment::new_or_prod();
- let comms_service_url =
- std::env::var("COMMS_SERVICE_URL").context("COMMS_SERVICE_URL must be provided")?;
let document_storage_service_url = std::env::var("DOCUMENT_STORAGE_SERVICE_URL")
.context("DOCUMENT_STORAGE_SERVICE_URL must be provided")?;
@@ -138,7 +133,6 @@ impl Config {
google_client_secret_key,
stripe_secret_key,
port,
- comms_service_url,
service_internal_auth_key,
document_storage_service_url,
notification_service_url,
diff --git a/rust/cloud-storage/authentication_service/src/main.rs b/rust/cloud-storage/authentication_service/src/main.rs
index ab4c63f570..e948f3f3ce 100644
--- a/rust/cloud-storage/authentication_service/src/main.rs
+++ b/rust/cloud-storage/authentication_service/src/main.rs
@@ -1,5 +1,4 @@
use anyhow::Context;
-use comms_service_client::CommsServiceClient;
use config::{Config, Environment};
use document_storage_service_client::DocumentStorageServiceClient;
use macro_auth::middleware::decode_jwt::JwtValidationArgs;
@@ -136,12 +135,6 @@ async fn main() -> anyhow::Result<()> {
);
tracing::trace!("initialized auth client");
- let comms_client = CommsServiceClient::new(
- config.service_internal_auth_key.clone(),
- config.comms_service_url.clone(),
- );
- tracing::trace!("initialized comms client");
-
let document_storage_service_client = DocumentStorageServiceClient::new(
config.service_internal_auth_key.clone(),
config.document_storage_service_url.clone(),
@@ -204,7 +197,6 @@ async fn main() -> anyhow::Result<()> {
auth_client: Arc::new(auth_client),
macro_cache_client: Arc::new(macro_cache_client),
stripe_client: Arc::new(stripe_client),
- comms_client: Arc::new(comms_client),
document_storage_service_client: Arc::new(document_storage_service_client),
notification_service_client: Arc::new(notification_service_client),
ses_client: Arc::new(ses_client),
diff --git a/rust/cloud-storage/comms_service/src/api/channels/get_channel_metadata.rs b/rust/cloud-storage/comms_service/src/api/channels/get_channel_metadata.rs
index fc947ada79..343b7b425f 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/get_channel_metadata.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/get_channel_metadata.rs
@@ -4,7 +4,7 @@ use crate::api::{
};
use anyhow::Result;
use axum::{
- extract::{Path, Query, State},
+ extract::State,
http::StatusCode,
response::{IntoResponse, Json, Response},
};
@@ -23,11 +23,6 @@ pub struct ChannelMetadataResponse {
pub channel_type: model::comms::ChannelType,
}
-#[derive(Deserialize, Debug)]
-pub struct UserIdQuery {
- pub user_id: MacroUserIdStr<'static>,
-}
-
#[tracing::instrument(skip(db))]
pub async fn get_channel_name_and_type(
db: &Pool<Postgres>,
@@ -118,30 +113,3 @@ pub async fn handler_external(
Ok((StatusCode::OK, Json(response)).into_response())
}
-
-/// Internal handler without authentication
-#[tracing::instrument(skip(ctx))]
-pub async fn handler_internal(
- State(ctx): State<AppState>,
- Path(channel_id): Path<models_comms::channel::ChannelId>,
- Query(query): Query<UserIdQuery>,
-) -> Result<Response, Response> {
- let (channel_name, channel_type) =
- get_channel_name_and_type(&ctx.db, &channel_id, query.user_id)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to get channel metadata");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "unable to get channel metadata",
- )
- .into_response()
- })?;
-
- let response = ChannelMetadataResponse {
- channel_name,
- channel_type,
- };
-
- Ok((StatusCode::OK, Json(response)).into_response())
-}
diff --git a/rust/cloud-storage/comms_service/src/api/channels/get_channel_transcript.rs b/rust/cloud-storage/comms_service/src/api/channels/get_channel_transcript.rs
index 0e3896027a..ed679151b4 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/get_channel_transcript.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/get_channel_transcript.rs
@@ -5,7 +5,7 @@ use crate::api::{
use ai_format::insight_context_log::InsightContextLog;
use ai_format::util::Indent;
use axum::{
- extract::{Path, Query, State},
+ extract::{Query, State},
http::StatusCode,
response::{IntoResponse, Json, Response},
};
@@ -88,26 +88,3 @@ pub async fn handler_external(
Ok((StatusCode::OK, Json(response)).into_response())
}
-
-/// Internal handler without authentication
-#[tracing::instrument(skip(ctx))]
-pub async fn handler_internal(
- State(ctx): State<AppState>,
- Path(channel_id): Path<Uuid>,
- Query(query): Query<GetChannelTranscriptQuery>,
-) -> Result<Response, Response> {
- let transcript = get_channel_transcript(&ctx.db, &channel_id, query.since, query.limit)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to get channel transcript");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "unable to get channel transcript",
- )
- .into_response()
- })?;
-
- let response = ChannelTranscriptResponse { transcript };
-
- Ok((StatusCode::OK, Json(response)).into_response())
-}
diff --git a/rust/cloud-storage/comms_service/src/api/context.rs b/rust/cloud-storage/comms_service/src/api/context.rs
index ab8be38656..5b839c6bba 100644
--- a/rust/cloud-storage/comms_service/src/api/context.rs
+++ b/rust/cloud-storage/comms_service/src/api/context.rs
@@ -8,7 +8,6 @@ use connection_gateway_client::client::ConnectionGatewayClient;
use frecency::outbound::postgres::FrecencyPgStorage;
use macro_auth::middleware::decode_jwt::JwtValidationArgs;
use macro_env_var::env_var;
-use macro_middleware::auth::internal_access::InternalApiSecretKey;
use secretsmanager_client::LocalOrRemoteSecret;
use sqlx::PgPool;
use std::sync::Arc;
@@ -21,7 +20,6 @@ env_var! {
#[derive(Clone, FromRef)]
pub struct AppState {
pub jwt_validation_args: JwtValidationArgs,
- pub internal_auth_key: LocalOrRemoteSecret<InternalApiSecretKey>,
pub db: PgPool,
pub connection_gateway_client: Arc<ConnectionGatewayClient>,
pub macro_notify_client: Arc<macro_notify::MacroNotify>,
diff --git a/rust/cloud-storage/comms_service/src/api/internal/add_user_to_org_channels.rs b/rust/cloud-storage/comms_service/src/api/internal/add_user_to_org_channels.rs
deleted file mode 100644
index 9fc08f3aa2..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/add_user_to_org_channels.rs
+++ /dev/null
@@ -1,46 +0,0 @@
-use axum::extract::{Json, State};
-use comms_db_client::{
- channels::get_channels::get_org_channels,
- participants::add_participant::{AddParticipantOptions, add_participant},
-};
-use model::comms::{AddUserToOrgChannelsRequest, ParticipantRole};
-use reqwest::StatusCode;
-
-use crate::api::context::AppState;
-
-#[tracing::instrument(skip(ctx))]
-pub async fn handler(
- State(ctx): State<AppState>,
- req: Json<AddUserToOrgChannelsRequest>,
-) -> Result<StatusCode, (StatusCode, String)> {
- tracing::trace!("adding user to org channels");
-
- let org_channels = get_org_channels(&ctx.db, &req.org_id).await.map_err(|e| {
- tracing::error!(error=?e, "unable to get org channels");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to get org channels".to_string(),
- )
- })?;
-
- for channel in org_channels.iter() {
- add_participant(
- &ctx.db,
- AddParticipantOptions {
- channel_id: &channel.id.0,
- user_id: &req.user_id,
- participant_role: Some(ParticipantRole::Member),
- },
- )
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to add user to org channel");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to add user to org channel".to_string(),
- )
- })?;
- }
-
- Ok(StatusCode::OK)
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/check_channels_for_user.rs b/rust/cloud-storage/comms_service/src/api/internal/check_channels_for_user.rs
deleted file mode 100644
index cbf643cb0d..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/check_channels_for_user.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-use axum::{
- extract::{self, State},
- http::StatusCode,
- response::{IntoResponse, Json, Response},
-};
-
-use crate::api::context::AppState;
-use model::comms::CheckChannelsForUserRequest;
-
-#[tracing::instrument(skip(ctx))]
-pub async fn handler(
- State(ctx): State<AppState>,
- req: extract::Json<CheckChannelsForUserRequest>,
-) -> Result<Response, Response> {
- tracing::trace!("checking channels for user");
-
- if req.channel_ids.is_empty() {
- return Err((StatusCode::BAD_REQUEST, "no channel ids").into_response());
- }
-
- let result = comms_db_client::channels::get_channels::check_channels_for_user(
- &ctx.db,
- &req.user_id,
- &req.channel_ids,
- )
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to check channels for user");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "unable to check channels for user",
- )
- .into_response()
- })?;
-
- Ok((StatusCode::OK, Json(result)).into_response())
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/create_welcome_message.rs b/rust/cloud-storage/comms_service/src/api/internal/create_welcome_message.rs
deleted file mode 100644
index 40ebf7a806..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/create_welcome_message.rs
+++ /dev/null
@@ -1,129 +0,0 @@
-use axum::{
- extract::{self, State},
- http::StatusCode,
- response::{IntoResponse, Json, Response},
-};
-use comms_db_client::{
- activity::upsert_activity::upsert_activity,
- channels::{
- create_channel::{CreateChannelOptions, create_channel},
- get_dm, updated_at,
- },
- messages::create_message,
- model::ActivityType,
-};
-use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
-use tracing::Instrument;
-
-use crate::{api::context::AppState, service::sender::notify};
-use model::{
- comms::{ChannelType, CreateWelcomeMessageRequest, GetOrCreateAction},
- response::EmptyResponse,
-};
-
-static WELCOME_MESSAGE: &str = "Welcome to Macro. If you have any questions, please reach out!";
-static SLEEP_TIME_SECONDS: u64 = 60;
-
-#[tracing::instrument(skip(app_state))]
-pub async fn handler(
- State(app_state): State<AppState>,
- req: extract::Json<CreateWelcomeMessageRequest>,
-) -> Result<Response, Response> {
- tracing::trace!("checking channels for user");
-
- tokio::spawn(
- {
- let ctx = app_state.clone();
- let welcome_user_id = req.welcome_user_id.clone();
- let to_user_id = req.to_user_id.clone();
- async move {
- if let Err(e) = create_welcome_message(&ctx, welcome_user_id, to_user_id).await {
- tracing::error!(error=?e, "unable to create welcome message");
- }
- }
- }
- .in_current_span(),
- );
-
- Ok((StatusCode::OK, Json(EmptyResponse::default())).into_response())
-}
-
-#[tracing::instrument(skip(ctx))]
-async fn create_welcome_message(
- ctx: &AppState,
- welcome_user_id: MacroUserIdStr<'_>,
- to_user_id: MacroUserIdStr<'_>,
-) -> anyhow::Result<()> {
- let content = WELCOME_MESSAGE.to_string();
- let sleep_time = SLEEP_TIME_SECONDS;
- let participants: Vec<_> = vec![welcome_user_id.copied(), to_user_id.copied()];
-
- tracing::trace!("sleeping welcome message");
- tokio::time::sleep(std::time::Duration::from_secs(sleep_time)).await;
-
- let maybe_dm =
- get_dm::maybe_get_dm(&ctx.db, welcome_user_id.as_ref(), to_user_id.as_ref()).await?;
-
- let (channel_id, action) = match maybe_dm {
- Some(private_id) => (private_id, GetOrCreateAction::Get),
- None => {
- let id = create_channel(
- &ctx.db,
- CreateChannelOptions {
- name: None,
- owner_id: welcome_user_id.to_string(),
- org_id: None,
- channel_type: ChannelType::DirectMessage,
- participants: participants.iter().map(|x| x.to_string()).collect(),
- },
- )
- .await?;
-
- (id, GetOrCreateAction::Create)
- }
- };
-
- if action == GetOrCreateAction::Get {
- tracing::debug!("dm already exists");
- return Ok(());
- }
-
- tracing::trace!("sending welcome message to dm");
- let mut connection = ctx.db.acquire().await?;
-
- let message = create_message::create_message(
- &mut *connection,
- create_message::CreateMessageOptions {
- channel_id,
- sender_id: welcome_user_id.to_string(),
- content: content.to_string(),
- thread_id: None,
- },
- )
- .await?;
-
- tracing::trace!("created welcome message to dm");
-
- updated_at::updated_at(&mut *connection, &message.channel_id)
- .await
- .inspect_err(|e| {
- tracing::error!(error=?e, "unable to update channel updated_at");
- })
- .ok();
-
- notify::notify_message(ctx, message.clone(), &participants).await?;
-
- upsert_activity(
- &ctx.db,
- welcome_user_id.as_ref(),
- &channel_id,
- &ActivityType::Interact,
- )
- .await
- .inspect_err(|err| {
- tracing::error!(error=?err, "unable to upsert activity for message");
- })
- .ok();
-
- Ok(())
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/delete_mentions_by_source.rs b/rust/cloud-storage/comms_service/src/api/internal/delete_mentions_by_source.rs
deleted file mode 100644
index 3fef1413dd..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/delete_mentions_by_source.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-use axum::{
- extract::State,
- response::{IntoResponse, Json, Response},
-};
-use model::response::EmptyResponse;
-use models_comms::mentions::DeleteMentionsRequest;
-use reqwest::StatusCode;
-use sqlx::PgPool;
-
-#[tracing::instrument(skip(db))]
-pub async fn handler(
- State(db): State<PgPool>,
- Json(req): Json<DeleteMentionsRequest>,
-) -> Result<Response, Response> {
- tracing::trace!(
- "deleting mentions with source_entity_ids {}",
- req.item_ids.join(",")
- );
-
- comms_db_client::entity_mentions::delete_entity_mentions_by_source(&db, req.item_ids)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to delete entity mentions by source");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to delete entity mentions by source".to_string(),
- )
- .into_response()
- })?;
-
- Ok((StatusCode::OK, Json(EmptyResponse::default())).into_response())
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/get_channel_mentions.rs b/rust/cloud-storage/comms_service/src/api/internal/get_channel_mentions.rs
deleted file mode 100644
index f9a585364e..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/get_channel_mentions.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-use axum::{
- extract::{Path, State},
- response::{IntoResponse, Json, Response},
-};
-use reqwest::StatusCode;
-use serde::Deserialize;
-
-use crate::api::context::AppState;
-
-#[derive(Deserialize)]
-pub struct Params {
- pub item_id: String,
- pub item_type: String,
-}
-
-#[tracing::instrument(skip(ctx))]
-pub async fn handler(
- State(ctx): State<AppState>,
- Path(Params { item_id, item_type }): Path<Params>,
-) -> Result<Response, Response> {
- tracing::trace!("getting channel mentions for item");
-
- let channel_ids =
- comms_db_client::mentions::get_channel_mentions_by_item(&ctx.db, &item_id, &item_type)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to get channel mentions");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to get channel mentions".to_string(),
- )
- .into_response()
- })?;
-
- Ok((StatusCode::OK, Json(channel_ids)).into_response())
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/get_channel_message.rs b/rust/cloud-storage/comms_service/src/api/internal/get_channel_message.rs
deleted file mode 100644
index 879c56556b..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/get_channel_message.rs
+++ /dev/null
@@ -1,47 +0,0 @@
-use axum::{
- extract::{Path, State},
- response::{IntoResponse, Json, Response},
-};
-use model::response::ErrorResponse;
-use reqwest::StatusCode;
-use serde::Deserialize;
-use uuid::Uuid;
-
-use crate::api::context::AppState;
-
-#[derive(Deserialize)]
-pub struct Params {
- pub channel_id: Uuid,
- pub message_id: Uuid,
-}
-
-#[tracing::instrument(skip(ctx))]
-pub async fn handler(
- State(ctx): State<AppState>,
- Path(Params {
- channel_id,
- message_id,
- }): Path<Params>,
-) -> Result<Response, Response> {
- tracing::info!("get_channel_message");
-
- let channel_message_response =
- comms_db_client::messages::get_channel_message::get_channel_message_by_id(
- &ctx.db,
- &channel_id,
- &message_id,
- )
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to get channel message");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: &e.to_string(),
- }),
- )
- .into_response()
- })?;
-
- Ok((StatusCode::OK, Json(channel_message_response)).into_response())
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/get_channel_participants.rs b/rust/cloud-storage/comms_service/src/api/internal/get_channel_participants.rs
deleted file mode 100644
index 6d4a9154bb..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/get_channel_participants.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-use crate::api::context::AppState;
-use axum::{
- extract::{Path, State},
- response::{IntoResponse, Json, Response},
-};
-use doppleganger::Mirror;
-use reqwest::StatusCode;
-use uuid::Uuid;
-
-#[derive(serde::Serialize, serde::Deserialize, Debug)]
-pub struct PathParams {
- pub channel_id: Uuid,
-}
-
-#[tracing::instrument(skip(ctx))]
-pub async fn handler(
- State(ctx): State<AppState>,
- Path(PathParams { channel_id }): Path<PathParams>,
-) -> Result<Response, Response> {
- tracing::trace!("getting participants for channel");
-
- let participants =
- comms_db_client::participants::get_participants::get_participants(&ctx.db, &channel_id)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to get channel participants");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to get channel participants".to_string(),
- )
- .into_response()
- })?;
-
- Ok((
- StatusCode::OK,
- Json(<Vec<model::comms::ChannelParticipant>>::mirror(
- participants,
- )),
- )
- .into_response())
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/get_channels_history.rs b/rust/cloud-storage/comms_service/src/api/internal/get_channels_history.rs
deleted file mode 100644
index 2f5bc46ae6..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/get_channels_history.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-use crate::api::context::AppState;
-use anyhow::Result;
-use axum::{Json, extract::State, http::StatusCode, response::IntoResponse};
-use comms_db_client::activity::get_activity::get_channel_history_info;
-use model::comms::{GetChannelsHistoryRequest, GetChannelsHistoryResponse};
-use thiserror::Error;
-
-#[derive(Debug, Error)]
-pub enum GetChannelsHistoryError {
- #[error(transparent)]
- Sqlx(#[from] sqlx::Error),
-}
-
-impl IntoResponse for GetChannelsHistoryError {
- fn into_response(self) -> axum::response::Response {
- let status = match &self {
- GetChannelsHistoryError::Sqlx(_) => StatusCode::INTERNAL_SERVER_ERROR,
- };
- (status, self.to_string()).into_response()
- }
-}
-
-/// get channel information for use in search responses
-pub async fn handler(
- State(app_state): State<AppState>,
- Json(req): Json<GetChannelsHistoryRequest>,
-) -> Result<Json<GetChannelsHistoryResponse>, GetChannelsHistoryError> {
- let channels_history =
- get_channel_history_info(&app_state.db, &req.user_id, &req.channel_ids).await?;
-
- Ok(Json(GetChannelsHistoryResponse { channels_history }))
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/get_user_channel_ids.rs b/rust/cloud-storage/comms_service/src/api/internal/get_user_channel_ids.rs
deleted file mode 100644
index 1e6ac575a5..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/get_user_channel_ids.rs
+++ /dev/null
@@ -1,47 +0,0 @@
-use axum::{
- extract::{Path, Query, State},
- response::{IntoResponse, Json, Response},
-};
-use model::response::ErrorResponse;
-use reqwest::StatusCode;
-use serde::Deserialize;
-
-use crate::api::context::AppState;
-
-#[derive(Deserialize)]
-pub struct Params {
- pub user_id: String,
-}
-
-#[derive(Deserialize, Debug)]
-pub struct QueryParams {
- pub org_id: Option<i64>,
-}
-
-#[tracing::instrument(skip(ctx))]
-pub async fn handler(
- State(ctx): State<AppState>,
- Path(Params { user_id }): Path<Params>,
- Query(params): Query<QueryParams>,
-) -> Result<Response, Response> {
- tracing::info!("get_user_channel_ids");
-
- let user_channel_ids = comms_db_client::channels::get_channels::get_user_channel_ids(
- &ctx.db,
- &user_id,
- params.org_id,
- )
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to get user channel ids");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: &e.to_string(),
- }),
- )
- .into_response()
- })?;
-
- Ok((StatusCode::OK, Json(user_channel_ids)).into_response())
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/mod.rs b/rust/cloud-storage/comms_service/src/api/internal/mod.rs
deleted file mode 100644
index 171de8841d..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/mod.rs
+++ /dev/null
@@ -1,73 +0,0 @@
-pub mod add_user_to_org_channels;
-use axum::middleware::from_fn_with_state;
-use axum::routing::{delete, get, post};
-pub mod check_channels_for_user;
-mod create_welcome_message;
-mod delete_mentions_by_source;
-pub mod get_channel_mentions;
-mod get_channel_message;
-mod get_channel_participants;
-mod get_channels_history;
-mod get_user_channel_ids;
-pub mod remove_user_from_org_channels;
-
-use crate::api::context::AppState;
-use crate::api::middleware;
-use axum::Router;
-use macro_axum_utils::compose_layers;
-use macro_middleware::auth;
-
-pub fn router(app_state: AppState) -> Router<AppState> {
- Router::new()
- .route(
- "/add_user_to_org_channels",
- post(add_user_to_org_channels::handler),
- )
- .route(
- "/remove_user_from_org_channels",
- post(remove_user_from_org_channels::handler),
- )
- .route(
- "/check_channels_for_user",
- post(check_channels_for_user::handler),
- )
- .route(
- "/get_channel_mentions/:item_id/:item_type",
- get(get_channel_mentions::handler),
- )
- .route(
- "/get_channel_participants/:channel_id",
- get(get_channel_participants::handler),
- )
- .route(
- "/create_welcome_message",
- post(create_welcome_message::handler),
- )
- .route("/get_channels_history", post(get_channels_history::handler))
- .route(
- "/channel/:channel_id/:message_id",
- get(get_channel_message::handler),
- )
- .route(
- "/user_channels/:user_id",
- get(get_user_channel_ids::handler),
- )
- .route(
- "/get_channel_metadata/:channel_id",
- get(crate::api::channels::get_channel_metadata::handler_internal),
- )
- .route(
- "/get_channel_transcript/:channel_id",
- get(crate::api::channels::get_channel_transcript::handler_internal),
- )
- .route(
- "/delete_mentions_by_source",
- delete(delete_mentions_by_source::handler),
- )
- .route("/health", get(async move || "healthy"))
- .layer(compose_layers![
- from_fn_with_state(app_state.clone(), auth::internal_access::handler),
- from_fn_with_state(app_state.clone(), middleware::connection_drop_prevention,),
- ])
- .with_state(app_state)
-}
diff --git a/rust/cloud-storage/comms_service/src/api/internal/remove_user_from_org_channels.rs b/rust/cloud-storage/comms_service/src/api/internal/remove_user_from_org_channels.rs
deleted file mode 100644
index b4cf90d837..0000000000
--- a/rust/cloud-storage/comms_service/src/api/internal/remove_user_from_org_channels.rs
+++ /dev/null
@@ -1,46 +0,0 @@
-use axum::extract::{Json, State};
-use comms_db_client::{
- channels::get_channels::get_org_channels,
- participants::remove_participant::{RemoveParticipantOptions, remove_participant},
-};
-
-use model::comms::RemoveUserFromOrgChannelsRequest;
-use reqwest::StatusCode;
-
-use crate::api::context::AppState;
-
-#[tracing::instrument(skip(ctx))]
-pub async fn handler(
- State(ctx): State<AppState>,
- req: Json<RemoveUserFromOrgChannelsRequest>,
-) -> Result<StatusCode, (StatusCode, String)> {
- tracing::trace!("removing user from organization channels");
-
- let org_channels = get_org_channels(&ctx.db, &req.org_id).await.map_err(|e| {
- tracing::error!(error=?e, "unable to get org channels");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to get org channels".to_string(),
- )
- })?;
-
- for channel in org_channels.iter() {
- remove_participant(
- &ctx.db,
- RemoveParticipantOptions {
- channel_id: &channel.id.0,
- user_id: &req.user_id,
- },
- )
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to remove user from org channel");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to remove user from org channel".to_string(),
- )
- })?;
- }
-
- Ok(StatusCode::OK)
-}
diff --git a/rust/cloud-storage/comms_service/src/api/middleware/mod.rs b/rust/cloud-storage/comms_service/src/api/middleware/mod.rs
index 0bd803c0ab..4e5af0b475 100644
--- a/rust/cloud-storage/comms_service/src/api/middleware/mod.rs
+++ b/rust/cloud-storage/comms_service/src/api/middleware/mod.rs
@@ -1,9 +1,6 @@
mod permissions_token;
mod renamed_middleware {
- pub use macro_middleware::{
- auth::decode_jwt::handler as decode_jwt,
- connection_drop_prevention_handler as connection_drop_prevention,
- };
+ pub use macro_middleware::auth::decode_jwt::handler as decode_jwt;
}
pub use permissions_token::*;
pub use renamed_middleware::*;
diff --git a/rust/cloud-storage/comms_service/src/api/mod.rs b/rust/cloud-storage/comms_service/src/api/mod.rs
index a6c4f3f14e..6d1eeb6fdb 100644
--- a/rust/cloud-storage/comms_service/src/api/mod.rs
+++ b/rust/cloud-storage/comms_service/src/api/mod.rs
@@ -14,7 +14,6 @@ mod channels;
pub mod context;
mod extractors;
mod health;
-mod internal;
mod mentions;
mod middleware;
mod preview;
@@ -36,7 +35,6 @@ pub fn service(app_state: AppState) -> Service {
app_state.jwt_validation_args.clone(),
middleware::decode_jwt,
))
- .nest("/internal", internal::router(app_state.clone()))
.with_state(app_state)
.merge(health::router().layer(cors.clone()))
.merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", swagger::ApiDoc::openapi()))
diff --git a/rust/cloud-storage/comms_service/src/main.rs b/rust/cloud-storage/comms_service/src/main.rs
index d531c5bfbb..ea1562a565 100644
--- a/rust/cloud-storage/comms_service/src/main.rs
+++ b/rust/cloud-storage/comms_service/src/main.rs
@@ -124,10 +124,6 @@ async fn main() -> anyhow::Result<()> {
let service = api::service(AppState {
jwt_validation_args,
- internal_auth_key: secretsmanager_client::LocalOrRemoteSecret::Local(
- config.internal_auth_key.clone(),
- ),
-
db,
sqs_client: Arc::new(sqs_client),
macro_notify_client: Arc::new(macro_notify_client),
diff --git a/rust/cloud-storage/comms_service_client/src/channel_message.rs b/rust/cloud-storage/comms_service_client/src/channel_message.rs
deleted file mode 100644
index e4be077297..0000000000
--- a/rust/cloud-storage/comms_service_client/src/channel_message.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-use model::comms::GetChannelMessageResponse;
-
-use super::CommsServiceClient;
-use crate::error::{ClientError, ResponseExt};
-
-impl CommsServiceClient {
- #[tracing::instrument(skip(self))]
- pub async fn get_channel_message(
- &self,
- channel_id: &str,
- message_id: &str,
- ) -> Result<GetChannelMessageResponse, ClientError> {
- let response = self
- .client
- .get(format!(
- "{}/internal/channel/{}/{}",
- self.url, channel_id, message_id
- ))
- .send()
- .await
- .map_client_error()
- .await?;
-
- let result = response
- .json::<GetChannelMessageResponse>()
- .await
- .map_err(|e| {
- ClientError::Generic(anyhow::anyhow!(
- "unable to parse response from get_channel_message: {}",
- e.to_string()
- ))
- })?;
-
- Ok(result)
- }
-}
diff --git a/rust/cloud-storage/comms_service_client/src/channels.rs b/rust/cloud-storage/comms_service_client/src/channels.rs
index 3cbc9084a7..d9947cd25d 100644
--- a/rust/cloud-storage/comms_service_client/src/channels.rs
+++ b/rust/cloud-storage/comms_service_client/src/channels.rs
@@ -1,9 +1,6 @@
use super::CommsServiceClient;
use crate::error::{ClientError, ResponseExt};
-use model::comms::{
- ChannelMessage, ChannelParticipant, ChannelType, GetChannelsHistoryRequest,
- GetChannelsHistoryResponse,
-};
+use model::comms::{ChannelMessage, ChannelParticipant, ChannelType};
use models_comms::channel::{ChannelId, OrganizationId};
use serde::{Deserialize, Serialize};
use urlencoding;
@@ -52,8 +49,6 @@ pub struct ApiChannelWithLatest {
}
impl CommsServiceClient {
- // External routes - require JWT authentication and perform permission checks
-
/// Get all channels the user has access to using external authenticated endpoint
#[tracing::instrument(skip(self, jwt_token), err)]
pub async fn get_channels_external(
@@ -158,105 +153,4 @@ impl CommsServiceClient {
Ok(result)
}
-
- // Internal routes - no authentication, used for service-to-service communication
-
- /// Get channel metadata using internal endpoint
- #[tracing::instrument(skip(self))]
- pub async fn get_channel_metadata_internal(
- &self,
- channel_id: &Uuid,
- user_id: Option<&str>,
- ) -> Result<ChannelMetadataResponse, ClientError> {
- let mut url = format!("{}/internal/get_channel_metadata/{}", self.url, channel_id);
- if let Some(user_id) = user_id {
- url = format!("{}?user_id={}", url, urlencoding::encode(user_id));
- }
- let response = self.client.get(url).send().await.map_client_error().await?;
-
- let result = response
- .json::<ChannelMetadataResponse>()
- .await
- .map_err(|e| {
- ClientError::Generic(anyhow::anyhow!(
- "unable to parse response from get_channel_metadata_internal: {}",
- e.to_string()
- ))
- })?;
-
- Ok(result)
- }
-
- /// Get channel transcript using internal endpoint
- #[tracing::instrument(skip(self))]
- pub async fn get_channel_transcript_internal(
- &self,
- channel_id: &Uuid,
- since: Option<chrono::DateTime<chrono::Utc>>,
- limit: Option<i64>,
- ) -> Result<ChannelTranscriptResponse, ClientError> {
- let mut url = format!(
- "{}/internal/get_channel_transcript/{}",
- self.url, channel_id
- );
- let mut query_params = vec![];
- if let Some(since) = since {
- query_params.push(format!(
- "since={}",
- urlencoding::encode(&since.to_rfc3339())
- ));
- }
- if let Some(limit) = limit {
- query_params.push(format!("limit={}", limit));
- }
- if !query_params.is_empty() {
- url = format!("{}?{}", url, query_params.join("&"));
- }
- let response = self
- .client
- .get(&url)
- .send()
- .await
- .map_client_error()
- .await?;
-
- let result = response
- .json::<ChannelTranscriptResponse>()
- .await
- .map_err(|e| {
- ClientError::Generic(anyhow::anyhow!(
- "unable to parse response from get_channel_transcript_internal: {}",
- e.to_string()
- ))
- })?;
-
- Ok(result)
- }
-
- #[tracing::instrument(skip(self))]
- pub async fn get_channels_history(
- &self,
- request: GetChannelsHistoryRequest,
- ) -> Result<GetChannelsHistoryResponse, ClientError> {
- let response = self
- .client
- .post(format!("{}/internal/get_channels_history", self.url))
- .json(&request)
- .send()
- .await
- .map_client_error()
- .await?;
-
- let result = response
- .json::<GetChannelsHistoryResponse>()
- .await
- .map_err(|e| {
- ClientError::Generic(anyhow::anyhow!(
- "unable to parse response from get_channels_history: {}",
- e.to_string()
- ))
- })?;
-
- Ok(result)
- }
}
diff --git a/rust/cloud-storage/comms_service_client/src/constants.rs b/rust/cloud-storage/comms_service_client/src/constants.rs
deleted file mode 100644
index 7493559310..0000000000
--- a/rust/cloud-storage/comms_service_client/src/constants.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub const MACRO_INTERNAL_AUTH_KEY_HEADER_KEY: &str = "x-internal-auth-key";
diff --git a/rust/cloud-storage/comms_service_client/src/create_welcome_message.rs b/rust/cloud-storage/comms_service_client/src/create_welcome_message.rs
deleted file mode 100644
index b6cce9e5c2..0000000000
--- a/rust/cloud-storage/comms_service_client/src/create_welcome_message.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-use crate::error::{ClientError, ResponseExt};
-use model::comms::CreateWelcomeMessageRequest;
-
-use super::CommsServiceClient;
-
-impl CommsServiceClient {
- #[tracing::instrument(skip(self))]
- pub async fn create_welcome_message(
- &self,
- request: CreateWelcomeMessageRequest,
- ) -> Result<(), ClientError> {
- self.client
- .post(format!("{}/internal/create_welcome_message", self.url))
- .json(&request)
- .send()
- .await
- .map_client_error()
- .await?;
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/comms_service_client/src/lib.rs b/rust/cloud-storage/comms_service_client/src/lib.rs
index f167da2567..f02094e0d9 100644
--- a/rust/cloud-storage/comms_service_client/src/lib.rs
+++ b/rust/cloud-storage/comms_service_client/src/lib.rs
@@ -1,15 +1,6 @@
-use constants::MACRO_INTERNAL_AUTH_KEY_HEADER_KEY;
-
-pub mod channel_message;
pub mod channels;
-pub(crate) mod constants;
-pub mod create_welcome_message;
pub mod error;
-pub mod mentions;
pub mod messages;
-pub mod organization;
-pub mod participants;
-pub mod permissions;
#[derive(Clone)]
pub struct CommsServiceClient {
@@ -18,18 +9,14 @@ pub struct CommsServiceClient {
}
impl CommsServiceClient {
- pub fn new(internal_auth_key: String, url: String) -> Self {
- let mut headers = reqwest::header::HeaderMap::new();
- headers.insert(
- MACRO_INTERNAL_AUTH_KEY_HEADER_KEY,
- internal_auth_key.parse().unwrap(),
- );
-
- let client = reqwest::Client::builder()
- .default_headers(headers)
- .build()
- .unwrap();
+ pub fn new(url: String) -> Self {
+ let client = reqwest::Client::builder().build().unwrap();
Self { url, client }
}
+
+ /// Returns the base URL of the comms service
+ pub fn url(&self) -> &str {
+ &self.url
+ }
}
diff --git a/rust/cloud-storage/comms_service_client/src/mentions.rs b/rust/cloud-storage/comms_service_client/src/mentions.rs
deleted file mode 100644
index 4973c8842a..0000000000
--- a/rust/cloud-storage/comms_service_client/src/mentions.rs
+++ /dev/null
@@ -1,52 +0,0 @@
-use super::CommsServiceClient;
-use crate::error::{ClientError, ResponseExt};
-use models_comms::mentions::DeleteMentionsRequest;
-
-impl CommsServiceClient {
- /// Given an item id and item type, this will return all channel ids that mention the item
- #[tracing::instrument(skip(self))]
- pub async fn get_channel_mentions(
- &self,
- item_id: &str,
- item_type: &str,
- ) -> Result<Vec<String>, ClientError> {
- let response = self
- .client
- .get(format!(
- "{}/internal/get_channel_mentions/{}/{}",
- self.url, item_id, item_type
- ))
- .send()
- .await
- .map_client_error()
- .await?;
-
- let result = response.json::<Vec<String>>().await.map_err(|e| {
- ClientError::Generic(anyhow::anyhow!(
- "unable to parse response from get_channel_mentions: {}",
- e.to_string()
- ))
- })?;
-
- Ok(result)
- }
-
- /// Delete entity mentions by source. Used when we delete the source item
- #[tracing::instrument(skip(self))]
- pub async fn delete_mentions_by_source(
- &self,
- item_ids: Vec<String>,
- ) -> Result<(), ClientError> {
- let req = DeleteMentionsRequest { item_ids };
-
- self.client
- .delete(format!("{}/internal/delete_mentions_by_source", self.url))
- .json(&req)
- .send()
- .await
- .map_client_error()
- .await?;
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/comms_service_client/src/organization.rs b/rust/cloud-storage/comms_service_client/src/organization.rs
deleted file mode 100644
index 184672a5f3..0000000000
--- a/rust/cloud-storage/comms_service_client/src/organization.rs
+++ /dev/null
@@ -1,55 +0,0 @@
-use crate::error::{ClientError, ResponseExt};
-use model::comms::{AddUserToOrgChannelsRequest, RemoveUserFromOrgChannelsRequest};
-
-use super::CommsServiceClient;
-
-impl CommsServiceClient {
- #[tracing::instrument(skip(self))]
- pub async fn add_user_to_org_channels(
- &self,
- user_id: &str,
- org_id: &i64,
- ) -> Result<(), ClientError> {
- let body = serde_json::to_value(AddUserToOrgChannelsRequest {
- user_id: user_id.to_string(),
- org_id: *org_id,
- })
- .map_err(|e| ClientError::Generic(anyhow::anyhow!(e.to_string())))?;
-
- self.client
- .post(format!("{}/internal/add_user_to_org_channels", self.url))
- .json(&body)
- .send()
- .await
- .map_client_error()
- .await?;
-
- Ok(())
- }
-
- #[tracing::instrument(skip(self))]
- pub async fn remove_user_from_org_channels(
- &self,
- user_id: &str,
- org_id: &i64,
- ) -> Result<(), ClientError> {
- let body = serde_json::to_value(RemoveUserFromOrgChannelsRequest {
- user_id: user_id.to_string(),
- org_id: *org_id,
- })
- .map_err(|e| ClientError::Generic(anyhow::anyhow!(e.to_string())))?;
-
- self.client
- .post(format!(
- "{}/internal/remove_user_from_org_channels",
- self.url
- ))
- .json(&body)
- .send()
- .await
- .map_client_error()
- .await?;
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/comms_service_client/src/participants.rs b/rust/cloud-storage/comms_service_client/src/participants.rs
deleted file mode 100644
index b01ff83bdd..0000000000
--- a/rust/cloud-storage/comms_service_client/src/participants.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-use crate::CommsServiceClient;
-use crate::error::{ClientError, ResponseExt};
-use model::comms::ChannelParticipant;
-
-impl CommsServiceClient {
- /// Returns the participants in a channel.
- #[tracing::instrument(skip(self))]
- pub async fn get_channel_participants(
- &self,
- channel_id: &str,
- ) -> Result<Vec<ChannelParticipant>, ClientError> {
- let res = self
- .client
- .get(format!(
- "{}/internal/get_channel_participants/{channel_id}",
- self.url
- ))
- .send()
- .await
- .map_client_error()
- .await?;
-
- let result = res.json::<Vec<ChannelParticipant>>().await.map_err(|e| {
- ClientError::Generic(anyhow::anyhow!(
- "unable to parse response from get_channel_participants: {}",
- e.to_string()
- ))
- })?;
-
- Ok(result)
- }
-}
diff --git a/rust/cloud-storage/comms_service_client/src/permissions.rs b/rust/cloud-storage/comms_service_client/src/permissions.rs
deleted file mode 100644
index 52990f8e76..0000000000
--- a/rust/cloud-storage/comms_service_client/src/permissions.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-use uuid::Uuid;
-
-use crate::error::{ClientError, ResponseExt};
-use model::comms::CheckChannelsForUserRequest;
-
-use super::CommsServiceClient;
-
-impl CommsServiceClient {
- /// Given a list of channel ids and a user id, this will return all channel ids in the list
- /// that the user is part of.
- #[tracing::instrument(skip(self))]
- pub async fn check_channels_for_user(
- &self,
- user_id: &str,
- channel_ids: &[Uuid],
- ) -> Result<Vec<Uuid>, ClientError> {
- let body = serde_json::to_value(CheckChannelsForUserRequest {
- user_id: user_id.to_string(),
- channel_ids: channel_ids.to_vec(),
- })
- .map_err(|e| ClientError::Generic(anyhow::anyhow!(e.to_string())))?;
-
- let response = self
- .client
- .post(format!("{}/internal/check_channels_for_user", self.url))
- .json(&body)
- .send()
- .await
- .map_client_error()
- .await?;
-
- let result = response.json::<Vec<Uuid>>().await.map_err(|e| {
- ClientError::Generic(anyhow::anyhow!(
- "unable to parse response from check_channels_for_user: {}",
- e.to_string()
- ))
- })?;
-
- Ok(result)
- }
-}
diff --git a/rust/cloud-storage/delete_document_worker/Cargo.toml b/rust/cloud-storage/delete_document_worker/Cargo.toml
index 21f7a81c42..8520fb8c45 100644
--- a/rust/cloud-storage/delete_document_worker/Cargo.toml
+++ b/rust/cloud-storage/delete_document_worker/Cargo.toml
@@ -16,7 +16,7 @@ aws-sdk-secretsmanager = { workspace = true }
aws-sdk-sqs = { workspace = true }
axum = { workspace = true }
chrono = { workspace = true }
-comms_service_client = { path = "../comms_service_client" }
+comms_db_client = { path = "../comms_db_client" }
futures = { workspace = true }
macro_cors = { path = "../macro_cors" }
macro_db_client = { path = "../macro_db_client" }
diff --git a/rust/cloud-storage/delete_document_worker/src/config.rs b/rust/cloud-storage/delete_document_worker/src/config.rs
index cd825a4670..3fdead4700 100644
--- a/rust/cloud-storage/delete_document_worker/src/config.rs
+++ b/rust/cloud-storage/delete_document_worker/src/config.rs
@@ -22,10 +22,6 @@ pub struct Config {
pub port: usize,
- pub comms_service_auth_key: String,
-
- pub comms_service_url: String,
-
/// API key for sync service
pub sync_service_auth_key: String,
@@ -61,12 +57,6 @@ impl Config {
.parse::<usize>()
.context("PORT must be a valid number")?;
- let comms_service_auth_key = std::env::var("COMMS_SERVICE_AUTH_KEY")
- .context("COMMS_SERVICE_AUTH_KEY must be provided")?;
-
- let comms_service_url =
- std::env::var("COMMS_SERVICE_URL").context("COMMS_SERVICE_URL must be provided")?;
-
let sync_service_auth_key = std::env::var("SYNC_SERVICE_AUTH_KEY")
.context("SYNC_SERVICE_AUTH_KEY must be provided")?;
@@ -82,8 +72,6 @@ impl Config {
environment,
port,
delete_document_queue,
- comms_service_auth_key,
- comms_service_url,
sync_service_auth_key,
sync_service_url,
})
diff --git a/rust/cloud-storage/delete_document_worker/src/context.rs b/rust/cloud-storage/delete_document_worker/src/context.rs
index 4d0b6bcb69..02c31f2b15 100644
--- a/rust/cloud-storage/delete_document_worker/src/context.rs
+++ b/rust/cloud-storage/delete_document_worker/src/context.rs
@@ -11,6 +11,5 @@ pub struct QueueWorkerContext {
pub s3_client: Arc<s3_client::S3>,
pub redis_client: Arc<Redis>,
pub sync_service_client: Arc<sync_service_client::SyncServiceClient>,
- pub comms_service_client: Arc<comms_service_client::CommsServiceClient>,
pub config: Config,
}
diff --git a/rust/cloud-storage/delete_document_worker/src/main.rs b/rust/cloud-storage/delete_document_worker/src/main.rs
index 412064cc0f..ea709d4c01 100644
--- a/rust/cloud-storage/delete_document_worker/src/main.rs
+++ b/rust/cloud-storage/delete_document_worker/src/main.rs
@@ -78,27 +78,12 @@ pub async fn main() -> anyhow::Result<()> {
config.sync_service_url.clone(),
);
- let comms_service_auth_key = match config.environment {
- Environment::Local => config.comms_service_auth_key.clone(),
- _ => secretsmanager_client
- .get_secret_value(&config.comms_service_auth_key)
- .await
- .context("unable to get secret")?
- .to_string(),
- };
-
- let comms_service_client = comms_service_client::CommsServiceClient::new(
- comms_service_auth_key,
- config.comms_service_url.clone(),
- );
-
let queue_worker_context = QueueWorkerContext {
db: db.clone(),
worker: Arc::new(delete_document_worker),
s3_client: Arc::new(s3_client),
redis_client: Arc::new(redis_client),
sync_service_client: Arc::new(sync_service_client),
- comms_service_client: Arc::new(comms_service_client),
config: config.clone(),
};
diff --git a/rust/cloud-storage/delete_document_worker/src/process/handle.rs b/rust/cloud-storage/delete_document_worker/src/process/handle.rs
index c20d3e2b8b..82e4779f41 100644
--- a/rust/cloud-storage/delete_document_worker/src/process/handle.rs
+++ b/rust/cloud-storage/delete_document_worker/src/process/handle.rs
@@ -66,13 +66,14 @@ pub async fn handle(
}
// delete entity mentions where this doc is the source
- let _ = ctx
- .comms_service_client
- .delete_mentions_by_source(vec![document_id.to_string()])
- .await
- .inspect_err(|e| {
- tracing::warn!(error=?e, "could not delete entity mentions for document");
- });
+ let _ = comms_db_client::entity_mentions::delete_entity_mentions_by_source(
+ &ctx.db,
+ vec![document_id.to_string()],
+ )
+ .await
+ .inspect_err(|e| {
+ tracing::warn!(error=?e, "could not delete entity mentions for document");
+ });
let user_id = user_id.context("user_id should be some")?;
diff --git a/rust/cloud-storage/document_cognition_service/src/api/context.rs b/rust/cloud-storage/document_cognition_service/src/api/context.rs
index 281cf7ef28..cb70db793c 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/context.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/context.rs
@@ -71,10 +71,7 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Ar
));
let macro_notify_client =
MacroNotifyClient::new("dummy_queue".into(), "dummy_service".into()).await;
- let comms_service_client = Arc::new(CommsServiceClient::new(
- "dummy_auth_key".into(),
- "http://localhost".into(),
- ));
+ let comms_service_client = Arc::new(CommsServiceClient::new("http://localhost".into()));
let search_service_client =
SearchServiceClient::new("dummy_auth_key".into(), "http://localhost".into());
let lexical_client = Arc::new(LexicalClient::new(
@@ -111,7 +108,7 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Ar
.with_macro_db(pool.clone())
.build(),
)
- .with_channel_client(comms_service_client.clone())
+ .with_channel_client_and_db(comms_service_client.clone(), pool.clone())
.with_dcs_client(document_cognition_service_client)
.with_email_client(email_service_client)
.with_static_file_client(static_file_service_client.clone());
diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rs
index 7e8917e0d6..f4914f6887 100644
--- a/rust/cloud-storage/document_cognition_service/src/main.rs
+++ b/rust/cloud-storage/document_cognition_service/src/main.rs
@@ -89,10 +89,7 @@ async fn main() -> anyhow::Result<()> {
);
tracing::info!("initialized dss client");
- let comms_service_client = CommsServiceClient::new(
- internal_auth_key.as_ref().to_string(),
- config.comms_service_url.clone(),
- );
+ let comms_service_client = CommsServiceClient::new(config.comms_service_url.clone());
tracing::info!("initialized comms client");
let sync_service_auth_key = match config.environment {
@@ -195,7 +192,7 @@ async fn main() -> anyhow::Result<()> {
.with_macro_db(db.clone())
.build(),
)
- .with_channel_client(comms_service_client.clone())
+ .with_channel_client_and_db(comms_service_client.clone(), db.clone())
.with_dcs_client(document_cognition_service_client)
.with_email_client(email_service_client)
.with_static_file_client(static_file_service_client.clone()),
diff --git a/rust/cloud-storage/macro_project_utils/Cargo.toml b/rust/cloud-storage/macro_project_utils/Cargo.toml
index b3a38a62ca..2494fed29c 100644
--- a/rust/cloud-storage/macro_project_utils/Cargo.toml
+++ b/rust/cloud-storage/macro_project_utils/Cargo.toml
@@ -6,7 +6,6 @@ version = "0.1.0"
[dependencies]
anyhow = { workspace = true }
-comms_service_client = { path = "../comms_service_client" }
macro_db_client = { path = "../macro_db_client" }
macro_notify = { path = "../macro_notify" }
model = { path = "../model" }
diff --git a/rust/cloud-storage/macro_share_permissions/Cargo.toml b/rust/cloud-storage/macro_share_permissions/Cargo.toml
index e700311112..62ff1f860c 100644
--- a/rust/cloud-storage/macro_share_permissions/Cargo.toml
+++ b/rust/cloud-storage/macro_share_permissions/Cargo.toml
@@ -7,7 +7,6 @@ version = "0.1.0"
[dependencies]
anyhow = { workspace = true }
-comms_service_client = { path = "../comms_service_client" }
macro_db_client = { path = "../macro_db_client" }
comms_db_client = { path = "../comms_db_client" }
macro_user_id = { path = "../macro_user_id" }
diff --git a/rust/cloud-storage/scribe/Cargo.toml b/rust/cloud-storage/scribe/Cargo.toml
index 68073ed191..e5852c1917 100644
--- a/rust/cloud-storage/scribe/Cargo.toml
+++ b/rust/cloud-storage/scribe/Cargo.toml
@@ -7,7 +7,7 @@ version = "0.1.0"
[features]
all = ["channel", "dcs", "document", "email", "static_file"]
-channel = ["comms_service_client", "models_comms"]
+channel = ["comms_service_client", "comms_db_client", "models_comms", "dep:sqlx"]
dcs = ["document_cognition_service_client"]
default = []
document = [
@@ -54,6 +54,7 @@ document_storage_service_client = { path = "../document_storage_service_client",
lexical_client = { path = "../lexical_client", optional = true }
sync_service_client = { path = "../sync_service_client", optional = true }
+comms_db_client = { path = "../comms_db_client", optional = true }
comms_service_client = { path = "../comms_service_client", optional = true }
document_cognition_service_client = { path = "../document_cognition_service_client", optional = true }
email_service_client = { path = "../email_service_client", optional = true }
diff --git a/rust/cloud-storage/scribe/src/channel/client.rs b/rust/cloud-storage/scribe/src/channel/client.rs
index 6ed1fadc03..9cf6e502c1 100644
--- a/rust/cloud-storage/scribe/src/channel/client.rs
+++ b/rust/cloud-storage/scribe/src/channel/client.rs
@@ -2,8 +2,9 @@ use ai_format::insight_context_log::InsightContextLog;
use ai_format::util::Indent;
use anyhow::Error;
use comms_service_client::CommsServiceClient;
-use comms_service_client::channels::ApiChannelWithLatest;
+use comms_service_client::channels::{ApiChannelWithLatest, ChannelMetadataResponse};
use models_comms::channel::ChannelMetadata;
+use sqlx::{Pool, Postgres};
use std::fmt::Debug;
use std::sync::Arc;
use uuid::Uuid;
@@ -11,11 +12,13 @@ use uuid::Uuid;
#[derive(Clone)]
pub struct ChannelClient {
inner: Arc<CommsServiceClient>,
+ db: Pool<Postgres>,
}
impl ChannelClient {
- pub fn new(client: Arc<CommsServiceClient>) -> Self {
- Self { inner: client }
+ /// Create a new ChannelClient with a database pool for internal (non-JWT) operations
+ pub fn new_with_db(client: Arc<CommsServiceClient>, db: Pool<Postgres>) -> Self {
+ Self { inner: client, db }
}
/// List all channels the user has access to
@@ -30,7 +33,7 @@ impl ChannelClient {
}
/// Get channel metadata (name and type) by channel ID
- /// Uses external authenticated endpoint if jwt_token is provided, otherwise uses internal endpoint
+ /// Uses external authenticated endpoint if jwt_token is provided, otherwise uses direct DB access
#[tracing::instrument(skip(self, jwt_token), err)]
pub async fn get_channel_metadata(
&self,
@@ -41,21 +44,27 @@ impl ChannelClient {
.try_into()
.map_err(|_| anyhow::anyhow!("invalid uuid"))?;
- let response = match jwt_token {
+ let channel = match jwt_token {
Some(token) => self
.inner
.get_channel_metadata_external(&channel_id, token)
.await
.map_err(Error::from)?,
- None => self
- .inner
- .get_channel_metadata_internal(&channel_id, None)
- .await
- .map_err(Error::from)?,
+ None => {
+ let channel =
+ comms_db_client::channels::get_channel::get_channel(&self.db, &channel_id)
+ .await?;
+
+ ChannelMetadataResponse {
+ channel_name: channel.name.unwrap_or_default(),
+ channel_type: channel.channel_type,
+ }
+ }
};
+
Ok(ChannelMetadata {
- name: response.channel_name,
- channel_type: match response.channel_type {
+ name: channel.channel_name,
+ channel_type: match channel.channel_type {
model::comms::ChannelType::Public => models_comms::channel::ChannelType::Public,
model::comms::ChannelType::Organization => {
models_comms::channel::ChannelType::Organization
@@ -69,7 +78,7 @@ impl ChannelClient {
}
/// Get channel transcript (message history) by channel ID
- /// Uses external authenticated endpoint if jwt_token is provided, otherwise uses internal endpoint
+ /// Uses external authenticated endpoint if jwt_token is provided, otherwise uses direct DB access
#[tracing::instrument(skip(self, jwt_token), err)]
pub async fn get_channel_transcript(
&self,
@@ -81,19 +90,23 @@ impl ChannelClient {
let channel_id = channel_id
.try_into()
.map_err(|_| anyhow::anyhow!("invalid uuid"))?;
- let response = match jwt_token {
- Some(token) => self
- .inner
- .get_channel_transcript_external(&channel_id, token, since, limit)
- .await
- .map_err(Error::from)?,
- None => self
- .inner
- .get_channel_transcript_internal(&channel_id, since, limit)
- .await
- .map_err(Error::from)?,
- };
- Ok(response.transcript)
+
+ match jwt_token {
+ Some(token) => {
+ let response = self
+ .inner
+ .get_channel_transcript_external(&channel_id, token, since, limit)
+ .await
+ .map_err(Error::from)?;
+ Ok(response.transcript)
+ }
+ None => {
+ // Use direct DB access for internal calls
+ let transcript =
+ format_channel_transcript(&self.db, &channel_id, since, limit).await?;
+ Ok(transcript)
+ }
+ }
}
/// Get messages with context around a specific message
@@ -145,3 +158,43 @@ impl ChannelClient {
Ok(formatted_text)
}
}
+
+/// Format channel messages into a transcript string
+/// This matches the logic in comms_service/src/api/channels/get_channel_transcript.rs
+async fn format_channel_transcript(
+ db: &Pool<Postgres>,
+ channel_id: &Uuid,
+ since: Option<chrono::DateTime<chrono::Utc>>,
+ limit: Option<i64>,
+) -> anyhow::Result<String> {
+ let messages =
+ comms_db_client::messages::get_messages::get_messages(db, channel_id, since, limit).await?;
+
+ let formatted_messages = messages
+ .iter()
+ .map(|msg| {
+ InsightContextLog {
+ name: "message".to_string(),
+ metadata: vec![
+ ("sender_id".to_string(), msg.sender_id.to_string()),
+ ("created_at".to_string(), msg.created_at.to_rfc3339()),
+ ],
+ content: msg.content.clone(),
+ }
+ .to_string()
+ })
+ .collect::<Vec<_>>()
+ .join("\n");
+
+ let formatted_text = InsightContextLog {
+ name: "conversation".to_string(),
+ metadata: vec![],
+ content: Indent(4, formatted_messages),
+ }
+ .to_string();
+
+ let prompt = "The following conversation is limited to the last 1000 messages. Ignore all formatting and do not show the user the formatted conversation.";
+ let formatted_messages = format!("{}\n\n{}", prompt, formatted_text);
+
+ Ok(formatted_messages)
+}
diff --git a/rust/cloud-storage/scribe/src/channel/mod.rs b/rust/cloud-storage/scribe/src/channel/mod.rs
index 81eb3fd718..796bfa35af 100644
--- a/rust/cloud-storage/scribe/src/channel/mod.rs
+++ b/rust/cloud-storage/scribe/src/channel/mod.rs
@@ -1,16 +1,19 @@
mod client;
pub use client::ChannelClient;
use comms_service_client::CommsServiceClient;
+use sqlx::{Pool, Postgres};
use crate::client::ScribeClient;
use std::sync::Arc;
impl<D, C, A, E, S> ScribeClient<D, C, A, E, S> {
- pub fn with_channel_client<T: Into<Arc<CommsServiceClient>>>(
+ /// Configure the channel client with both HTTP client and database pool for internal operations
+ pub fn with_channel_client_and_db<T: Into<Arc<CommsServiceClient>>>(
self,
channel_client: T,
+ db: Pool<Postgres>,
) -> ScribeClient<D, ChannelClient, A, E, S> {
- let client = ChannelClient::new(channel_client.into());
+ let client = ChannelClient::new_with_db(channel_client.into(), db);
ScribeClient {
document: self.document,
channel: client,
diff --git a/rust/cloud-storage/search_processing_service/Cargo.toml b/rust/cloud-storage/search_processing_service/Cargo.toml
index 35192d387d..f6b1bc4c03 100644
--- a/rust/cloud-storage/search_processing_service/Cargo.toml
+++ b/rust/cloud-storage/search_processing_service/Cargo.toml
@@ -27,8 +27,7 @@ aws-sdk-secretsmanager = { workspace = true }
aws-sdk-sqs = { workspace = true }
axum = { workspace = true }
chrono = { workspace = true }
-comms_db_client = { path = "../comms_db_client", optional = true }
-comms_service_client = { path = "../comms_service_client" }
+comms_db_client = { path = "../comms_db_client" }
email_db_client = { path = "../email_db_client", optional = true }
email_service_client = { path = "../email_service_client" }
futures = { workspace = true }
diff --git a/rust/cloud-storage/search_processing_service/src/config.rs b/rust/cloud-storage/search_processing_service/src/config.rs
index 025640e54a..e1106d52c0 100644
--- a/rust/cloud-storage/search_processing_service/src/config.rs
+++ b/rust/cloud-storage/search_processing_service/src/config.rs
@@ -35,9 +35,6 @@ pub struct Config {
/// The email service URL
pub email_service_url: String,
- /// The comms service URL
- pub comms_service_url: String,
-
/// The number of workers to spawn
pub worker_count: u8,
@@ -86,9 +83,6 @@ impl Config {
let email_service_url =
std::env::var("EMAIL_SERVICE_URL").context("EMAIL_SERVICE_URL must be provided")?;
- let comms_service_url =
- std::env::var("COMMS_SERVICE_URL").context("COMMS_SERVICE_URL must be provided")?;
-
let worker_count: u8 = std::env::var("WORKER_COUNT")
.unwrap_or("10".to_string())
.parse::<u8>()
@@ -110,7 +104,6 @@ impl Config {
document_storage_bucket,
sync_service_auth_key,
email_service_url,
- comms_service_url,
worker_count,
lexical_service_url,
})
diff --git a/rust/cloud-storage/search_processing_service/src/main.rs b/rust/cloud-storage/search_processing_service/src/main.rs
index dbc9980d8c..6e7d31a95f 100644
--- a/rust/cloud-storage/search_processing_service/src/main.rs
+++ b/rust/cloud-storage/search_processing_service/src/main.rs
@@ -124,11 +124,6 @@ async fn main() -> anyhow::Result<()> {
config.email_service_url.clone(),
);
- let comms_service_client = comms_service_client::CommsServiceClient::new(
- internal_auth_key.as_ref().to_string(),
- config.comms_service_url.clone(),
- );
-
let worker = sqs_worker::SQSWorker::new(
aws_sdk_sqs::Client::new(&aws_config),
config.search_event_queue.clone(),
@@ -141,7 +136,6 @@ async fn main() -> anyhow::Result<()> {
document_storage_bucket: config.document_storage_bucket.clone(),
s3_client: Arc::new(s3_client),
opensearch_client: Arc::new(opensearch_client.clone()),
- comms_service_client: Arc::new(comms_service_client),
lexical_client: Arc::new(lexical_client),
email_client: email_service_client.into(),
};
diff --git a/rust/cloud-storage/search_processing_service/src/process/channel.rs b/rust/cloud-storage/search_processing_service/src/process/channel.rs
index 8b45db547f..089b655d28 100644
--- a/rust/cloud-storage/search_processing_service/src/process/channel.rs
+++ b/rust/cloud-storage/search_processing_service/src/process/channel.rs
@@ -1,18 +1,26 @@
use anyhow::Context;
-use comms_service_client::CommsServiceClient;
use mention_utils::parse::{NullXmlFormatter, ParsedXmlText, XmlFormatter};
use opensearch_client::{
OpensearchClient, date_format::EpochSeconds, upsert::channel_message::UpsertChannelMessageArgs,
};
+use sqlx::{Pool, Postgres};
use sqs_client::search::channel::{ChannelMessageUpdate, RemoveChannelMessage};
+use uuid::Uuid;
pub async fn process_channel_message_update(
opensearch_client: &OpensearchClient,
- comms_service_client: &CommsServiceClient,
+ db: &Pool<Postgres>,
message: &ChannelMessageUpdate,
) -> anyhow::Result<()> {
- let channel_message_info = comms_service_client
- .get_channel_message(&message.channel_id, &message.message_id)
+ let channel_id = Uuid::parse_str(&message.channel_id).context("invalid channel_id uuid")?;
+ let message_id = Uuid::parse_str(&message.message_id).context("invalid message_id uuid")?;
+
+ let channel_message_info =
+ comms_db_client::messages::get_channel_message::get_channel_message_by_id(
+ db,
+ &channel_id,
+ &message_id,
+ )
.await
.context("unable to get channel message")?;
diff --git a/rust/cloud-storage/search_processing_service/src/process/context.rs b/rust/cloud-storage/search_processing_service/src/process/context.rs
index 2fb564cf7a..9f7e54bd86 100644
--- a/rust/cloud-storage/search_processing_service/src/process/context.rs
+++ b/rust/cloud-storage/search_processing_service/src/process/context.rs
@@ -7,7 +7,6 @@ pub struct SearchProcessingContext {
pub document_storage_bucket: String,
pub s3_client: Arc<s3_client::S3>,
pub opensearch_client: Arc<opensearch_client::OpensearchClient>,
- pub comms_service_client: Arc<comms_service_client::CommsServiceClient>,
pub lexical_client: Arc<lexical_client::LexicalClient>,
pub email_client: Arc<email_service_client::EmailServiceClient>,
}
diff --git a/rust/cloud-storage/search_processing_service/src/process/mod.rs b/rust/cloud-storage/search_processing_service/src/process/mod.rs
index e44f7d7497..17cec2b1d6 100644
--- a/rust/cloud-storage/search_processing_service/src/process/mod.rs
+++ b/rust/cloud-storage/search_processing_service/src/process/mod.rs
@@ -36,12 +36,8 @@ pub async fn process_message(
user::remove_user_profile(&ctx.opensearch_client, &user_profile_id).await?;
}
SearchQueueMessage::ChannelMessageUpdate(message) => {
- channel::process_channel_message_update(
- &ctx.opensearch_client,
- &ctx.comms_service_client,
- &message,
- )
- .await?;
+ channel::process_channel_message_update(&ctx.opensearch_client, &ctx.db, &message)
+ .await?;
}
SearchQueueMessage::RemoveChannelMessage(message) => {
channel::process_remove_channel_message(&ctx.opensearch_client, &message).await?;