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
feat(channels): seperate pagination for static vs dss attachment (#2830)
teoc1c7b9ad5b22
diff --git a/js/app/packages/channel/Attachments/ChannelAttachmentEntitySection.tsx b/js/app/packages/channel/Attachments/ChannelAttachmentEntitySection.tsxindex fb8a33f755..14ef3e8718 100644--- a/js/app/packages/channel/Attachments/ChannelAttachmentEntitySection.tsx+++ b/js/app/packages/channel/Attachments/ChannelAttachmentEntitySection.tsx@@ -5,10 +5,9 @@ import type { ApiChannelAttachment } from '@service-comms/client';import { useSoupItemsQuery } from '@queries/soup/items';import {flattenAttachments,- useChannelAttachmentsQuery,+ useChannelDocumentAttachmentsQuery,type ChannelAttachmentsData,} from '@queries/channel/channel-attachments';-import { partitionAttachments } from '@channel/Media/media-items';import {buildAttachmentEntityFilters,getEntityClickContent,@@ -19,16 +18,15 @@ import {} from './AttachmentEntityList';export function ChannelAttachmentEntitySection(props: { channelId: string }) {- const attachmentsQuery = useChannelAttachmentsQuery(() => props.channelId);+ const attachmentsQuery = useChannelDocumentAttachmentsQuery(+ () => props.channelId+ );- const allAttachments = createMemo(() =>+ const documentAttachments = createMemo(() =>flattenAttachments(attachmentsQuery.data as ChannelAttachmentsData | undefined));- const documentAttachments = createMemo(- () => partitionAttachments(allAttachments()).documentAttachments- );const soupQuery = useSoupItemsQuery(() => ({diff --git a/js/app/packages/channel/Attachments/ChannelAttachmentMediaSection.tsx b/js/app/packages/channel/Attachments/ChannelAttachmentMediaSection.tsxindex b08f52f29d..a409c7f81a 100644--- a/js/app/packages/channel/Attachments/ChannelAttachmentMediaSection.tsx+++ b/js/app/packages/channel/Attachments/ChannelAttachmentMediaSection.tsx@@ -1,14 +1,16 @@import { createMemo } from 'solid-js';import {flattenAttachments,- useChannelAttachmentsQuery,+ useChannelMediaAttachmentsQuery,type ChannelAttachmentsData,} from '@queries/channel/channel-attachments';import { type MediaItem, mapMediaItems } from '@channel/Media/media-items';import { MediaGallery } from './MediaGallery';export function ChannelAttachmentMediaSection(props: { channelId: string }) {- const attachmentsQuery = useChannelAttachmentsQuery(() => props.channelId);+ const attachmentsQuery = useChannelMediaAttachmentsQuery(+ () => props.channelId+ );const items = createMemo<MediaItem[]>((previous = []) =>mapMediaItems(diff --git a/js/app/packages/queries/channel/channel-attachments.ts b/js/app/packages/queries/channel/channel-attachments.tsindex 840e9cbd70..db5827079d 100644--- a/js/app/packages/queries/channel/channel-attachments.ts+++ b/js/app/packages/queries/channel/channel-attachments.ts@@ -2,6 +2,7 @@ import { throwOnErr } from '@core/util/maybeResult';import {commsServiceClient,type ApiChannelAttachment,+ type ChannelAttachmentType,type ChannelAttachmentsPage,} from '@service-comms/client';import { type InfiniteData, useInfiniteQuery } from '@tanstack/solid-query';@@ -14,16 +15,31 @@ export type ChannelAttachmentsData = InfiniteData<string | null>;-export function channelAttachmentsQueryOptions(channelId: string) {+export type ChannelAttachmentsQueryKey = ReturnType<+ typeof channelKeys.attachments+>['queryKey'];++export function channelAttachmentsQueryOptions(+ channelId: string,+ attachmentType?: ChannelAttachmentType+) {return {- queryKey: channelKeys.attachments(channelId).queryKey,- queryFn: async ({ pageParam }: { pageParam: string | null }) => {+ queryKey: channelKeys.attachments(channelId, attachmentType).queryKey,+ queryFn: async ({+ pageParam,+ signal,+ }: {+ pageParam: string | null;+ signal?: AbortSignal;+ }) => {return await throwOnErr(async () =>await commsServiceClient.getChannelAttachments({channel_id: channelId,limit: 100,cursor: pageParam,+ attachment_type: attachmentType,+ signal,}));},@@ -34,8 +50,23 @@ export function channelAttachmentsQueryOptions(channelId: string) {};}-export function useChannelAttachmentsQuery(channelId: Accessor<string>) {- return useInfiniteQuery(() => channelAttachmentsQueryOptions(channelId()));+export function useChannelAttachmentsQuery(+ channelId: Accessor<string>,+ attachmentType?: Accessor<ChannelAttachmentType | undefined>+) {+ return useInfiniteQuery(() =>+ channelAttachmentsQueryOptions(channelId(), attachmentType?.())+ );+}++export function useChannelMediaAttachmentsQuery(channelId: Accessor<string>) {+ return useChannelAttachmentsQuery(channelId, () => 'static');+}++export function useChannelDocumentAttachmentsQuery(+ channelId: Accessor<string>+) {+ return useChannelAttachmentsQuery(channelId, () => 'dss');}export function useChannelAttachmentsWithIndex(channelId: Accessor<string>) {@@ -60,9 +91,20 @@ export function flattenAttachments(return data.pages.flatMap((page) => page.items);}+export function getChannelAttachmentsQueryKey(+ channelId: string,+ attachmentType?: ChannelAttachmentType+): ChannelAttachmentsQueryKey {+ return channelKeys.attachments(channelId, attachmentType).queryKey;+}++export function getChannelAttachmentsQueryKeyPrefix(channelId: string) {+ return [...channelKeys.attachments._def, channelId];+}+export function softInvalidateChannelAttachments(channelId: string) {queryClient.invalidateQueries({- queryKey: channelKeys.attachments(channelId).queryKey,+ queryKey: getChannelAttachmentsQueryKeyPrefix(channelId),refetchType: 'inactive',});}diff --git a/js/app/packages/queries/channel/keys.ts b/js/app/packages/queries/channel/keys.tsindex e29b2d1b47..dd50b2ac79 100644--- a/js/app/packages/queries/channel/keys.ts+++ b/js/app/packages/queries/channel/keys.ts@@ -13,8 +13,8 @@ export const channelKeys = createQueryKeys('channel', {messagesByIds: (channelID: string, messageIds: string[]) => ({queryKey: [channelID, { messageIds }],}),- attachments: (channelID: string) => ({- queryKey: [channelID],+ attachments: (channelID: string, attachmentType?: string) => ({+ queryKey: attachmentType ? [channelID, { attachmentType }] : [channelID],}),participants: (channelID: string) => ({queryKey: [channelID],diff --git a/js/app/packages/queries/channel/tests/channel-attachments.test.ts b/js/app/packages/queries/channel/tests/channel-attachments.test.tsnew file mode 100644index 0000000000..14d4593841--- /dev/null+++ b/js/app/packages/queries/channel/tests/channel-attachments.test.ts@@ -0,0 +1,57 @@+import { commsServiceClient } from '@service-comms/client';+import { afterEach, describe, expect, it, vi } from 'vitest';+import {+ channelAttachmentsQueryOptions,+ getChannelAttachmentsQueryKey,+ getChannelAttachmentsQueryKeyPrefix,+} from '../channel-attachments';++vi.mock('@service-comms/client', () => ({+ commsServiceClient: {+ getChannelAttachments: vi.fn(),+ },+}));++describe('channel attachment queries', () => {+ afterEach(() => {+ vi.clearAllMocks();+ });++ it('keys media and document attachment queries separately', () => {+ expect(getChannelAttachmentsQueryKey('channel-1', 'static')).toEqual([+ ...getChannelAttachmentsQueryKeyPrefix('channel-1'),+ { attachmentType: 'static' },+ ]);+ expect(getChannelAttachmentsQueryKey('channel-1', 'dss')).toEqual([+ ...getChannelAttachmentsQueryKeyPrefix('channel-1'),+ { attachmentType: 'dss' },+ ]);+ expect(getChannelAttachmentsQueryKey('channel-1', 'static')).not.toEqual(+ getChannelAttachmentsQueryKey('channel-1', 'dss')+ );+ });++ it('passes attachment type, cursor, and abort signal to the service client', async () => {+ const page = { items: [], next_cursor: null };+ vi.mocked(commsServiceClient.getChannelAttachments).mockResolvedValue([+ null,+ page,+ ]);+ const signal = new AbortController().signal;++ await expect(+ channelAttachmentsQueryOptions('channel-1', 'static').queryFn({+ pageParam: 'cursor-1',+ signal,+ })+ ).resolves.toBe(page);++ expect(commsServiceClient.getChannelAttachments).toHaveBeenCalledWith({+ channel_id: 'channel-1',+ limit: 100,+ cursor: 'cursor-1',+ attachment_type: 'static',+ signal,+ });+ });+});diff --git a/js/app/packages/service-clients/service-comms/client.ts b/js/app/packages/service-clients/service-comms/client.tsindex 28a2ae50e5..4962c56958 100644--- a/js/app/packages/service-clients/service-comms/client.ts+++ b/js/app/packages/service-clients/service-comms/client.ts@@ -81,6 +81,7 @@ type WithChannelId = { channel_id: string };type WithMessageId = { message_id: string };type WithMentionId = { mention_id: string };type WithEntity = { entity_type: string; entity_id: string };+export type ChannelAttachmentType = 'static' | 'dss';export const ChannelTypeEnum = {Public: ChannelType.public,@@ -435,16 +436,22 @@ export const commsServiceClient = {);},async getChannelAttachments(- args: WithChannelId & { limit: number; cursor: string | null }+ args: WithChannelId & {+ limit: number;+ cursor: string | null;+ attachment_type?: ChannelAttachmentType;+ signal?: AbortSignal;+ }) {- const { channel_id, limit, cursor } = args;+ const { channel_id, limit, cursor, attachment_type, signal } = args;const params = new URLSearchParams();params.append('limit', limit.toString());if (cursor) params.append('cursor', cursor);+ if (attachment_type) params.append('attachment_type', attachment_type);return mapOk(await commsFetch<ApiChannelAttachmentsPage>(`/channels/${channel_id}/attachments?${params.toString()}`,- { method: 'GET' }+ { method: 'GET', signal }),(result) => result);diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/getChannelAttachmentsParams.ts b/js/app/packages/service-clients/service-storage/generated/schemas/getChannelAttachmentsParams.tsindex cbb2e706a0..3cc6d61619 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/getChannelAttachmentsParams.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/getChannelAttachmentsParams.ts@@ -15,4 +15,8 @@ export type GetChannelAttachmentsParams = {* Base64 encoded cursor value*/cursor?: string;+ /**+ * Filter by type: 'static' for images/videos, 'dss' for documents+ */+ attachment_type?: string;};diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.tsindex d6a9897695..674ad96fbd 100644--- a/js/app/packages/service-clients/service-storage/generated/zod.ts+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts@@ -1191,6 +1191,12 @@ export const getChannelAttachmentsQueryParams = zod.object({.optional().describe('Page size (1-500, default 50)'),cursor: zod.string().optional().describe('Base64 encoded cursor value'),+ attachment_type: zod+ .string()+ .optional()+ .describe(+ "Filter by type: 'static' for images\/videos, 'dss' for documents"+ ),});export const getChannelAttachmentsResponse = zoddiff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.jsonindex 44fa95b1a3..23bbe3066a 100644--- a/js/app/packages/service-clients/service-storage/openapi.json+++ b/js/app/packages/service-clients/service-storage/openapi.json@@ -1186,6 +1186,15 @@"schema": {"type": "string"}+ },+ {+ "name": "attachment_type",+ "in": "query",+ "description": "Filter by type: 'static' for images/videos, 'dss' for documents",+ "required": false,+ "schema": {+ "type": "string"+ }}],"responses": {diff --git a/rust/cloud-storage/channels/.sqlx/query-6958dcc3ad28334546d21a169c3724111cd93d5304bf2d9da4dac7a1cc5ad77d.json b/rust/cloud-storage/channels/.sqlx/query-58a665360907b8fc412e9f8dcb73696b517ecdd60243bf27c9564c7b969f1143.jsonsimilarity index 80%rename from rust/cloud-storage/channels/.sqlx/query-6958dcc3ad28334546d21a169c3724111cd93d5304bf2d9da4dac7a1cc5ad77d.jsonrename to rust/cloud-storage/channels/.sqlx/query-58a665360907b8fc412e9f8dcb73696b517ecdd60243bf27c9564c7b969f1143.jsonindex acac0f944a..a506603753 100644--- a/rust/cloud-storage/channels/.sqlx/query-6958dcc3ad28334546d21a169c3724111cd93d5304bf2d9da4dac7a1cc5ad77d.json+++ b/rust/cloud-storage/channels/.sqlx/query-58a665360907b8fc412e9f8dcb73696b517ecdd60243bf27c9564c7b969f1143.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT a.id, a.channel_id, a.message_id, m.sender_id,\n a.entity_type, a.entity_id,\n a.width AS \"width?\", a.height AS \"height?\", a.created_at\n FROM comms_attachments a\n JOIN comms_messages m ON m.id = a.message_id\n WHERE a.channel_id = $1\n AND m.deleted_at IS NULL\n AND ($2::timestamptz IS NULL OR (a.created_at, a.id) < ($2, $3))\n ORDER BY a.created_at DESC, a.id DESC\n LIMIT $4\n ",+ "query": "\n SELECT a.id, a.channel_id, a.message_id, m.sender_id,\n a.entity_type, a.entity_id,\n a.width AS \"width?\", a.height AS \"height?\", a.created_at\n FROM comms_attachments a\n JOIN comms_messages m ON m.id = a.message_id\n WHERE a.channel_id = $1\n AND m.deleted_at IS NULL\n AND ($2::timestamptz IS NULL OR (a.created_at, a.id) < ($2, $3))\n AND ($5::bool IS NULL\n OR ($5 = true AND a.entity_type LIKE 'static/%')\n OR ($5 = false AND a.entity_type NOT LIKE 'static/%'))\n ORDER BY a.created_at DESC, a.id DESC\n LIMIT $4\n ","describe": {"columns": [{@@ -54,7 +54,8 @@"Uuid","Timestamptz","Uuid",- "Int8"+ "Int8",+ "Bool"]},"nullable": [@@ -69,5 +70,5 @@false]},- "hash": "6958dcc3ad28334546d21a169c3724111cd93d5304bf2d9da4dac7a1cc5ad77d"+ "hash": "58a665360907b8fc412e9f8dcb73696b517ecdd60243bf27c9564c7b969f1143"}diff --git a/rust/cloud-storage/channels/src/domain/models.rs b/rust/cloud-storage/channels/src/domain/models.rsindex a7dd9fd3d5..ce708bbdbe 100644--- a/rust/cloud-storage/channels/src/domain/models.rs+++ b/rust/cloud-storage/channels/src/domain/models.rs@@ -1,6 +1,6 @@use chrono::{DateTime, Utc};use models_pagination::{CreatedAt, CursorVal, Identify, SortOn};-use serde::Deserialize;+use serde::{Deserialize, Serialize};use uuid::Uuid;/// Request to fetch a page of channel messages.@@ -12,6 +12,17 @@ pub struct GetChannelMessagesRequest {pub limit: u16,}+/// Filter for the type of channel attachments to return.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]+#[serde(rename_all = "snake_case")]+pub enum ChannelAttachmentType {+ /// Static file attachments (images, videos).+ Static,+ /// Document storage service attachments.+ Dss,+}+/// Filters for channel message queries.#[derive(Debug, Clone, Default, Deserialize)]#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]diff --git a/rust/cloud-storage/channels/src/domain/ports.rs b/rust/cloud-storage/channels/src/domain/ports.rsindex 0831110bbf..bd8f4b7c51 100644--- a/rust/cloud-storage/channels/src/domain/ports.rs+++ b/rust/cloud-storage/channels/src/domain/ports.rs@@ -1,7 +1,7 @@use crate::domain::models::{- ChannelAttachment, ChannelMessageFilters, ChannelParticipant, CountedReaction,- MessageAttachment, MessagePageDirection, ThreadData, ThreadReply, ThreadReplyRow,- TopLevelMessageRow,+ ChannelAttachment, ChannelAttachmentType, ChannelMessageFilters, ChannelParticipant,+ CountedReaction, MessageAttachment, MessagePageDirection, ThreadData, ThreadReply,+ ThreadReplyRow, TopLevelMessageRow,};use chrono::{DateTime, Utc};use models_pagination::{CreatedAt, Query};@@ -55,6 +55,7 @@ pub trait ChannelMessagesRepo: Send + Sync + 'static {channel_id: Uuid,query: &Query<Uuid, CreatedAt, ()>,limit: u16,+ attachment_type: Option<ChannelAttachmentType>,) -> impl Future<Output = Result<Vec<ChannelAttachment>, Self::Err>> + Send;/// Fetch active participants for a channel.@@ -100,6 +101,7 @@ pub trait ChannelMessagesService: Send + Sync + 'static {channel_id: Uuid,query: Query<Uuid, CreatedAt, ()>,limit: u16,+ attachment_type: Option<ChannelAttachmentType>,) -> impl Future<Output = Result<ChannelAttachmentsPage, ChannelMessagesErr>> + Send;/// Fetch active participants for a channel.diff --git a/rust/cloud-storage/channels/src/domain/service.rs b/rust/cloud-storage/channels/src/domain/service.rsindex 2608a42a15..48359bedd6 100644--- a/rust/cloud-storage/channels/src/domain/service.rs+++ b/rust/cloud-storage/channels/src/domain/service.rs@@ -1,7 +1,7 @@use crate::domain::{models::{- ChannelMessage, ChannelMessageFilters, ChannelParticipant, MessagePageDirection,- ThreadInfo, ThreadReply, TopLevelMessageRow,+ ChannelAttachmentType, ChannelMessage, ChannelMessageFilters, ChannelParticipant,+ MessagePageDirection, ThreadInfo, ThreadReply, TopLevelMessageRow,},ports::{ChannelAttachmentsPage, ChannelMessagesErr, ChannelMessagesQueryResult,@@ -214,12 +214,13 @@ wherechannel_id: Uuid,query: Query<Uuid, CreatedAt, ()>,limit: u16,+ attachment_type: Option<ChannelAttachmentType>,) -> Result<ChannelAttachmentsPage, ChannelMessagesErr> {let limit = limit.clamp(1, 500);let attachments = self.repo- .get_channel_attachments(channel_id, &query, limit)+ .get_channel_attachments(channel_id, &query, limit, attachment_type).await.map_err(anyhow::Error::from)?;diff --git a/rust/cloud-storage/channels/src/domain/service/test.rs b/rust/cloud-storage/channels/src/domain/service/test.rsindex b57bff6336..d97f8fcb26 100644--- a/rust/cloud-storage/channels/src/domain/service/test.rs+++ b/rust/cloud-storage/channels/src/domain/service/test.rs@@ -41,7 +41,7 @@ fn empty_repo() -> MockChannelMessagesRepo {repo.expect_get_attachments_batch().returning(|_| Box::pin(async { Ok(HashMap::new()) }));repo.expect_get_channel_attachments()- .returning(|_, _, _| Box::pin(async { Ok(vec![]) }));+ .returning(|_, _, _, _| Box::pin(async { Ok(vec![]) }));repo.expect_get_channel_participants().returning(|_| Box::pin(async { Ok(vec![]) }));repo.expect_resolve_top_level_parent()@@ -205,7 +205,7 @@ async fn clamps_limit() {async fn returns_empty_attachments_page() {let svc = ChannelMessagesServiceImpl::new(empty_repo());let page = svc- .get_channel_attachments(Uuid::nil(), Query::Sort(CreatedAt, ()), 50)+ .get_channel_attachments(Uuid::nil(), Query::Sort(CreatedAt, ()), 50, None).await.unwrap();diff --git a/rust/cloud-storage/channels/src/inbound/axum_router.rs b/rust/cloud-storage/channels/src/inbound/axum_router.rsindex 4e5f47bcfc..302a17a363 100644--- a/rust/cloud-storage/channels/src/inbound/axum_router.rs+++ b/rust/cloud-storage/channels/src/inbound/axum_router.rs@@ -3,8 +3,8 @@ mod test;pub use crate::domain::models::ChannelMessageFilters;use crate::domain::models::{- ChannelAttachment, ChannelMessage, ChannelParticipant, CountedReaction, MessageAttachment,- MessagePageDirection, ParticipantRole, ThreadInfo, ThreadReply,+ ChannelAttachment, ChannelAttachmentType, ChannelMessage, ChannelParticipant, CountedReaction,+ MessageAttachment, MessagePageDirection, ParticipantRole, ThreadInfo, ThreadReply,};use crate::domain::ports::{ChannelMessagesErr, ChannelMessagesPage, ChannelMessagesQueryResult, ChannelMessagesService,@@ -83,6 +83,9 @@ pub struct Params {/// instead of cursor-paginated results.#[serde(default)]load_around_message_id: Option<Uuid>,+ /// Filter attachments by type: `static` for images/videos, `dss` for documents.+ #[serde(default)]+ attachment_type: Option<ChannelAttachmentType>,}/// Path params for thread replies endpoint.@@ -367,6 +370,7 @@ pub async fn get_thread_replies_handler<S: ChannelMessagesService, Svc: EntityAc("channel_id" = Uuid, Path, description = "Channel ID"),("limit" = Option<u16>, Query, description = "Page size (1-500, default 50)"),("cursor" = Option<String>, Query, description = "Base64 encoded cursor value"),+ ("attachment_type" = Option<String>, Query, description = "Filter by type: 'static' for images/videos, 'dss' for documents"),),responses((status = 200, body = ApiChannelAttachmentsPage),@@ -381,7 +385,8 @@ pub async fn get_thread_replies_handler<S: ChannelMessagesService, Svc: EntityAcfields(channel_id = tracing::field::Empty,limit = tracing::field::Empty,- has_cursor = tracing::field::Empty+ has_cursor = tracing::field::Empty,+ attachment_type = tracing::field::Empty))]pub async fn get_channel_attachments_handler<@@ -401,10 +406,14 @@ pub async fn get_channel_attachments_handler<span.record("channel_id", tracing::field::display(channel_id));span.record("limit", limit);span.record("has_cursor", has_cursor);+ span.record(+ "attachment_type",+ tracing::field::debug(¶ms.attachment_type),+ );let page = state.service- .get_channel_attachments(channel_id, query, limit)+ .get_channel_attachments(channel_id, query, limit, params.attachment_type).await?;Ok(Json(page.type_erase().map(ApiChannelAttachment::from)))diff --git a/rust/cloud-storage/channels/src/inbound/axum_router/test.rs b/rust/cloud-storage/channels/src/inbound/axum_router/test.rsindex c12bca809b..b9cea6d061 100644--- a/rust/cloud-storage/channels/src/inbound/axum_router/test.rs+++ b/rust/cloud-storage/channels/src/inbound/axum_router/test.rs@@ -188,6 +188,7 @@ impl ChannelMessagesService for MockService {_channel_id: Uuid,_query: Query<Uuid, CreatedAt, ()>,_limit: u16,+ _attachment_type: Option<crate::domain::models::ChannelAttachmentType>,) -> Result<ChannelAttachmentsPage, ChannelMessagesErr> {Ok(Vec::<ChannelAttachment>::new().into_iter()@@ -247,6 +248,7 @@ impl ChannelMessagesService for ErrorService {_channel_id: Uuid,_query: Query<Uuid, CreatedAt, ()>,_limit: u16,+ _attachment_type: Option<crate::domain::models::ChannelAttachmentType>,) -> Result<ChannelAttachmentsPage, ChannelMessagesErr> {Err(ChannelMessagesErr::Repo(anyhow::anyhow!("database error")))}@@ -302,6 +304,7 @@ impl ChannelMessagesService for ParticipantsService {_channel_id: Uuid,_query: Query<Uuid, CreatedAt, ()>,_limit: u16,+ _attachment_type: Option<crate::domain::models::ChannelAttachmentType>,) -> Result<ChannelAttachmentsPage, ChannelMessagesErr> {Ok(Vec::<ChannelAttachment>::new().into_iter()@@ -604,6 +607,7 @@ impl ChannelMessagesService for NotFoundService {_channel_id: Uuid,_query: Query<Uuid, CreatedAt, ()>,_limit: u16,+ _attachment_type: Option<crate::domain::models::ChannelAttachmentType>,) -> Result<ChannelAttachmentsPage, ChannelMessagesErr> {Ok(Vec::<ChannelAttachment>::new().into_iter()@@ -665,6 +669,7 @@ impl ChannelMessagesService for AroundHasItemsService {_channel_id: Uuid,_query: Query<Uuid, CreatedAt, ()>,_limit: u16,+ _attachment_type: Option<crate::domain::models::ChannelAttachmentType>,) -> Result<ChannelAttachmentsPage, ChannelMessagesErr> {Ok(Vec::<ChannelAttachment>::new().into_iter()@@ -862,6 +867,7 @@ impl ChannelMessagesService for std::sync::Arc<CapturingService> {_channel_id: Uuid,_query: Query<Uuid, CreatedAt, ()>,_limit: u16,+ _attachment_type: Option<crate::domain::models::ChannelAttachmentType>,) -> Result<ChannelAttachmentsPage, ChannelMessagesErr> {Ok(Vec::<ChannelAttachment>::new().into_iter()diff --git a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rsindex d0ef72b081..e79927078a 100644--- a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs+++ b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs@@ -3,9 +3,9 @@ mod tests;use crate::domain::{models::{- ChannelAttachment, ChannelMessageFilters, ChannelParticipant, CountedReaction,- MessageAttachment, MessagePageDirection, ParticipantRole, ThreadData, ThreadReplyRow,- TopLevelMessageRow,+ ChannelAttachment, ChannelAttachmentType, ChannelMessageFilters, ChannelParticipant,+ CountedReaction, MessageAttachment, MessagePageDirection, ParticipantRole, ThreadData,+ ThreadReplyRow, TopLevelMessageRow,},ports::{ChannelMessagesRepo, TopLevelMessagesQueryResult},};@@ -449,12 +449,15 @@ impl ChannelMessagesRepo for PgChannelMessagesRepo {channel_id: Uuid,query: &Query<Uuid, CreatedAt, ()>,limit: u16,+ attachment_type: Option<ChannelAttachmentType>,) -> Result<Vec<ChannelAttachment>, Self::Err> {let (cursor_created_at, cursor_id) = match query.vals() {(Some(id), Some(val)) => (Some(*val), Some(*id)),_ => (None, None),};+ let is_static_filter = attachment_type.map(|t| t == ChannelAttachmentType::Static);+let rows = sqlx::query_as!(ChannelAttachmentRow,r#"@@ -466,6 +469,9 @@ impl ChannelMessagesRepo for PgChannelMessagesRepo {WHERE a.channel_id = $1AND m.deleted_at IS NULLAND ($2::timestamptz IS NULL OR (a.created_at, a.id) < ($2, $3))+ AND ($5::bool IS NULL+ OR ($5 = true AND a.entity_type LIKE 'static/%')+ OR ($5 = false AND a.entity_type NOT LIKE 'static/%'))ORDER BY a.created_at DESC, a.id DESCLIMIT $4"#,@@ -473,6 +479,7 @@ impl ChannelMessagesRepo for PgChannelMessagesRepo {cursor_created_at,cursor_id,i64::from(limit) as i64,+ is_static_filter,).fetch_all(&self.pool).await?;diff --git a/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs b/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rsindex c73909949d..df90601c6b 100644--- a/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs+++ b/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs@@ -444,7 +444,7 @@ async fn channel_attachments_cursor_pagination(pool: Pool<Postgres>) -> anyhow::let repo = repo(pool);// ch1 has 3 attachments total (a001, a002 on msg1, a003 on msg3)let page1 = repo- .get_channel_attachments(CH1, &Query::Sort(CreatedAt, ()), 2)+ .get_channel_attachments(CH1, &Query::Sort(CreatedAt, ()), 2, None).await?;assert_eq!(page1.len(), 2, "limit respected");@@ -459,7 +459,7 @@ async fn channel_attachments_cursor_pagination(pool: Pool<Postgres>) -> anyhow::},filter: (),});- let page2 = repo.get_channel_attachments(CH1, &cursor, 2).await?;+ let page2 = repo.get_channel_attachments(CH1, &cursor, 2, None).await?;assert_eq!(page2.len(), 1, "remaining attachment");// No overlap between pages@@ -476,7 +476,7 @@ async fn channel_attachments_cursor_pagination(pool: Pool<Postgres>) -> anyhow::async fn channel_attachments_include_dimensions(pool: Pool<Postgres>) -> anyhow::Result<()> {let repo = repo(pool);let all = repo- .get_channel_attachments(CH1, &Query::Sort(CreatedAt, ()), 50)+ .get_channel_attachments(CH1, &Query::Sort(CreatedAt, ()), 50, None).await?;let img = all.iter().find(|a| a.entity_type == "image").unwrap();@@ -496,7 +496,7 @@ async fn channel_attachments_include_dimensions(pool: Pool<Postgres>) -> anyhow:async fn channel_attachments_exclude_deleted_messages(pool: Pool<Postgres>) -> anyhow::Result<()> {let repo = repo(pool);let all = repo- .get_channel_attachments(CH1, &Query::Sort(CreatedAt, ()), 50)+ .get_channel_attachments(CH1, &Query::Sort(CreatedAt, ()), 50, None).await?;let ids: Vec<Uuid> = all.iter().map(|a| a.id).collect();