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(channels): patch message take new attachments (#2783)

teoea8d6afb0214
diff --git a/js/app/package.json b/js/app/package.json
index 1f21e29908..5a971798fd 100644
--- a/js/app/package.json
+++ b/js/app/package.json
@@ -141,7 +141,7 @@
"knip": "^6.0.4",
"lightningcss": "^1.30.2",
"openai": "^6.25.0",
- "orval": "^7.13.0",
+ "orval": "^7.21.0",
"typescript": "^5.9.3",
"vite": "^6.4.1",
"vite-plugin-solid": "^2.11.8",
diff --git a/js/app/packages/channel/Channel/create-message-editor.ts b/js/app/packages/channel/Channel/create-message-editor.ts
index 94838d4f50..b9a0319bf8 100644
--- a/js/app/packages/channel/Channel/create-message-editor.ts
+++ b/js/app/packages/channel/Channel/create-message-editor.ts
@@ -1,11 +1,13 @@
import { toast } from '@core/component/Toast/Toast';
import { createSignal, type Accessor } from 'solid-js';
import type { InputSnapshot } from '@channel/Input';
+import type { NewAttachment } from '@service-comms/generated/models/newAttachment';
import type { MessageData } from '../Message';
import type { MessageEditState } from '../Thread/types';
import {
buildMessageEditSnapshot,
getAttachmentIdsToDelete,
+ getAttachmentsToAdd,
} from './message-editing';
type PatchMessageInput = {
@@ -13,6 +15,7 @@ type PatchMessageInput = {
messageID: string;
content: string;
attachmentIDsToDelete?: string[];
+ attachmentsToAdd?: NewAttachment[];
};
type CreateMessageEditorOptions = {
@@ -64,9 +67,15 @@ export function createMessageEditor(
nextSnapshot: snapshot,
});
+ const newAttachments = getAttachmentsToAdd({
+ currentAttachments: message.attachments,
+ nextSnapshot: snapshot,
+ });
+
const hasContentChanged = nextContent !== message.content;
- const hasRemovedAttachments = attachmentIDsToDelete.length > 0;
- if (!hasContentChanged && !hasRemovedAttachments) {
+ const hasAttachmentChanges =
+ attachmentIDsToDelete.length > 0 || newAttachments.length > 0;
+ if (!hasContentChanged && !hasAttachmentChanges) {
setEditState(undefined);
return;
}
@@ -76,6 +85,7 @@ export function createMessageEditor(
messageID: message.id,
content: nextContent,
attachmentIDsToDelete,
+ attachmentsToAdd: newAttachments.length > 0 ? newAttachments : undefined,
});
setEditState(undefined);
};
diff --git a/js/app/packages/channel/Channel/message-editing.ts b/js/app/packages/channel/Channel/message-editing.ts
index cd013bffdf..fb49042b86 100644
--- a/js/app/packages/channel/Channel/message-editing.ts
+++ b/js/app/packages/channel/Channel/message-editing.ts
@@ -5,7 +5,9 @@ import {
STATIC_VIDEO,
} from '@core/store/cacheChannelInput';
import type { ApiMessageAttachment } from '@service-storage/generated/schemas/apiMessageAttachment';
-import type { InputAttachmentData, InputSnapshot } from '../Input';
+import type { NewAttachment } from '@service-comms/generated/models/newAttachment';
+import { attachmentEntityType } from '../Input/message-payload';
+import type { InputAttachmentData, InputSnapshot } from '../Input/types';
import type { MessageData } from '../Message';
function toInputAttachmentKind(
@@ -55,3 +57,21 @@ export function getAttachmentIdsToDelete(args: {
.filter((attachment) => !nextAttachmentIds.has(attachment.entity_id))
.map((attachment) => attachment.id);
}
+
+export function getAttachmentsToAdd(args: {
+ currentAttachments: ApiMessageAttachment[];
+ nextSnapshot: InputSnapshot;
+}): NewAttachment[] {
+ const currentIds = new Set(
+ args.currentAttachments.map((attachment) => attachment.entity_id)
+ );
+
+ return args.nextSnapshot.attachments
+ .filter((attachment) => !currentIds.has(attachment.id))
+ .map((attachment) => ({
+ entity_id: attachment.id,
+ entity_type: attachmentEntityType(attachment.kind),
+ width: attachment.width ?? null,
+ height: attachment.height ?? null,
+ }));
+}
diff --git a/js/app/packages/channel/Channel/tests/message-editing.test.ts b/js/app/packages/channel/Channel/tests/message-editing.test.ts
new file mode 100644
index 0000000000..d66d4c3e61
--- /dev/null
+++ b/js/app/packages/channel/Channel/tests/message-editing.test.ts
@@ -0,0 +1,89 @@
+import { describe, expect, it, vi } from 'vitest';
+import type { ApiMessageAttachment } from '@service-storage/generated/schemas/apiMessageAttachment';
+import type { InputAttachmentData, InputSnapshot } from '../../Input/types';
+
+vi.mock('@core/store/cacheChannelInput', () => ({
+ STATIC_IMAGE: 'static/image',
+ STATIC_VIDEO: 'static/video',
+ isStaticAttachmentType: (v: string) =>
+ v === 'static/image' || v === 'static/video',
+}));
+
+vi.mock('@core/constant/allBlocks', () => ({
+ fileTypeToBlockName: () => undefined,
+}));
+
+import {
+ getAttachmentIdsToDelete,
+ getAttachmentsToAdd,
+} from '../message-editing';
+
+function attachment(
+ overrides: Partial<ApiMessageAttachment> & { entity_id: string }
+): ApiMessageAttachment {
+ return {
+ id: `att-${overrides.entity_id}`,
+ entity_type: 'document',
+ created_at: '2026-01-01T00:00:00Z',
+ ...overrides,
+ };
+}
+
+function inputAttachment(
+ overrides: Partial<InputAttachmentData> & { id: string }
+): InputAttachmentData {
+ return {
+ name: overrides.id,
+ kind: 'document',
+ ...overrides,
+ };
+}
+
+function snapshot(attachments: InputAttachmentData[]): InputSnapshot {
+ return { value: '', mentions: [], attachments };
+}
+
+describe('getAttachmentsToAdd', () => {
+ it('maps each kind to the correct entity type', () => {
+ const result = getAttachmentsToAdd({
+ currentAttachments: [],
+ nextSnapshot: snapshot([
+ inputAttachment({ id: 'img', kind: 'image' }),
+ inputAttachment({ id: 'vid', kind: 'video' }),
+ inputAttachment({ id: 'doc', kind: 'document' }),
+ ]),
+ });
+ expect(result.map((a) => [a.entity_id, a.entity_type])).toEqual([
+ ['img', 'static/image'],
+ ['vid', 'static/video'],
+ ['doc', 'document'],
+ ]);
+ });
+
+ it('handles simultaneous add and delete', () => {
+ const current = [
+ attachment({ entity_id: 'a' }),
+ attachment({ entity_id: 'b' }),
+ ];
+ const next = snapshot([
+ inputAttachment({ id: 'a' }),
+ inputAttachment({ id: 'c', kind: 'image', width: 100, height: 200 }),
+ ]);
+ expect(
+ getAttachmentIdsToDelete({
+ currentAttachments: current,
+ nextSnapshot: next,
+ })
+ ).toEqual(['att-b']);
+ expect(
+ getAttachmentsToAdd({ currentAttachments: current, nextSnapshot: next })
+ ).toEqual([
+ {
+ entity_id: 'c',
+ entity_type: 'static/image',
+ width: 100,
+ height: 200,
+ },
+ ]);
+ });
+});
diff --git a/js/app/packages/channel/Input/index.ts b/js/app/packages/channel/Input/index.ts
index 8b0c6d1ace..3f8e280ef1 100644
--- a/js/app/packages/channel/Input/index.ts
+++ b/js/app/packages/channel/Input/index.ts
@@ -5,7 +5,10 @@ export { createInputAttachmentTracker } from './attachment-tracker';
export { createInputState } from './create-input-state';
export { createConfiguredChannelMarkdownEditor } from './configured-markdown-editor';
export { createMentionsTracker } from './mentions-tracker';
-export { buildPostMessageRequest } from './message-payload';
+export {
+ buildPostMessageRequest,
+ attachmentEntityType,
+} from './message-payload';
export { uploadInputAttachments } from './upload-attachments';
export { Root } from './Root';
diff --git a/js/app/packages/channel/Input/message-payload.ts b/js/app/packages/channel/Input/message-payload.ts
index 91d151740e..c70dd050f7 100644
--- a/js/app/packages/channel/Input/message-payload.ts
+++ b/js/app/packages/channel/Input/message-payload.ts
@@ -5,10 +5,10 @@ import type { SimpleMention } from '@service-comms/generated/models/simpleMentio
import type { InputAttachmentData, InputSnapshot } from './types';
import { match } from 'ts-pattern';
-function attachmentEntityType(
- attachment: Pick<InputAttachmentData, 'kind'>
+export function attachmentEntityType(
+ kind: InputAttachmentData['kind']
): string {
- switch (attachment.kind) {
+ switch (kind) {
case 'image':
return STATIC_IMAGE;
case 'video':
@@ -86,7 +86,7 @@ export function buildPostMessageRequest(
mentions: expandMentions(snapshot.mentions, participantIds ?? []),
attachments: snapshot.attachments.map((attachment) => ({
entity_id: attachment.id,
- entity_type: attachmentEntityType(attachment),
+ entity_type: attachmentEntityType(attachment.kind),
width: attachment.width ?? null,
height: attachment.height ?? null,
})),
diff --git a/js/app/packages/queries/channel/message.ts b/js/app/packages/queries/channel/message.ts
index 6b1f8dfb16..2251f6eb41 100644
--- a/js/app/packages/queries/channel/message.ts
+++ b/js/app/packages/queries/channel/message.ts
@@ -15,6 +15,7 @@ import type {
PostMessageRequest,
} from '@service-comms/generated/models';
import type { Attachment, Message } from '@service-comms/generated/models';
+import type { NewAttachment } from '@service-comms/generated/models/newAttachment';
import { useMutation } from '@tanstack/solid-query';
import { queryClient } from '../client';
import { channelKeys, ChannelNonceKeys } from './keys';
@@ -281,6 +282,7 @@ export function optimisticUpdateChannelMessage(
vars: WithChannelId<
Pick<ChannelMessage, 'message_id' | 'content'> & {
attachment_ids_to_delete?: string[];
+ attachments_to_add?: NewAttachment[];
}
>
): UpdateMessageContext | undefined {
@@ -310,13 +312,25 @@ export function optimisticUpdateChannelMessage(
}
if (context) {
+ const kept = context.previousAttachments.filter(
+ (attachment) => !deletedAttachmentIDs.has(attachment.id)
+ );
+ const added: Attachment[] = (vars.attachments_to_add ?? []).map((a) => ({
+ id: crypto.randomUUID(),
+ channel_id: vars.channelId,
+ message_id: vars.message_id,
+ entity_id: a.entity_id,
+ entity_type: a.entity_type,
+ width: a.width,
+ height: a.height,
+ created_at: now,
+ }));
+
replaceTargetMessageState(vars.channelId, target, {
content: vars.content,
editedAt: now,
updatedAt: now,
- attachments: context.previousAttachments.filter(
- (attachment) => !deletedAttachmentIDs.has(attachment.id)
- ),
+ attachments: [...kept, ...added],
});
}
@@ -505,6 +519,7 @@ type PatchMessageParams = {
messageID: string;
content: string;
attachmentIDsToDelete?: string[];
+ attachmentsToAdd?: NewAttachment[];
};
type PatchMutationContext = UpdateMessageContext | undefined;
@@ -535,6 +550,7 @@ export function usePatchMessageMutation(
message_id: vars.messageID,
content: vars.content,
attachment_ids_to_delete: vars.attachmentIDsToDelete,
+ attachments_to_add: vars.attachmentsToAdd,
nonce: patchNonce.use(vars),
})
);
@@ -556,6 +572,7 @@ export function usePatchMessageMutation(
message_id: vars.messageID,
content: vars.content,
attachment_ids_to_delete: vars.attachmentIDsToDelete,
+ attachments_to_add: vars.attachmentsToAdd,
});
},
onError(error, vars, context) {
diff --git a/js/app/packages/service-clients/service-comms/client.ts b/js/app/packages/service-clients/service-comms/client.ts
index 9938e9a0ee..28a2ae50e5 100644
--- a/js/app/packages/service-clients/service-comms/client.ts
+++ b/js/app/packages/service-clients/service-comms/client.ts
@@ -178,14 +178,25 @@ export const commsServiceClient = {
WithChannelId &
WithMessageId & { nonce?: string }
) {
- const { channel_id, content, message_id, attachment_ids_to_delete, nonce } =
- args;
+ const {
+ channel_id,
+ content,
+ message_id,
+ attachment_ids_to_delete,
+ attachments_to_add,
+ nonce,
+ } = args;
return mapOk(
await commsFetch<MessageResponse>(
`/comms/channels/${channel_id}/message/${message_id}`,
{
method: 'PATCH',
- body: JSON.stringify({ content, attachment_ids_to_delete, nonce }),
+ body: JSON.stringify({
+ content,
+ attachment_ids_to_delete,
+ attachments_to_add,
+ nonce,
+ }),
}
),
(result) => result
diff --git a/js/app/packages/service-clients/service-comms/generated/models/index.ts b/js/app/packages/service-clients/service-comms/generated/models/index.ts
index 84bb82f8e7..0bd58e2f81 100644
--- a/js/app/packages/service-clients/service-comms/generated/models/index.ts
+++ b/js/app/packages/service-clients/service-comms/generated/models/index.ts
@@ -105,6 +105,7 @@ export * from './patchChannelOptionsChannelName';
export * from './patchMessageParams';
export * from './patchMessageRequest';
export * from './patchMessageRequestAttachmentIdsToDelete';
+export * from './patchMessageRequestAttachmentsToAdd';
export * from './patchMessageRequestContent';
export * from './patchMessageRequestNonce';
export * from './postActivityRequest';
diff --git a/js/app/packages/service-clients/service-comms/generated/models/patchMessageRequest.ts b/js/app/packages/service-clients/service-comms/generated/models/patchMessageRequest.ts
index 1dfee0bc06..f80fa38bde 100644
--- a/js/app/packages/service-clients/service-comms/generated/models/patchMessageRequest.ts
+++ b/js/app/packages/service-clients/service-comms/generated/models/patchMessageRequest.ts
@@ -5,11 +5,13 @@
* OpenAPI spec version: 0.1.0
*/
import type { PatchMessageRequestAttachmentIdsToDelete } from './patchMessageRequestAttachmentIdsToDelete';
+import type { PatchMessageRequestAttachmentsToAdd } from './patchMessageRequestAttachmentsToAdd';
import type { PatchMessageRequestContent } from './patchMessageRequestContent';
import type { PatchMessageRequestNonce } from './patchMessageRequestNonce';
export interface PatchMessageRequest {
attachment_ids_to_delete?: PatchMessageRequestAttachmentIdsToDelete;
+ attachments_to_add?: PatchMessageRequestAttachmentsToAdd;
content?: PatchMessageRequestContent;
nonce?: PatchMessageRequestNonce;
}
diff --git a/js/app/packages/service-clients/service-comms/generated/models/patchMessageRequestAttachmentsToAdd.ts b/js/app/packages/service-clients/service-comms/generated/models/patchMessageRequestAttachmentsToAdd.ts
new file mode 100644
index 0000000000..0cddb51a8d
--- /dev/null
+++ b/js/app/packages/service-clients/service-comms/generated/models/patchMessageRequestAttachmentsToAdd.ts
@@ -0,0 +1,9 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * comms_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { NewAttachment } from './newAttachment';
+
+export type PatchMessageRequestAttachmentsToAdd = NewAttachment[] | null;
diff --git a/js/app/packages/service-clients/service-comms/openapi.json b/js/app/packages/service-clients/service-comms/openapi.json
index 24d5c26d9d..fe64d33643 100644
--- a/js/app/packages/service-clients/service-comms/openapi.json
+++ b/js/app/packages/service-clients/service-comms/openapi.json
@@ -2532,6 +2532,12 @@
"type": "string"
}
},
+ "attachments_to_add": {
+ "type": ["array", "null"],
+ "items": {
+ "$ref": "#/components/schemas/NewAttachment"
+ }
+ },
"content": {
"type": ["string", "null"]
},
diff --git a/js/bun.lock b/js/bun.lock
index 77d088d67e..26f84b3199 100644
--- a/js/bun.lock
+++ b/js/bun.lock
@@ -132,7 +132,7 @@
"knip": "^6.0.4",
"lightningcss": "^1.30.2",
"openai": "^6.25.0",
- "orval": "^7.13.0",
+ "orval": "^7.21.0",
"typescript": "^5.9.3",
"vite": "^6.4.1",
"vite-plugin-solid": "^2.11.8",
diff --git a/rust/cloud-storage/comms_service/src/api/channels/patch_message.rs b/rust/cloud-storage/comms_service/src/api/channels/patch_message.rs
index 2b0a82f20e..b2d891b89c 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/patch_message.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/patch_message.rs
@@ -16,8 +16,9 @@ use axum::{
use axum_extra::extract::Cached;
use comms_db_client::{
activity::upsert_activity::upsert_activity,
+ messages::add_attachments,
messages::patch_message::{patch_message, patch_message_attachments},
- model::ActivityType,
+ model::{ActivityType, NewAttachment},
};
use macro_user_id::cowlike::CowLike;
use serde::{Deserialize, Serialize};
@@ -28,6 +29,7 @@ use uuid::Uuid;
pub struct PatchMessageRequest {
pub content: Option<String>,
pub attachment_ids_to_delete: Option<Vec<String>>,
+ pub attachments_to_add: Option<Vec<NewAttachment>>,
pub nonce: Option<String>,
}
@@ -65,14 +67,19 @@ pub async fn patch_message_handler(
) -> Result<(StatusCode, String), (StatusCode, String)> {
tracing::info!("patch_message");
- if let Some(attachment_ids) = &req.attachment_ids_to_delete
- && !attachment_ids.is_empty()
- {
- delete_message_attachments(
+ let attachment_ids_to_delete = req.attachment_ids_to_delete.clone().unwrap_or_default();
+ let attachments_to_add = req.attachments_to_add.clone().unwrap_or_default();
+ let attachments_changed =
+ !attachment_ids_to_delete.is_empty() || !attachments_to_add.is_empty();
+
+ if attachments_changed {
+ patch_message_attachments_state(
&app_state,
- attachment_ids.clone(),
+ attachment_ids_to_delete,
+ attachments_to_add,
message_id,
channel_id,
+ &message_sender.user_id,
req.nonce.as_deref(),
)
.await?;
@@ -135,6 +142,26 @@ pub async fn patch_message_handler(
})
.ok();
+ service::search::send_channel_message_to_search_extractor_queue(
+ &app_state.sqs_client,
+ channel_id,
+ &params.message_id,
+ );
+ }
+
+ if attachments_changed && req.content.is_none() {
+ upsert_activity(
+ &app_state.db,
+ &message_sender.user_id,
+ &channel_id,
+ &ActivityType::Interact,
+ )
+ .await
+ .inspect_err(|err| {
+ tracing::error!(error=?err, "unable to upsert activity for message attachment patch");
+ })
+ .ok();
+
service::search::send_channel_message_to_search_extractor_queue(
&app_state.sqs_client,
channel_id,
@@ -145,16 +172,17 @@ pub async fn patch_message_handler(
Ok((StatusCode::OK, "message sent".to_string()))
}
-#[tracing::instrument(skip(ctx))]
-async fn delete_message_attachments(
+#[tracing::instrument(skip(ctx, attachment_ids_to_delete, attachments, user_id), err(Debug))]
+async fn patch_message_attachments_state(
ctx: &AppState,
- attachment_ids: Vec<String>,
+ attachment_ids_to_delete: Vec<String>,
+ attachments: Vec<NewAttachment>,
message_id: Uuid,
channel_id: Uuid,
+ user_id: &str,
nonce: Option<&str>,
) -> Result<(), (StatusCode, String)> {
- // Parse string IDs into UUIDs
- let attachment_uuids = attachment_ids
+ let attachment_uuids = attachment_ids_to_delete
.iter()
.map(|id| Uuid::parse_str(id))
.collect::<Result<Vec<Uuid>, _>>()
@@ -163,85 +191,123 @@ async fn delete_message_attachments(
(StatusCode::BAD_REQUEST, err.to_string())
})?;
- // Get all attachments for the message
- let attachments = comms_db_client::attachments::get_attachments::get_attachments_by_message_id(
- &ctx.db, message_id,
- )
- .await
- .map_err(|err| {
- tracing::error!(error=?err, "unable to fetch attachments");
- (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
- })?;
+ let existing_attachments =
+ comms_db_client::attachments::get_attachments::get_attachments_by_message_id(
+ &ctx.db, message_id,
+ )
+ .await
+ .map_err(|err| {
+ tracing::error!(error=?err, "unable to fetch attachments");
+ (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
+ })?;
- // Filter attachments to only include those that are being deleted
- let attachments_to_delete = attachments
+ let attachments_to_delete = existing_attachments
.iter()
.filter(|a| attachment_uuids.contains(&a.id))
.cloned()
.collect::<Vec<_>>();
- let remaining_attachments = attachments
- .iter()
- .filter(|a| !attachment_uuids.contains(&a.id))
- .cloned()
- .collect::<Vec<_>>();
-
- // If attachment_id is not in the list of attachments to delete, we need to log an error
if attachments_to_delete.len() != attachment_uuids.len() {
- tracing::error!("some attachments were not found: {:?}", attachment_uuids);
+ tracing::error!(attachment_ids=?attachment_uuids, "some attachments were not found");
}
- // Extract validated attachment IDs
let fetched_attachment_ids: Vec<Uuid> = attachments_to_delete.iter().map(|a| a.id).collect();
let fetched_attachments_entity_ids: Vec<String> = attachments_to_delete
.iter()
.map(|a| a.entity_id.clone())
.collect();
- // Delete attachments from database
- comms_db_client::attachments::delete_attachments::delete_attachments_by_ids(
- &ctx.db,
- fetched_attachment_ids,
- )
- .await
- .map_err(|err| {
- tracing::error!(error=?err, "unable to delete attachments");
- (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
- })?;
+ if !fetched_attachment_ids.is_empty() {
+ comms_db_client::attachments::delete_attachments::delete_attachments_by_ids(
+ &ctx.db,
+ fetched_attachment_ids,
+ )
+ .await
+ .map_err(|err| {
+ tracing::error!(error=?err, "unable to delete attachments");
+ (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
+ })?;
- // Remove entity mentions for attachments being removed from message
- comms_db_client::entity_mentions::delete_entity_mentions_by_entity(
- &ctx.db,
- fetched_attachments_entity_ids,
- message_id.to_string(),
- )
- .await
- .map_err(|err| {
- tracing::error!(error=?err, "unable to delete entity mentions");
- (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
- })?;
+ comms_db_client::entity_mentions::delete_entity_mentions_by_entity(
+ &ctx.db,
+ fetched_attachments_entity_ids,
+ message_id.to_string(),
+ )
+ .await
+ .map_err(|err| {
+ tracing::error!(error=?err, "unable to delete entity mentions");
+ (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
+ })?;
+ }
+
+ if !attachments.is_empty() {
+ add_attachments::add_attachments_to_message(
+ &ctx.db,
+ &message_id,
+ &channel_id,
+ attachments.clone(),
+ )
+ .await
+ .map_err(|err| {
+ tracing::error!(error=?err, "unable to add attachments to message");
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ "unable to add attachments to message".to_string(),
+ )
+ })?;
+ }
- // TODO: delete from sfs it's a static file attachment (image)
+ let items_to_share: Vec<(String, String)> = attachments
+ .iter()
+ .filter(|a| a.entity_type != "user")
+ .map(|a| (a.entity_id.clone(), a.entity_type.clone()))
+ .collect();
+
+ if !items_to_share.is_empty() {
+ let channel_id_str = channel_id.to_string();
+ let user_id = user_id.to_owned();
+ let db = ctx.db.clone();
+ let entity_access_service = ctx.entity_access_service.clone();
+ tokio::spawn(async move {
+ super::post_message::update_channel_share_permissions_for_items(
+ &db,
+ &*entity_access_service,
+ &user_id,
+ &channel_id_str,
+ items_to_share,
+ )
+ .await;
+ });
+ }
+
+ let all_attachments =
+ comms_db_client::attachments::get_attachments::get_attachments_by_message_id(
+ &ctx.db, message_id,
+ )
+ .await
+ .map_err(|err| {
+ tracing::error!(error=?err, "unable to fetch attachments after patch");
+ (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
+ })?;
- // Notify about the remaining attachments
notify::notify_attachments(
ctx,
WithNonce {
data: AttachmentData {
channel_id: &channel_id,
message_id: &message_id,
- attachments: &remaining_attachments,
+ attachments: &all_attachments,
},
nonce,
},
)
.await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to notify attachments");
- (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())
+ .map_err(|err| {
+ tracing::error!(error=?err, "unable to notify attachments");
+ (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
})?;
- patch_message_attachments(&ctx.db, message_id, remaining_attachments)
+ patch_message_attachments(&ctx.db, message_id, all_attachments)
.await
.map_err(|err| {
tracing::error!(error=?err, "unable to patch message attachments");
diff --git a/rust/cloud-storage/comms_service/src/api/channels/post_message.rs b/rust/cloud-storage/comms_service/src/api/channels/post_message.rs
index f3efb3278a..f46e97a747 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/post_message.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/post_message.rs
@@ -290,7 +290,7 @@ pub fn dispatch_notification_task(
}
/// Updates channel share permissions for a list of items shared in a message.
-async fn update_channel_share_permissions_for_items(
+pub(super) async fn update_channel_share_permissions_for_items(
db: &PgPool,
entity_access_service: &impl entity_access::domain::ports::EntityAccessService,
user_id: &str,