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(soup): Move email to trash (#1616)

Evan Hutnikcd930f9d1b3e
diff --git a/js/app/packages/app/component/next-soup/actions/make-delete-action.ts b/js/app/packages/app/component/next-soup/actions/make-delete-action.ts
index 02b297a105..a18505ecb6 100644
--- a/js/app/packages/app/component/next-soup/actions/make-delete-action.ts
+++ b/js/app/packages/app/component/next-soup/actions/make-delete-action.ts
@@ -4,7 +4,7 @@ import { openBulkEditModal } from '@app/component/bulk-edit-entity/BulkEditEntit
import { globalSplitManager } from '@app/signal/splitLayout';
import { globalRemoveFromSplitHistory } from '@app/component/split-layout/layoutUtils';
import type { SoupState } from '../create-soup-state';
-import { restoreSoupFocus } from '../utils';
+import { restoreSoupFocus, trashEmails } from '../utils';
import { useMaybePreviewPanel } from '@app/component/PreviewPanel';
type MakeDeleteOptions = {
@@ -15,7 +15,10 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {
const { userId } = options;
const canExecute = (entity: EntityData): boolean => {
- if (entity.type === 'channel' || entity.type === 'email') {
+ if (entity.type === 'email') {
+ return true;
+ }
+ if (entity.type === 'channel') {
return false;
}
return entity.ownerId === userId();
@@ -49,37 +52,95 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {
const inPreview = previewPanel !== undefined;
- openBulkEditModal({
- view: 'delete',
- entities,
- onFinish: () => {
- const splitManager = globalSplitManager();
- if (splitManager) {
- const entityIdSet = new Set(entities.map(({ id }) => id));
- globalRemoveFromSplitHistory(splitManager, (entry) =>
- entityIdSet.has(entry.id)
- );
- }
+ // Separate email entities from non-email entities
+ const emailEntities = entities.filter((e) => e.type === 'email');
+ const nonEmailEntities = entities.filter((e) => e.type !== 'email');
- soup.selection.clear();
- if (nextEntity) {
- soup.focus.set(nextEntity.id);
- }
+ const trashEmailEntities = () => {
+ const handle = trashEmails(emailEntities.map((e) => e.id));
- toast.success(
- entities.length > 1 ? `Deleted ${entities.length} items` : 'Deleted'
+ const splitManager = globalSplitManager();
+ if (splitManager) {
+ const entityIdSet = new Set(emailEntities.map(({ id }) => id));
+ globalRemoveFromSplitHistory(splitManager, (entry) =>
+ entityIdSet.has(entry.id)
);
+ }
- restoreSoupFocus(nextEntity?.id, inPreview);
- },
- onCancel: () => {
- const firstEntity = entities[0];
- if (firstEntity) {
- soup.focus.set(firstEntity.id);
- }
- restoreSoupFocus(firstEntity?.id, inPreview);
- },
- });
+ soup.selection.clear();
+ if (nextEntity) {
+ soup.focus.set(nextEntity.id);
+ }
+
+ const toastId = toast.success(
+ emailEntities.length > 1
+ ? `Moved ${emailEntities.length} items to Trash`
+ : 'Moved to Trash',
+ undefined,
+ {
+ text: 'Undo',
+ onClick: () => {
+ if (toastId != null) toast.dismiss(toastId);
+ handle.undo().then(
+ () => toast.success('Restored from Trash'),
+ () => toast.failure('Failed to restore from Trash')
+ );
+ },
+ },
+ 10_000
+ );
+
+ // Surface background API failures
+ handle.done.catch(() => {
+ toast.failure('Failed to move to Trash');
+ });
+
+ restoreSoupFocus(nextEntity?.id, inPreview);
+ };
+
+ if (nonEmailEntities.length > 0) {
+ // Handle non-email entities first via the bulk edit modal,
+ // then trash emails in onFinish so nextEntity/focus are still valid.
+ openBulkEditModal({
+ view: 'delete',
+ entities: nonEmailEntities,
+ onFinish: () => {
+ const splitManager = globalSplitManager();
+ if (splitManager) {
+ const entityIdSet = new Set(nonEmailEntities.map(({ id }) => id));
+ globalRemoveFromSplitHistory(splitManager, (entry) =>
+ entityIdSet.has(entry.id)
+ );
+ }
+
+ toast.success(
+ nonEmailEntities.length > 1
+ ? `Deleted ${nonEmailEntities.length} items`
+ : 'Deleted'
+ );
+
+ if (emailEntities.length > 0) {
+ trashEmailEntities();
+ } else {
+ soup.selection.clear();
+ if (nextEntity) {
+ soup.focus.set(nextEntity.id);
+ }
+ restoreSoupFocus(nextEntity?.id, inPreview);
+ }
+ },
+ onCancel: () => {
+ const firstEntity = nonEmailEntities[0];
+ if (firstEntity) {
+ soup.focus.set(firstEntity.id);
+ }
+ restoreSoupFocus(firstEntity?.id, inPreview);
+ },
+ });
+ } else if (emailEntities.length > 0) {
+ // Email-only selection: trash immediately
+ trashEmailEntities();
+ }
};
return { canExecute, execute, executeWithSoup };
diff --git a/js/app/packages/app/component/next-soup/utils.ts b/js/app/packages/app/component/next-soup/utils.ts
index 9905d8649e..0149be0111 100644
--- a/js/app/packages/app/component/next-soup/utils.ts
+++ b/js/app/packages/app/component/next-soup/utils.ts
@@ -17,6 +17,8 @@ import {
import { queryKeys } from '@macro-entity';
import { queryClient } from '@queries/client';
import { emailClient } from '@service-email/client';
+import { emailKeys } from '@queries/email/keys';
+import { throwOnErr } from '@core/util/maybeResult';
import {
removeSoupEntities,
getSoupEntityById,
@@ -426,3 +428,122 @@ export async function archiveEmail(
]);
}
}
+
+export type TrashEmailsHandle = {
+ /** Fire-and-forget promise for the API calls. Rejects on failure (rolls back optimistic update). */
+ done: Promise<void>;
+ /** Optimistically restores all entities and calls the API to remove the TRASH label. */
+ undo: () => Promise<void>;
+};
+
+/**
+ * Optimistically removes one or more email threads from soup + email caches,
+ * then fires the TRASH label API calls in the background. Takes a single
+ * snapshot before all removals so undo restores the complete pre-trash state.
+ * Returns synchronously so the caller can show the undo toast immediately.
+ */
+export function trashEmails(ids: string[]): TrashEmailsHandle {
+ queryClient.cancelQueries({ queryKey: queryKeys.all.email });
+
+ const previousEmail = queryClient.getQueriesData<{
+ pages: { items: EntityData[] }[];
+ }>({
+ queryKey: queryKeys.all.email,
+ });
+
+ const idSet = new Set(ids);
+ const soupTxn = removeSoupEntities(idSet);
+
+ // Optimistically remove from email queries
+ for (const [key, data] of previousEmail) {
+ if (!data) continue;
+ queryClient.setQueryData(key, {
+ ...data,
+ pages: data.pages.map((page) => ({
+ ...page,
+ items: page.items.filter((item) => !idSet.has(item.id)),
+ })),
+ });
+ }
+
+ const rollback = () => {
+ soupTxn.rollback();
+ for (const [key, data] of previousEmail) {
+ queryClient.setQueryData(key, data);
+ }
+ };
+
+ // Resolved lazily by the API calls; used by undo
+ let trashLabelId: string | undefined;
+
+ const done = (async () => {
+ try {
+ const labelsData = await queryClient.fetchQuery({
+ queryKey: emailKeys.labels.queryKey,
+ queryFn: async () =>
+ throwOnErr(async () => await emailClient.getUserLabels()),
+ staleTime: 5 * 60 * 1000,
+ });
+ const trashLabel = labelsData?.labels.find(
+ (l) => l.provider_label_id === 'TRASH'
+ );
+ const labelId = trashLabel?.id;
+ if (!labelId) {
+ throw new Error('TRASH label not found');
+ }
+ trashLabelId = labelId;
+
+ await Promise.all(
+ ids.map((id) =>
+ emailClient.updateThreadLabel({
+ thread_id: id,
+ label_id: labelId,
+ value: true,
+ })
+ )
+ );
+ } catch (err) {
+ rollback();
+ throw err;
+ } finally {
+ await Promise.all([
+ queryClient.invalidateQueries({ queryKey: queryKeys.all.email }),
+ ...ids.map((id) => invalidateSoupEntity(id)),
+ ]);
+ }
+ })();
+
+ return {
+ done,
+ undo: async () => {
+ // Wait for the trash calls to finish so we know the label ID.
+ // If the trash call itself failed, rollback already happened — nothing to undo.
+ try {
+ await done;
+ } catch {
+ return;
+ }
+
+ rollback();
+
+ try {
+ await Promise.all(
+ ids.map((id) =>
+ emailClient.updateThreadLabel({
+ thread_id: id,
+ label_id: trashLabelId!,
+ value: false,
+ })
+ )
+ );
+ } finally {
+ // Only invalidate email queries — skip soup invalidation since
+ // rollback() already restored the correct cache state.
+ await queryClient.invalidateQueries({
+ queryKey: queryKeys.all.email,
+ refetchType: 'none',
+ });
+ }
+ },
+ };
+}
diff --git a/js/app/packages/queries/email/keys.ts b/js/app/packages/queries/email/keys.ts
index f309e65af6..11adf36b3c 100644
--- a/js/app/packages/queries/email/keys.ts
+++ b/js/app/packages/queries/email/keys.ts
@@ -3,6 +3,7 @@ import type { PreviewViewStandardLabel } from '@service-email/generated/schemas'
export const emailKeys = createQueryKeys('email', {
all: null,
+ labels: null,
links: null,
threads: null,
thread: (threadId: string) => ({
diff --git a/js/app/packages/queries/email/label.ts b/js/app/packages/queries/email/label.ts
new file mode 100644
index 0000000000..90ac96a487
--- /dev/null
+++ b/js/app/packages/queries/email/label.ts
@@ -0,0 +1,24 @@
+import { throwOnErr } from '@core/util/maybeResult';
+import { queryClient } from '@queries/client';
+import { emailClient } from '@service-email/client';
+import { useQuery } from '@tanstack/solid-query';
+import { emailKeys } from './keys';
+
+const LABEL_STALE_TIME = 5 * 60 * 1000;
+
+export function useEmailLabelsQuery() {
+ return useQuery(() => ({
+ queryKey: emailKeys.labels.queryKey,
+ queryFn: async () =>
+ throwOnErr(async () => await emailClient.getUserLabels()),
+ staleTime: LABEL_STALE_TIME,
+ refetchOnWindowFocus: 'always',
+ }));
+}
+
+export function invalidateEmailLabels() {
+ queryClient.cancelQueries({ queryKey: emailKeys.labels.queryKey });
+ queryClient.invalidateQueries({
+ queryKey: emailKeys.labels.queryKey,
+ });
+}
diff --git a/js/app/packages/service-clients/service-email/client.ts b/js/app/packages/service-clients/service-email/client.ts
index 76369627ca..25d888e434 100644
--- a/js/app/packages/service-clients/service-email/client.ts
+++ b/js/app/packages/service-clients/service-email/client.ts
@@ -26,6 +26,7 @@ import type {
SendMessageResponse,
UpdateLabelBatchRequest,
UpdateLabelBatchResponse,
+ UpdateThreadLabelRequest,
UpsertScheduledRequest,
UpsertScheduledResponse,
} from './generated/schemas';
@@ -120,6 +121,21 @@ export const emailClient = {
(result) => result
);
},
+ async updateThreadLabel(
+ args: { thread_id: string } & UpdateThreadLabelRequest
+ ) {
+ const { thread_id, label_id, value } = args;
+ return mapOk(
+ await emailFetch<UpdateLabelBatchResponse>(
+ `/email/threads/${thread_id}/labels`,
+ {
+ method: 'PATCH',
+ body: JSON.stringify({ label_id, value }),
+ }
+ ),
+ (result) => result
+ );
+ },
async flagArchived(args: { value: boolean; id: string }) {
const { value, id } = args;
return mapOk(
diff --git a/js/app/packages/service-clients/service-email/generated/client.ts b/js/app/packages/service-clients/service-email/generated/client.ts
index d847c87470..4f2fd7cd55 100644
--- a/js/app/packages/service-clients/service-email/generated/client.ts
+++ b/js/app/packages/service-clients/service-email/generated/client.ts
@@ -40,6 +40,7 @@ import type {
SendMessageResponse,
UpdateLabelBatchRequest,
UpdateLabelBatchResponse,
+ UpdateThreadLabelRequest,
UpsertScheduledRequest,
UpsertScheduledResponse,
} from './schemas';
@@ -1977,6 +1978,79 @@ export const archiveThread = async (
} as archiveThreadResponse;
};
+/**
+ * @summary Add or remove a label from all messages in a thread
+ */
+export type addRemoveThreadLabelResponse200 = {
+ data: UpdateLabelBatchResponse;
+ status: 200;
+};
+
+export type addRemoveThreadLabelResponse400 = {
+ data: ErrorResponse;
+ status: 400;
+};
+
+export type addRemoveThreadLabelResponse401 = {
+ data: ErrorResponse;
+ status: 401;
+};
+
+export type addRemoveThreadLabelResponse404 = {
+ data: ErrorResponse;
+ status: 404;
+};
+
+export type addRemoveThreadLabelResponse500 = {
+ data: ErrorResponse;
+ status: 500;
+};
+
+export type addRemoveThreadLabelResponseSuccess =
+ addRemoveThreadLabelResponse200 & {
+ headers: Headers;
+ };
+export type addRemoveThreadLabelResponseError = (
+ | addRemoveThreadLabelResponse400
+ | addRemoveThreadLabelResponse401
+ | addRemoveThreadLabelResponse404
+ | addRemoveThreadLabelResponse500
+) & {
+ headers: Headers;
+};
+
+export type addRemoveThreadLabelResponse =
+ | addRemoveThreadLabelResponseSuccess
+ | addRemoveThreadLabelResponseError;
+
+export const getAddRemoveThreadLabelUrl = (id: string) => {
+ return `/email/threads/${id}/labels`;
+};
+
+export const addRemoveThreadLabel = async (
+ id: string,
+ updateThreadLabelRequest: UpdateThreadLabelRequest,
+ options?: RequestInit
+): Promise<addRemoveThreadLabelResponse> => {
+ const res = await fetch(getAddRemoveThreadLabelUrl(id), {
+ ...options,
+ method: 'PATCH',
+ headers: { 'Content-Type': 'application/json', ...options?.headers },
+ body: JSON.stringify(updateThreadLabelRequest),
+ });
+
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
+
+ const data: addRemoveThreadLabelResponse['data'] = body
+ ? JSON.parse(body)
+ : {};
+ return {
+ data,
+ status: res.status,
+ headers: res.headers,
+ } as addRemoveThreadLabelResponse;
+};
+
export type getThreadMessagesHandlerResponse200 = {
data: ParsedMessage[];
status: 200;
diff --git a/js/app/packages/service-clients/service-email/generated/schemas/index.ts b/js/app/packages/service-clients/service-email/generated/schemas/index.ts
index c6f4d8a7bc..295dcd6548 100644
--- a/js/app/packages/service-clients/service-email/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-email/generated/schemas/index.ts
@@ -184,6 +184,7 @@ export * from './threadProviderId';
export * from './threadSummary';
export * from './updateLabelBatchRequest';
export * from './updateLabelBatchResponse';
+export * from './updateThreadLabelRequest';
export * from './upsertScheduledRequest';
export * from './upsertScheduledResponse';
export * from './userProvider';
diff --git a/js/app/packages/service-clients/service-email/generated/schemas/updateThreadLabelRequest.ts b/js/app/packages/service-clients/service-email/generated/schemas/updateThreadLabelRequest.ts
new file mode 100644
index 0000000000..12a575b548
--- /dev/null
+++ b/js/app/packages/service-clients/service-email/generated/schemas/updateThreadLabelRequest.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * email_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+export interface UpdateThreadLabelRequest {
+ label_id: string;
+ value: boolean;
+}
diff --git a/js/app/packages/service-clients/service-email/openapi.json b/js/app/packages/service-clients/service-email/openapi.json
index 1925a2a50b..565a84463c 100644
--- a/js/app/packages/service-clients/service-email/openapi.json
+++ b/js/app/packages/service-clients/service-email/openapi.json
@@ -1912,6 +1912,87 @@
}
}
},
+ "/email/threads/{id}/labels": {
+ "patch": {
+ "tags": ["Threads"],
+ "summary": "Add or remove a label from all messages in a thread",
+ "operationId": "add_remove_thread_label",
+ "parameters": [
+ {
+ "name": "id",
+ "in": "path",
+ "description": "Thread ID.",
+ "required": true,
+ "schema": {
+ "type": "string",
+ "format": "uuid"
+ }
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/UpdateThreadLabelRequest"
+ }
+ }
+ },
+ "required": true
+ },
+ "responses": {
+ "200": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/UpdateLabelBatchResponse"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "401": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "404": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/email/threads/{id}/messages": {
"get": {
"tags": ["Threads"],
@@ -3707,6 +3788,19 @@
}
}
},
+ "UpdateThreadLabelRequest": {
+ "type": "object",
+ "required": ["label_id", "value"],
+ "properties": {
+ "label_id": {
+ "type": "string",
+ "format": "uuid"
+ },
+ "value": {
+ "type": "boolean"
+ }
+ }
+ },
"UpsertScheduledRequest": {
"type": "object",
"required": ["send_time"],
diff --git a/rust/cloud-storage/email_service/src/api/email/threads/labels.rs b/rust/cloud-storage/email_service/src/api/email/threads/labels.rs
new file mode 100644
index 0000000000..03755519d5
--- /dev/null
+++ b/rust/cloud-storage/email_service/src/api/email/threads/labels.rs
@@ -0,0 +1,141 @@
+use crate::api::context::ApiContext;
+use crate::api::email::messages::labels::{
+ UpdateLabelBatchResponse, add_label_to_messages, remove_label_from_messages,
+};
+use axum::extract::{Path, State};
+use axum::http::StatusCode;
+use axum::response::{IntoResponse, Response};
+use axum::{Extension, Json};
+use model::response::ErrorResponse;
+use model::user::UserContext;
+use models_email::service;
+use models_email::service::link::Link;
+use sqlx::types::Uuid;
+use strum_macros::AsRefStr;
+use thiserror::Error;
+use utoipa::ToSchema;
+
+#[derive(Debug, Error, AsRefStr)]
+pub enum UpdateThreadLabelError {
+ #[error("Label not found")]
+ LabelNotFound,
+
+ #[error("No messages found for thread")]
+ ThreadEmpty,
+
+ #[error("Internal error")]
+ InternalError(#[from] anyhow::Error),
+}
+
+impl IntoResponse for UpdateThreadLabelError {
+ fn into_response(self) -> Response {
+ let status_code = match &self {
+ UpdateThreadLabelError::LabelNotFound => StatusCode::BAD_REQUEST,
+ UpdateThreadLabelError::ThreadEmpty => StatusCode::NOT_FOUND,
+ UpdateThreadLabelError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
+ };
+
+ (
+ status_code,
+ Json(ErrorResponse {
+ message: self.to_string().as_str(),
+ }),
+ )
+ .into_response()
+ }
+}
+
+#[derive(serde::Serialize, serde::Deserialize, Debug, ToSchema)]
+pub struct UpdateThreadLabelRequest {
+ pub label_id: Uuid,
+ pub value: bool,
+}
+
+/// Add or remove a label from all messages in a thread
+#[utoipa::path(
+ patch,
+ tag = "Threads",
+ path = "/email/threads/{id}/labels",
+ operation_id = "add_remove_thread_label",
+ request_body = UpdateThreadLabelRequest,
+ params(
+ ("id" = Uuid, Path, description = "Thread ID."),
+ ),
+ responses(
+ (status = 200, body=UpdateLabelBatchResponse),
+ (status = 400, body=ErrorResponse),
+ (status = 401, body=ErrorResponse),
+ (status = 404, body=ErrorResponse),
+ (status = 500, body=ErrorResponse),
+ )
+)]
+#[tracing::instrument(skip(ctx, user_context, gmail_token, body), fields(user_id=user_context.user_id, fusionauth_user_id=user_context.fusion_user_id), err)]
+pub async fn handler(
+ State(ctx): State<ApiContext>,
+ user_context: Extension<UserContext>,
+ gmail_token: Extension<String>,
+ link: Extension<Link>,
+ Path(thread_id): Path<Uuid>,
+ Json(body): Json<UpdateThreadLabelRequest>,
+) -> Result<Json<UpdateLabelBatchResponse>, UpdateThreadLabelError> {
+ let label = email_db_client::labels::get::fetch_label_by_id(&ctx.db, body.label_id, link.id)
+ .await?
+ .ok_or(UpdateThreadLabelError::LabelNotFound)?;
+
+ let db_messages =
+ email_db_client::messages::get_simple_messages::get_simple_messages_for_thread(
+ &ctx.db, thread_id, link.id,
+ )
+ .await?;
+
+ if db_messages.is_empty() {
+ return Err(UpdateThreadLabelError::ThreadEmpty);
+ }
+
+ let gmail_access_token = gmail_token.as_str();
+
+ let (successful_ids, failed_ids) = if body.value {
+ add_label_to_messages(
+ &ctx.db,
+ gmail_access_token,
+ &ctx.gmail_client,
+ db_messages,
+ label.provider_label_id.as_str(),
+ )
+ .await?
+ } else {
+ remove_label_from_messages(
+ &ctx.db,
+ gmail_access_token,
+ &ctx.gmail_client,
+ db_messages,
+ label.provider_label_id.as_str(),
+ )
+ .await?
+ };
+
+ // need to update flags on message object for certain labels
+ if label.provider_label_id.as_str() == service::label::system_labels::UNREAD {
+ email_db_client::messages::update::update_message_read_status_batch(
+ &ctx.db,
+ successful_ids.clone(),
+ &user_context.fusion_user_id,
+ !body.value,
+ )
+ .await?;
+ } else if label.provider_label_id.as_str() == service::label::system_labels::STARRED {
+ email_db_client::messages::update::update_message_starred_status_batch(
+ &ctx.db,
+ successful_ids.clone(),
+ &user_context.fusion_user_id,
+ body.value,
+ )
+ .await?;
+ }
+
+ Ok(Json(UpdateLabelBatchResponse {
+ successful_ids,
+ failed_ids,
+ missing_ids: vec![],
+ }))
+}
diff --git a/rust/cloud-storage/email_service/src/api/email/threads/mod.rs b/rust/cloud-storage/email_service/src/api/email/threads/mod.rs
index 6ca892ffc9..0b96a0c197 100644
--- a/rust/cloud-storage/email_service/src/api/email/threads/mod.rs
+++ b/rust/cloud-storage/email_service/src/api/email/threads/mod.rs
@@ -1,5 +1,6 @@
pub(crate) mod archived;
pub(crate) mod get;
+pub(crate) mod labels;
pub(crate) mod seen;
use axum::Router;
@@ -31,6 +32,13 @@ pub fn router(state: ApiContext) -> Router<ApiContext> {
),
)),
)
+ .route(
+ "/:id/labels",
+ patch(labels::handler).layer(axum::middleware::from_fn_with_state(
+ state.clone(),
+ crate::api::middleware::gmail_token::attach_gmail_token,
+ )),
+ )
.layer(axum::middleware::from_fn_with_state(
state.email_service.clone(),
crate::api::middleware::link::attach_link_context,
diff --git a/rust/cloud-storage/email_service/src/api/swagger.rs b/rust/cloud-storage/email_service/src/api/swagger.rs
index 00ae650e8c..df2fb99680 100644
--- a/rust/cloud-storage/email_service/src/api/swagger.rs
+++ b/rust/cloud-storage/email_service/src/api/swagger.rs
@@ -20,6 +20,7 @@ use crate::api::email::messages::send::{SendMessageRequest, SendMessageResponse}
use crate::api::email::settings::patch::{PatchSettingsRequest, PatchSettingsResponse};
use crate::api::email::threads::archived::ArchiveThreadRequest;
use crate::api::email::threads::get::GetThreadResponse;
+use crate::api::email::threads::labels::UpdateThreadLabelRequest;
use crate::api::{email, health};
use ::email::inbound;
use ::email::inbound::{ApiPaginatedThreadCursor, ApiSortMethod, GetPreviewsCursorParams};
@@ -65,6 +66,7 @@ use utoipa::OpenApi;
email::threads::get::get_thread_handler,
email::threads::get::get_thread_messages_handler,
email::threads::archived::archived_handler,
+ email::threads::labels::handler,
inbound::cursor_handler,
email::links::list::list_links_handler,
email::labels::create::handler,
@@ -106,6 +108,7 @@ use utoipa::OpenApi;
// Thread types
GetThreadResponse,
ArchiveThreadRequest,
+ UpdateThreadLabelRequest,
APIThread,
ThreadPreviewCursor,
// Preview types