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.

fix(email): Invalidate thread cache on scheduled send (#1825)

Evan Hutnik7732aa4a1161
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsx
index facd6f764d..abb5c2582f 100644
--- a/js/app/packages/block-email/component/BaseInput.tsx
+++ b/js/app/packages/block-email/component/BaseInput.tsx
@@ -746,14 +746,6 @@ export function BaseInput(props: {
const scheduleMessageMutation = useScheduleMessageMutation({
onSuccess: () => {
toast.success('Email scheduled');
-
- const thread = ctx.thread();
-
- if (!thread?.db_id) return;
-
- queryClient.invalidateQueries({
- queryKey: emailKeys.threadMessages(thread.db_id).queryKey,
- });
},
onError: () => {
toast.failure('Failed to schedule email');
@@ -877,6 +869,7 @@ export function BaseInput(props: {
scheduleMessageMutation.mutate({
draftID: currentDraftID,
sendTime,
+ threadID: currentThread?.db_id,
});
cleanupWatermark();
diff --git a/js/app/packages/block-email/component/Compose.tsx b/js/app/packages/block-email/component/Compose.tsx
index 9317f98fed..09d0c7c9fe 100644
--- a/js/app/packages/block-email/component/Compose.tsx
+++ b/js/app/packages/block-email/component/Compose.tsx
@@ -646,6 +646,7 @@ export function EmailCompose(props: EmailComposeProps) {
scheduleMessageMutation.mutate({
draftID,
sendTime,
+ threadID: saveDraftMutation.data?.draft.thread_db_id ?? undefined,
});
cleanupWatermark();
diff --git a/js/app/packages/queries/email/thread.ts b/js/app/packages/queries/email/thread.ts
index 1b852c4d03..f0e88a997f 100644
--- a/js/app/packages/queries/email/thread.ts
+++ b/js/app/packages/queries/email/thread.ts
@@ -293,7 +293,11 @@ export function useSendMessageMutation(
}));
}
-type ScheduleMessageParams = { draftID: string; sendTime: Date };
+type ScheduleMessageParams = {
+ draftID: string;
+ sendTime: Date;
+ threadID?: string;
+};
/**
* Mutation to send an email message.
@@ -316,7 +320,12 @@ export function useScheduleMessageMutation(
),
...withCallbacks<UpsertScheduledResponse, Error, ScheduleMessageParams>(
{
- onSuccess: () => {
+ onSuccess: (_data, vars) => {
+ if (vars.threadID) {
+ queryClient.invalidateQueries({
+ queryKey: emailKeys.threadMessages(vars.threadID).queryKey,
+ });
+ }
queryClient.invalidateQueries({
queryKey: emailKeys.previews._def,
});