Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(email): show share-menu emails in referencium (#6010)
teofe505b2cf079
diff --git a/.sqlx/query-b2a631a3c9b08b85813839c25a2c7a530010c3a00b2f2d67403bc036af6c8fb5.json b/.sqlx/query-17b62498d6b51217c7d86088a9be84dcca913396bfed619579b89879690c0cc4.jsonsimilarity index 79%rename from .sqlx/query-b2a631a3c9b08b85813839c25a2c7a530010c3a00b2f2d67403bc036af6c8fb5.jsonrename to .sqlx/query-17b62498d6b51217c7d86088a9be84dcca913396bfed619579b89879690c0cc4.jsonindex d3fc4432fe..35df7bd9f0 100644--- a/.sqlx/query-b2a631a3c9b08b85813839c25a2c7a530010c3a00b2f2d67403bc036af6c8fb5.json+++ b/.sqlx/query-17b62498d6b51217c7d86088a9be84dcca913396bfed619579b89879690c0cc4.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n em.source_entity_type,\n em.source_entity_id,\n em.entity_type,\n em.entity_id,\n em.user_id,\n em.created_at\n FROM comms_entity_mentions em\n WHERE em.entity_type = $1\n AND em.entity_id = $2\n AND em.source_entity_type != 'message'\n ORDER BY em.created_at DESC\n ",+ "query": "\n SELECT\n em.source_entity_type,\n em.source_entity_id,\n em.entity_type,\n em.entity_id,\n em.user_id,\n em.created_at\n FROM comms_entity_mentions em\n WHERE em.entity_type = ANY($1)\n AND em.entity_id = $2\n AND em.source_entity_type != 'message'\n ORDER BY em.created_at DESC\n ","describe": {"columns": [{@@ -36,7 +36,7 @@],"parameters": {"Left": [- "Text",+ "TextArray","Text"]},@@ -49,5 +49,5 @@false]},- "hash": "b2a631a3c9b08b85813839c25a2c7a530010c3a00b2f2d67403bc036af6c8fb5"+ "hash": "17b62498d6b51217c7d86088a9be84dcca913396bfed619579b89879690c0cc4"}diff --git a/.sqlx/query-000dcd3c4befc3975adf3bee932023bec273d62d6c2f233c3236ffebbfaf5810.json b/.sqlx/query-2346ae595fc3c16fcd0cbc00d93f363ed3fdb0159871827c63d7e7e4a4e35ef5.jsonsimilarity index 86%rename from .sqlx/query-000dcd3c4befc3975adf3bee932023bec273d62d6c2f233c3236ffebbfaf5810.jsonrename to .sqlx/query-2346ae595fc3c16fcd0cbc00d93f363ed3fdb0159871827c63d7e7e4a4e35ef5.jsonindex 02036afbf1..78a8f13921 100644--- a/.sqlx/query-000dcd3c4befc3975adf3bee932023bec273d62d6c2f233c3236ffebbfaf5810.json+++ b/.sqlx/query-2346ae595fc3c16fcd0cbc00d93f363ed3fdb0159871827c63d7e7e4a4e35ef5.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n a.channel_id AS \"channel_id: uuid::Uuid\",\n c.name AS \"channel_name?\", -- Option<String>\n a.message_id AS \"message_id: uuid::Uuid\",\n m.thread_id AS \"thread_id?: uuid::Uuid\",\n m.sender_id AS \"sender_id!\", -- String\n m.content AS \"message_content!\", -- String\n m.created_at AS \"message_created_at!: chrono::DateTime<chrono::Utc>\",\n a.created_at AS \"attachment_created_at!: chrono::DateTime<chrono::Utc>\"\n FROM comms_attachments a\n JOIN comms_messages m ON a.message_id = m.id\n JOIN comms_channels c ON a.channel_id = c.id\n JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE a.entity_type = $1\n AND a.entity_id = $2\n AND cp.user_id = $3\n AND cp.left_at IS NULL\n AND m.deleted_at IS NULL\n ORDER BY a.created_at DESC\n ",+ "query": "\n SELECT\n a.channel_id AS \"channel_id: uuid::Uuid\",\n c.name AS \"channel_name?\", -- Option<String>\n a.message_id AS \"message_id: uuid::Uuid\",\n m.thread_id AS \"thread_id?: uuid::Uuid\",\n m.sender_id AS \"sender_id!\", -- String\n m.content AS \"message_content!\", -- String\n m.created_at AS \"message_created_at!: chrono::DateTime<chrono::Utc>\",\n a.created_at AS \"attachment_created_at!: chrono::DateTime<chrono::Utc>\"\n FROM comms_attachments a\n JOIN comms_messages m ON a.message_id = m.id\n JOIN comms_channels c ON a.channel_id = c.id\n JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE a.entity_type = ANY($1)\n AND a.entity_id = $2\n AND cp.user_id = $3\n AND cp.left_at IS NULL\n AND m.deleted_at IS NULL\n ORDER BY a.created_at DESC\n ","describe": {"columns": [{@@ -46,7 +46,7 @@],"parameters": {"Left": [- "Text",+ "TextArray","Text","Text"]@@ -62,5 +62,5 @@false]},- "hash": "000dcd3c4befc3975adf3bee932023bec273d62d6c2f233c3236ffebbfaf5810"+ "hash": "2346ae595fc3c16fcd0cbc00d93f363ed3fdb0159871827c63d7e7e4a4e35ef5"}diff --git a/.sqlx/query-eda8f3dae4d58225307ad036c6a19e0d6bef4a3d9ea2791d75799c93b4f2350f.json b/.sqlx/query-83738f54a7c60ab63b5a34bbe91fbc9d5a6ae437ae40ce93363db4b96c0ff314.jsonsimilarity index 87%rename from .sqlx/query-eda8f3dae4d58225307ad036c6a19e0d6bef4a3d9ea2791d75799c93b4f2350f.jsonrename to .sqlx/query-83738f54a7c60ab63b5a34bbe91fbc9d5a6ae437ae40ce93363db4b96c0ff314.jsonindex bb45b730c4..038dd7c829 100644--- a/.sqlx/query-eda8f3dae4d58225307ad036c6a19e0d6bef4a3d9ea2791d75799c93b4f2350f.json+++ b/.sqlx/query-83738f54a7c60ab63b5a34bbe91fbc9d5a6ae437ae40ce93363db4b96c0ff314.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n m.channel_id AS \"channel_id: uuid::Uuid\",\n c.name AS \"channel_name?\", -- Option<String>\n m.id AS \"message_id: uuid::Uuid\",\n m.thread_id AS \"thread_id?: uuid::Uuid\",\n m.sender_id AS \"sender_id!\", -- String\n m.content AS \"message_content!\", -- String\n m.created_at AS \"message_created_at!: chrono::DateTime<chrono::Utc>\",\n em.created_at AS \"attachment_created_at!: chrono::DateTime<chrono::Utc>\"\n FROM comms_entity_mentions em\n JOIN comms_messages m ON (em.source_entity_id = m.id::text AND em.source_entity_type = 'message')\n JOIN comms_channels c ON m.channel_id = c.id\n JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE em.entity_type = $1\n AND em.entity_id = $2\n AND cp.user_id = $3\n AND cp.left_at IS NULL\n AND m.deleted_at IS NULL\n ORDER BY em.created_at DESC\n ",+ "query": "\n SELECT\n m.channel_id AS \"channel_id: uuid::Uuid\",\n c.name AS \"channel_name?\", -- Option<String>\n m.id AS \"message_id: uuid::Uuid\",\n m.thread_id AS \"thread_id?: uuid::Uuid\",\n m.sender_id AS \"sender_id!\", -- String\n m.content AS \"message_content!\", -- String\n m.created_at AS \"message_created_at!: chrono::DateTime<chrono::Utc>\",\n em.created_at AS \"attachment_created_at!: chrono::DateTime<chrono::Utc>\"\n FROM comms_entity_mentions em\n JOIN comms_messages m ON (em.source_entity_id = m.id::text AND em.source_entity_type = 'message')\n JOIN comms_channels c ON m.channel_id = c.id\n JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE em.entity_type = ANY($1)\n AND em.entity_id = $2\n AND cp.user_id = $3\n AND cp.left_at IS NULL\n AND m.deleted_at IS NULL\n ORDER BY em.created_at DESC\n ","describe": {"columns": [{@@ -46,7 +46,7 @@],"parameters": {"Left": [- "Text",+ "TextArray","Text","Text"]@@ -62,5 +62,5 @@false]},- "hash": "eda8f3dae4d58225307ad036c6a19e0d6bef4a3d9ea2791d75799c93b4f2350f"+ "hash": "83738f54a7c60ab63b5a34bbe91fbc9d5a6ae437ae40ce93363db4b96c0ff314"}diff --git a/apps/web/src/lib/core/component/ForwardToChannel.tsx b/apps/web/src/lib/core/component/ForwardToChannel.tsxindex db4de3ac5d..708f2fea51 100644--- a/apps/web/src/lib/core/component/ForwardToChannel.tsx+++ b/apps/web/src/lib/core/component/ForwardToChannel.tsx@@ -20,7 +20,10 @@ import { useSendMessageToPeople } from '@core/util/channels';import { getDestinationFromOptions } from '@core/util/destination';import CheckIcon from '@phosphor/check.svg?component-solid';import PaperPlaneTilt from '@phosphor/paper-plane-tilt.svg';-import { blockNameToItemType } from '@service-storage/client';+import {+ blockNameToItemType,+ itemTypeToReferenceEntityType,+} from '@service-storage/client';import type { AccessLevel } from '@service-storage/generated/schemas/accessLevel';import type { SharePermissionV2ChannelSharePermissions } from '@service-storage/generated/schemas/sharePermissionV2ChannelSharePermissions';import { Button, cn, Hotkey } from '@ui';@@ -278,11 +281,13 @@ export function ForwardToChannel(props: ForwardToChannelProps) {const blockName = useMaybeBlockAliasedName() ?? props.blockName;const blockId = useMaybeBlockId() ?? props.blockId;+ const itemType = () =>+ blockName != null ? blockNameToItemType(blockName) : undefined;+const asAttachment = () => {- const itemType =- blockName != null ? blockNameToItemType(blockName) : undefined;+ const type = itemType();return {- entity_type: itemType ?? 'unknown',+ entity_type: type ? itemTypeToReferenceEntityType(type) : 'unknown',entity_id: blockId ?? '',};};@@ -290,7 +295,7 @@ export function ForwardToChannel(props: ForwardToChannelProps) {const trackForwardShare = (targetType: 'channel' | 'user') => {const attachment = asAttachment();analytics.track('share_entity', {- entityType: attachment.entity_type,+ entityType: itemType() ?? attachment.entity_type,entityId: attachment.entity_id || undefined,shareMethod: 'forward',targetType,diff --git a/apps/web/src/lib/service-clients/service-storage/client.ts b/apps/web/src/lib/service-clients/service-storage/client.tsindex b8b7f090d7..9b6230950f 100644--- a/apps/web/src/lib/service-clients/service-storage/client.ts+++ b/apps/web/src/lib/service-clients/service-storage/client.ts@@ -165,6 +165,7 @@ import { saveDocumentHandlerResponse } from './generated/zod';import type { ItemType } from './itemType';export type { ItemType } from './itemType';+export { itemTypeToReferenceEntityType } from './itemType';import type {CollabSurfaceResponse,diff --git a/apps/web/src/lib/service-clients/service-storage/itemType.test.ts b/apps/web/src/lib/service-clients/service-storage/itemType.test.tsnew file mode 100644index 0000000000..ecab2c3737--- /dev/null+++ b/apps/web/src/lib/service-clients/service-storage/itemType.test.ts@@ -0,0 +1,22 @@+import { describe, expect, test } from 'vitest';+import { type ItemType, itemTypeToReferenceEntityType } from './itemType';++describe('itemTypeToReferenceEntityType', () => {+ test('maps email to the thread type used by referencium', () => {+ expect(itemTypeToReferenceEntityType('email')).toBe('thread');+ });++ test.each([+ 'document',+ 'chat',+ 'project',+ 'channel',+ 'call',+ 'calendar_event',+ ] as const satisfies readonly ItemType[])(+ 'leaves %s unchanged',+ (itemType) => {+ expect(itemTypeToReferenceEntityType(itemType)).toBe(itemType);+ }+ );+});diff --git a/apps/web/src/lib/service-clients/service-storage/itemType.ts b/apps/web/src/lib/service-clients/service-storage/itemType.tsindex 4d6bad6819..b9a668e7bd 100644--- a/apps/web/src/lib/service-clients/service-storage/itemType.ts+++ b/apps/web/src/lib/service-clients/service-storage/itemType.ts@@ -14,6 +14,17 @@ export type ItemType =| 'crm_company'| 'crm_contact';+/**+ * Entity type stored on channel attachments, mentions, and referencium.+ *+ * Email threads are `thread` in that system (`ReferencedShareItemType::EmailThread`).+ * Mentions already map `email` → `thread`; share-menu attachments must do the same+ * or they will not appear in the references side panel.+ */+export function itemTypeToReferenceEntityType(itemType: ItemType): string {+ return itemType === 'email' ? 'thread' : itemType;+}+/** Item types accepted by user history endpoints. */export const ITEM_TYPES = ['document',diff --git a/crates/channels/src/domain/models.rs b/crates/channels/src/domain/models.rsindex 2cd4d6f7e3..7bc1a25c37 100644--- a/crates/channels/src/domain/models.rs+++ b/crates/channels/src/domain/models.rs@@ -833,7 +833,7 @@ impl ReferencedShareItemType {"document" => Some(Self::Document),"chat" => Some(Self::Chat),"project" => Some(Self::Project),- "thread" => Some(Self::EmailThread),+ "thread" | "email" | "email_thread" => Some(Self::EmailThread),"call" => Some(Self::Call),_ => None,}@@ -849,6 +849,21 @@ impl ReferencedShareItemType {Self::Call => "call",}}++ /// Entity-type strings that should match when looking up references.+ ///+ /// Mentions store email threads as `"thread"`. The share menu historically+ /// stored `"email"`, so lookups treat those aliases as the same entity.+ pub fn reference_lookup_types(entity_type: &str) -> Vec<String> {+ match Self::from_raw(entity_type) {+ Some(Self::EmailThread) => vec![+ "thread".to_string(),+ "email".to_string(),+ "email_thread".to_string(),+ ],+ _ => vec![entity_type.to_string()],+ }+ }}/// Shareable item referenced by a channel message.@@ -1455,3 +1470,6 @@ pub struct DeleteEntityMentionResponse {/// Whether the mention was deleted.pub deleted: bool,}++#[cfg(test)]+mod test;diff --git a/crates/channels/src/domain/models/test.rs b/crates/channels/src/domain/models/test.rsnew file mode 100644index 0000000000..d0ad9b586a--- /dev/null+++ b/crates/channels/src/domain/models/test.rs@@ -0,0 +1,39 @@+use super::ReferencedShareItemType;++#[test]+fn from_raw_accepts_email_aliases_as_thread() {+ assert_eq!(+ ReferencedShareItemType::from_raw("thread"),+ Some(ReferencedShareItemType::EmailThread)+ );+ assert_eq!(+ ReferencedShareItemType::from_raw("email"),+ Some(ReferencedShareItemType::EmailThread)+ );+ assert_eq!(+ ReferencedShareItemType::from_raw("email_thread"),+ Some(ReferencedShareItemType::EmailThread)+ );+ assert_eq!(ReferencedShareItemType::EmailThread.as_str(), "thread");+}++#[test]+fn from_raw_rejects_unknown_types() {+ assert_eq!(ReferencedShareItemType::from_raw("unknown"), None);+ assert_eq!(ReferencedShareItemType::from_raw(""), None);+}++#[test]+fn reference_lookup_types_include_email_aliases_for_threads() {+ for requested in ["thread", "email", "email_thread"] {+ let types = ReferencedShareItemType::reference_lookup_types(requested);+ assert!(types.contains(&"thread".to_string()), "{requested}");+ assert!(types.contains(&"email".to_string()), "{requested}");+ assert!(types.contains(&"email_thread".to_string()), "{requested}");+ }++ assert_eq!(+ ReferencedShareItemType::reference_lookup_types("document"),+ vec!["document".to_string()]+ );+}diff --git a/crates/channels/src/domain/service/test.rs b/crates/channels/src/domain/service/test.rsindex 5c345ae677..fa8f1568aa 100644--- a/crates/channels/src/domain/service/test.rs+++ b/crates/channels/src/domain/service/test.rs@@ -1053,6 +1053,41 @@ async fn post_message_emits_message_posted_event_and_updates_share_permissions());}+#[tokio::test]+async fn post_message_treats_email_attachments_as_thread_share_items() {+ let channel_id = Uuid::new_v4();+ let repo = FakeMutationRepo::new(channel_id, "macro|[email protected]");+ let share = FakeReferenceSharing::default();+ let svc = mutation_service(repo, FakeEvents::default(), share.clone());++ svc.post_message(+ sender("macro|[email protected]"),+ channel_id,+ PostMessageRequest {+ content: "sharing an email".to_string(),+ mentions: vec![],+ thread_id: None,+ attachments: vec![NewChannelAttachment {+ entity_type: "email".to_string(),+ entity_id: "thread-1".to_string(),+ width: None,+ height: None,+ }],+ nonce: None,+ notification_policy: Default::default(),+ triggered_by: None,+ },+ )+ .await+ .unwrap();++ let shared = share.items.lock().unwrap();+ assert!(shared.contains(&ReferencedShareItem::new(+ "thread-1",+ ReferencedShareItemType::EmailThread+ )));+}+#[tokio::test]async fn post_message_ignores_channel_touch_errors() {let channel_id = Uuid::new_v4();diff --git a/crates/channels/src/outbound/pg_channels_repo.rs b/crates/channels/src/outbound/pg_channels_repo.rsindex 90b71c8b39..ae3185041b 100644--- a/crates/channels/src/outbound/pg_channels_repo.rs+++ b/crates/channels/src/outbound/pg_channels_repo.rs@@ -15,9 +15,9 @@ use crate::domain::{CreateChannelRequest, CreateEntityMentionOptions, CreatedChannel, EntityMention,GetChannelsParams, GetThreadReplyRowsParams, LatestMessage, MessageAttachment,MessagePageDirection, MutatedAttachment, MutatedMessage, NameLookup, NewChannelAttachment,- ParticipantRole, PatchChannelRequest, RecentChannelMessage, ResolvedChannelMessage,- SimpleMention, ThreadData, ThreadInfo, ThreadReply, ThreadReplyRow, TopLevelMessageRow,- UserName, fallback_user_name,+ ParticipantRole, PatchChannelRequest, RecentChannelMessage, ReferencedShareItemType,+ ResolvedChannelMessage, SimpleMention, ThreadData, ThreadInfo, ThreadReply, ThreadReplyRow,+ TopLevelMessageRow, UserName, fallback_user_name,},ports::{ChannelRepo, TopLevelMessagesQueryResult},};@@ -2354,6 +2354,7 @@ impl ChannelRepo for PgChannelsRepo {entity_id: &str,user_id: &str,) -> Result<Vec<AttachmentEntityReference>, Self::Err> {+ let entity_types = ReferencedShareItemType::reference_lookup_types(entity_type);let attachment_references_fut = async {sqlx::query_as!(AttachmentChannelReference,@@ -2371,14 +2372,14 @@ impl ChannelRepo for PgChannelsRepo {JOIN comms_messages m ON a.message_id = m.idJOIN comms_channels c ON a.channel_id = c.idJOIN comms_channel_participants cp ON cp.channel_id = c.id- WHERE a.entity_type = $1+ WHERE a.entity_type = ANY($1)AND a.entity_id = $2AND cp.user_id = $3AND cp.left_at IS NULLAND m.deleted_at IS NULLORDER BY a.created_at DESC"#,- entity_type,+ &entity_types,entity_id,user_id,)@@ -2404,14 +2405,14 @@ impl ChannelRepo for PgChannelsRepo {JOIN comms_messages m ON (em.source_entity_id = m.id::text AND em.source_entity_type = 'message')JOIN comms_channels c ON m.channel_id = c.idJOIN comms_channel_participants cp ON cp.channel_id = c.id- WHERE em.entity_type = $1+ WHERE em.entity_type = ANY($1)AND em.entity_id = $2AND cp.user_id = $3AND cp.left_at IS NULLAND m.deleted_at IS NULLORDER BY em.created_at DESC"#,- entity_type,+ &entity_types,entity_id,user_id,)@@ -2431,12 +2432,12 @@ impl ChannelRepo for PgChannelsRepo {em.user_id,em.created_atFROM comms_entity_mentions em- WHERE em.entity_type = $1+ WHERE em.entity_type = ANY($1)AND em.entity_id = $2AND em.source_entity_type != 'message'ORDER BY em.created_at DESC"#,- entity_type,+ &entity_types,entity_id,).fetch_all(&self.pool)@@ -3354,6 +3355,9 @@ impl ChannelRepo for PgChannelsRepo {let mut inserted = Vec::with_capacity(attachments.len());for attachment in attachments {+ let entity_type = ReferencedShareItemType::from_raw(&attachment.entity_type)+ .map(ReferencedShareItemType::as_str)+ .unwrap_or(attachment.entity_type.as_str());let row = sqlx::query_as!(MutatedAttachmentRow,r#"@@ -3372,7 +3376,7 @@ impl ChannelRepo for PgChannelsRepo {macro_uuid::generate_uuid_v7(),message_id,channel_id,- attachment.entity_type,+ entity_type,attachment.entity_id,attachment.width,attachment.height,diff --git a/crates/channels/src/outbound/pg_channels_repo/tests.rs b/crates/channels/src/outbound/pg_channels_repo/tests.rsindex 9696de26d1..0b0af16f7d 100644--- a/crates/channels/src/outbound/pg_channels_repo/tests.rs+++ b/crates/channels/src/outbound/pg_channels_repo/tests.rs@@ -1,8 +1,8 @@use crate::domain::models::{AttachmentEntityReference, BotId, BotSenderProfile, ChannelMessageFilters, ChannelType,ChannelWithParticipants, CreateChannelRequest, CreateEntityMentionOptions, GetChannelsParams,- GetChannelsRequest, GetThreadReplyRowsRequest, MessagePageDirection, NotificationFilters,- ParticipantRole, PatchChannelRequest,+ GetChannelsRequest, GetThreadReplyRowsRequest, MessagePageDirection, NewChannelAttachment,+ NotificationFilters, ParticipantRole, PatchChannelRequest,};use crate::domain::ports::{ChannelListRepo, ChannelRepo};use crate::outbound::pg_channels_repo::PgChannelsRepo;@@ -2878,6 +2878,71 @@ async fn attachment_references_merges_channel_and_generic_newest_first(Ok(())}+#[sqlx::test(+ fixtures(path = "../../../fixtures", scripts("channels_repo")),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn attachment_references_treats_email_alias_as_thread(+ pool: Pool<Postgres>,+) -> anyhow::Result<()> {+ // Share-menu attachments historically stored entity_type = 'email'.+ // Referencium queries 'thread', so the lookup must accept both.+ sqlx::query(+ r#"+ INSERT INTO comms_attachments (id, message_id, channel_id, entity_type, entity_id, width, height, created_at)+ VALUES (+ '00000000-0000-0000-0000-00000000a0e1',+ '00000000-0000-0000-0000-000000000001',+ '00000000-0000-0000-0000-000000000c01',+ 'email',+ 'email-share-1',+ NULL,+ NULL,+ '2024-01-01 10:05:00+00'+ )+ "#,+ )+ .execute(&pool)+ .await?;++ let repo = repo(pool);+ let by_thread = repo+ .get_attachment_references("thread", "email-share-1", USER_A)+ .await?;+ let by_email = repo+ .get_attachment_references("email", "email-share-1", USER_A)+ .await?;++ assert_eq!(channel_refs(&by_thread).len(), 1);+ assert_eq!(channel_refs(&by_email).len(), 1);+ assert_eq!(channel_refs(&by_thread)[0].message_id, MSG1);+ Ok(())+}++#[sqlx::test(+ fixtures(path = "../../../fixtures", scripts("channels_repo")),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn add_attachments_normalizes_email_to_thread(pool: Pool<Postgres>) -> anyhow::Result<()> {+ let inserted = repo(pool)+ .add_attachments(+ MSG1,+ CH1,+ vec![NewChannelAttachment {+ entity_type: "email".to_string(),+ entity_id: "email-norm-1".to_string(),+ width: None,+ height: None,+ }],+ )+ .await?;++ assert_eq!(inserted.len(), 1);+ assert_eq!(inserted[0].entity_type, "thread");+ assert_eq!(inserted[0].entity_id, "email-norm-1");+ Ok(())+}+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]async fn bot_profiles_includes_soft_deleted_bots(pool: Pool<Postgres>) -> anyhow::Result<()> {let active = Uuid::new_v4();