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): port context api to channels hex crate (#3581)
teof354a4870ef2
diff --git a/js/app/packages/queries/preview/fetchers.ts b/js/app/packages/queries/preview/fetchers.tsindex e0188cef8a..31d6f51e0f 100644--- a/js/app/packages/queries/preview/fetchers.ts+++ b/js/app/packages/queries/preview/fetchers.ts@@ -49,10 +49,14 @@ async function fetchChannelPreviews(}export async function fetchMessageContext(- messageId: string+ channelId: string,+ messageId: string,+ signal?: AbortSignal): Promise<MessageContext | null> {- const msgResult = await commsServiceClient.getMessageWithContext({+ const msgResult = await storageServiceClient.getMessageWithContext({+ channel_id: channelId,message_id: messageId,+ signal,});if (msgResult.isErr()) {diff --git a/js/app/packages/queries/preview/keys.ts b/js/app/packages/queries/preview/keys.tsindex 196d426798..c663af244c 100644--- a/js/app/packages/queries/preview/keys.ts+++ b/js/app/packages/queries/preview/keys.ts@@ -5,8 +5,8 @@ export const previewKeys = createQueryKeys('preview', {return {queryKey: [itemId],contextQueries: {- channelMessage: (messageId: string) => {- return { queryKey: [messageId] };+ channelMessage: (channelId: string, messageId: string) => {+ return { queryKey: [channelId, messageId] };},},};diff --git a/js/app/packages/queries/preview/preview.ts b/js/app/packages/queries/preview/preview.tsindex c54fd0858e..955c2dc0d9 100644--- a/js/app/packages/queries/preview/preview.ts+++ b/js/app/packages/queries/preview/preview.ts@@ -54,13 +54,16 @@ export function useItemPreview(item: Accessor<ItemEntity>) {const maybeChannelMessageQuery = useQuery(() => {const item_ = item();- const messageId = item_.type === 'channel' ? item_.messageId : undefined;+ const channelId = item_.type === 'channel' ? item_.id : '';+ const messageId = item_.type === 'channel' ? (item_.messageId ?? '') : '';return {- queryKey: previewKeys.item(item().id)._ctx.channelMessage(messageId!)- .queryKey,- queryFn: () => fetchMessageContext(messageId!),+ queryKey: previewKeys+ .item(item_.id)+ ._ctx.channelMessage(channelId, messageId).queryKey,+ queryFn: ({ signal }) =>+ fetchMessageContext(channelId, messageId, signal),staleTime: PREVIEW_STALE_TIME,- enabled: !!messageId && previewQuery.isSuccess,+ enabled: !!channelId && !!messageId && previewQuery.isSuccess,};});diff --git a/js/app/packages/queries/preview/types.ts b/js/app/packages/queries/preview/types.tsindex 1f9d45c4e3..4b28dc09b2 100644--- a/js/app/packages/queries/preview/types.ts+++ b/js/app/packages/queries/preview/types.ts@@ -1,8 +1,10 @@import type { DateValue } from '@core/util/date';import type { SubType } from '@entity';import type { ChannelType } from '@service-cognition/generated/schemas/channelType';-import type { Message } from '@service-comms/generated/models';-import type { ItemType } from '@service-storage/client';+import type {+ ApiChannelContextMessage,+ ItemType,+} from '@service-storage/client';import type { FileType } from '@service-storage/generated/schemas/fileType';type AccessType = 'access' | 'no_access' | 'does_not_exist';@@ -52,7 +54,7 @@ type PreviewDocumentAccess = {channelType?: never;} & BasePreviewItem<'document'>;-export type MessageContext = Message;+export type MessageContext = ApiChannelContextMessage;export type PreviewChannelAccess = {access: Extract<AccessType, 'access'>;diff --git a/js/app/packages/service-clients/service-storage/client.ts b/js/app/packages/service-clients/service-storage/client.tsindex 5a36fc4a5d..2300200ddf 100644--- a/js/app/packages/service-clients/service-storage/client.ts+++ b/js/app/packages/service-clients/service-storage/client.ts@@ -76,6 +76,8 @@ import type { GetDocumentProcessingResultResponse } from './generated/schemas/geimport type { GetDocumentResponseData } from './generated/schemas/getDocumentResponseData';import type { GetDocumentSearchResponse } from './generated/schemas/getDocumentSearchResponse';import type { GetInstructionsDocumentResponse } from './generated/schemas/getInstructionsDocumentResponse';+import type { GetMessageWithContextParams } from './generated/schemas/getMessageWithContextParams';+import type { GetMessageWithContextResponse } from './generated/schemas/getMessageWithContextResponse';import type { GetOrCreateChannelResponse } from './generated/schemas/getOrCreateChannelResponse';import type { GetOrCreateDmRequest } from './generated/schemas/getOrCreateDmRequest';import type { GetOrCreatePrivateRequest } from './generated/schemas/getOrCreatePrivateRequest';@@ -158,6 +160,7 @@ export const DEFAULT_ITEM_TYPE: ItemType = 'document';export type { ApiChannelAttachment } from './generated/schemas/apiChannelAttachment';export type { ApiChannelAttachmentsPage as ChannelAttachmentsPage } from './generated/schemas/apiChannelAttachmentsPage';+export type { ApiChannelContextMessage } from './generated/schemas/apiChannelContextMessage';export type { ApiChannelMessage } from './generated/schemas/apiChannelMessage';export type { ApiChannelMessagesPage as ChannelMessagesPage } from './generated/schemas/apiChannelMessagesPage';export type { ApiChannelParticipant } from './generated/schemas/apiChannelParticipant';@@ -595,6 +598,24 @@ export const storageServiceClient = {).map((result) => result);},+ async getMessageWithContext(+ args: WithChannelId &+ WithMessageId &+ GetMessageWithContextParams & { signal?: AbortSignal }+ ) {+ const { channel_id, message_id, before, after, signal } = args;+ const params = new URLSearchParams();+ if (before !== undefined) params.append('before', before.toString());+ if (after !== undefined) params.append('after', after.toString());+ const query = params.toString();+ return (+ await dssFetch<GetMessageWithContextResponse>(+ `/channels/${channel_id}/messages/${message_id}/context${query ? `?${query}` : ''}`,+ { method: 'GET', signal }+ )+ ).map((result) => result);+ },+async getChannelAttachments(args: WithChannelId & {limit: number;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessage.ts b/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessage.tsnew file mode 100644index 0000000000..2fb18ac1ed--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessage.ts@@ -0,0 +1,33 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */+import type { ApiChannelContextMessageDeletedAt } from './apiChannelContextMessageDeletedAt';+import type { ApiChannelContextMessageEditedAt } from './apiChannelContextMessageEditedAt';+import type { ApiChannelContextMessageThreadId } from './apiChannelContextMessageThreadId';++/**+ * A channel message returned by the message-context endpoint.+ */+export interface ApiChannelContextMessage {+ /** Channel id. */+ channel_id: string;+ /** Message content. */+ content: string;+ /** When the message was created. */+ created_at: string;+ /** When the message was soft-deleted. */+ deleted_at?: ApiChannelContextMessageDeletedAt;+ /** When the message was edited. */+ edited_at?: ApiChannelContextMessageEditedAt;+ /** Message id. */+ id: string;+ /** Sender user id. */+ sender_id: string;+ /** Parent thread id for replies. */+ thread_id?: ApiChannelContextMessageThreadId;+ /** When the message was last updated. */+ updated_at: string;+}diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessageDeletedAt.ts b/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessageDeletedAt.tsnew file mode 100644index 0000000000..0e1288dca3--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessageDeletedAt.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * When the message was soft-deleted.+ */+export type ApiChannelContextMessageDeletedAt = string | null;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessageEditedAt.ts b/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessageEditedAt.tsnew file mode 100644index 0000000000..d9bbaa2c88--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessageEditedAt.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * When the message was edited.+ */+export type ApiChannelContextMessageEditedAt = string | null;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessageThreadId.ts b/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessageThreadId.tsnew file mode 100644index 0000000000..52c82d0b45--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/apiChannelContextMessageThreadId.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Parent thread id for replies.+ */+export type ApiChannelContextMessageThreadId = string | null;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/getMessageWithContextParams.ts b/js/app/packages/service-clients/service-storage/generated/schemas/getMessageWithContextParams.tsnew file mode 100644index 0000000000..46605e96f5--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/getMessageWithContextParams.ts@@ -0,0 +1,17 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++export type GetMessageWithContextParams = {+ /**+ * Number of older messages to include+ */+ before?: number;+ /**+ * Number of newer messages to include+ */+ after?: number;+};diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/getMessageWithContextResponse.ts b/js/app/packages/service-clients/service-storage/generated/schemas/getMessageWithContextResponse.tsnew file mode 100644index 0000000000..f04eaabae0--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/getMessageWithContextResponse.ts@@ -0,0 +1,15 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */+import type { ApiChannelContextMessage } from './apiChannelContextMessage';++/**+ * Response from the message-context endpoint.+ */+export interface GetMessageWithContextResponse {+ /** Messages around the requested message in chronological order. */+ messages: ApiChannelContextMessage[];+}diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.tsindex cd44ae2c9f..957fb4ebc1 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts@@ -45,6 +45,10 @@ export * from './apiChannelAttachmentHeight';export * from './apiChannelAttachmentsPage';export * from './apiChannelAttachmentsPageNextCursor';export * from './apiChannelAttachmentWidth';+export * from './apiChannelContextMessage';+export * from './apiChannelContextMessageDeletedAt';+export * from './apiChannelContextMessageEditedAt';+export * from './apiChannelContextMessageThreadId';export * from './apiChannelMessage';export * from './apiChannelMessageDeletedAt';export * from './apiChannelMessageEditedAt';@@ -433,6 +437,8 @@ export * from './getDocumentUserAccessLevelResponse';export * from './getInstructionsDocumentResponse';export * from './getItemsSoupParams';export * from './getLocationHandlerParams';+export * from './getMessageWithContextParams';+export * from './getMessageWithContextResponse';export * from './getOrCreateAction';export * from './getOrCreateChannelResponse';export * from './getOrCreateDmRequest';diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.tsindex 1674325ac3..ce82aaa129 100644--- a/js/app/packages/service-clients/service-storage/generated/zod.ts+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts@@ -1896,6 +1896,64 @@ export const postChannelMessagesResponse = zod}).describe('Paginated response of channel messages.');+/**+ * @summary Handler for `GET /channels/{channel_id}/messages/{message_id}/context`.+ */+export const getMessageWithContextParams = zod.object({+ channel_id: zod.uuid().describe('Channel ID'),+ message_id: zod.uuid().describe('Message ID to get context around'),+});++export const getMessageWithContextQueryParams = zod.object({+ before: zod+ .number()+ .optional()+ .describe('Number of older messages to include'),+ after: zod+ .number()+ .optional()+ .describe('Number of newer messages to include'),+});++export const getMessageWithContextResponse = zod+ .object({+ messages: zod+ .array(+ zod+ .object({+ channel_id: zod.uuid().describe('Channel id.'),+ content: zod.string().describe('Message content.'),+ created_at: zod.iso+ .datetime({})+ .describe('When the message was created.'),+ deleted_at: zod.iso+ .datetime({})+ .nullish()+ .describe('When the message was soft-deleted.'),+ edited_at: zod.iso+ .datetime({})+ .nullish()+ .describe('When the message was edited.'),+ id: zod.uuid().describe('Message id.'),+ sender_id: zod.string().describe('Sender user id.'),+ thread_id: zod+ .uuid()+ .nullish()+ .describe('Parent thread id for replies.'),+ updated_at: zod.iso+ .datetime({})+ .describe('When the message was last updated.'),+ })+ .describe(+ 'A channel message returned by the message-context endpoint.'+ )+ )+ .describe(+ 'Messages around the requested message in chronological order.'+ ),+ })+ .describe('Response from the message-context endpoint.');+/*** @summary Handler for `GET /channels/{channel_id}/messages/{message_id}/replies`.*/diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.jsonindex 1f3653f406..8cb6a19594 100644--- a/js/app/packages/service-clients/service-storage/openapi.json+++ b/js/app/packages/service-clients/service-storage/openapi.json@@ -2349,6 +2349,97 @@}}},+ "/channels/{channel_id}/messages/{message_id}/context": {+ "get": {+ "tags": ["channels::inbound::axum_router"],+ "summary": "Handler for `GET /channels/{channel_id}/messages/{message_id}/context`.",+ "operationId": "get_message_with_context",+ "parameters": [+ {+ "name": "channel_id",+ "in": "path",+ "description": "Channel ID",+ "required": true,+ "schema": {+ "type": "string",+ "format": "uuid"+ }+ },+ {+ "name": "message_id",+ "in": "path",+ "description": "Message ID to get context around",+ "required": true,+ "schema": {+ "type": "string",+ "format": "uuid"+ }+ },+ {+ "name": "before",+ "in": "query",+ "description": "Number of older messages to include",+ "required": false,+ "schema": {+ "type": "integer",+ "format": "int64"+ }+ },+ {+ "name": "after",+ "in": "query",+ "description": "Number of newer messages to include",+ "required": false,+ "schema": {+ "type": "integer",+ "format": "int64"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/GetMessageWithContextResponse"+ }+ }+ }+ },+ "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"+ }+ }+ }+ }+ }+ }+ },"/channels/{channel_id}/messages/{message_id}/replies": {"get": {"tags": ["channels::inbound::axum_router"],@@ -7586,6 +7677,63 @@}}},+ "ApiChannelContextMessage": {+ "type": "object",+ "description": "A channel message returned by the message-context endpoint.",+ "required": [+ "id",+ "channel_id",+ "sender_id",+ "content",+ "created_at",+ "updated_at"+ ],+ "properties": {+ "channel_id": {+ "type": "string",+ "format": "uuid",+ "description": "Channel id."+ },+ "content": {+ "type": "string",+ "description": "Message content."+ },+ "created_at": {+ "type": "string",+ "format": "date-time",+ "description": "When the message was created."+ },+ "deleted_at": {+ "type": ["string", "null"],+ "format": "date-time",+ "description": "When the message was soft-deleted."+ },+ "edited_at": {+ "type": ["string", "null"],+ "format": "date-time",+ "description": "When the message was edited."+ },+ "id": {+ "type": "string",+ "format": "uuid",+ "description": "Message id."+ },+ "sender_id": {+ "type": "string",+ "description": "Sender user id."+ },+ "thread_id": {+ "type": ["string", "null"],+ "format": "uuid",+ "description": "Parent thread id for replies."+ },+ "updated_at": {+ "type": "string",+ "format": "date-time",+ "description": "When the message was last updated."+ }+ }+ },"ApiChannelMessage": {"type": "object","description": "A top-level channel message with thread info.",@@ -11429,6 +11577,20 @@}}},+ "GetMessageWithContextResponse": {+ "type": "object",+ "description": "Response from the message-context endpoint.",+ "required": ["messages"],+ "properties": {+ "messages": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/ApiChannelContextMessage"+ },+ "description": "Messages around the requested message in chronological order."+ }+ }+ },"GetOrCreateAction": {"type": "string","description": "Result of a get-or-create channel operation.",diff --git a/rust/cloud-storage/.sqlx/query-244c5d4b6165e48a376b1a33583bcc6cbe5e22bd559419180a6c2f2855ff607e.json b/rust/cloud-storage/.sqlx/query-244c5d4b6165e48a376b1a33583bcc6cbe5e22bd559419180a6c2f2855ff607e.jsonnew file mode 100644index 0000000000..7303f3cfa9--- /dev/null+++ b/rust/cloud-storage/.sqlx/query-244c5d4b6165e48a376b1a33583bcc6cbe5e22bd559419180a6c2f2855ff607e.json@@ -0,0 +1,73 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n id,\n channel_id,\n thread_id,\n sender_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages\n WHERE channel_id = $1\n AND (created_at, id) > ($2, $3)\n ORDER BY created_at ASC, id ASC\n LIMIT $4\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "channel_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 2,+ "name": "thread_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 3,+ "name": "sender_id",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,+ "name": "created_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 6,+ "name": "updated_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 7,+ "name": "edited_at?",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 8,+ "name": "deleted_at?",+ "type_info": "Timestamptz"+ }+ ],+ "parameters": {+ "Left": [+ "Uuid",+ "Timestamptz",+ "Uuid",+ "Int8"+ ]+ },+ "nullable": [+ false,+ false,+ true,+ false,+ false,+ false,+ false,+ null,+ null+ ]+ },+ "hash": "244c5d4b6165e48a376b1a33583bcc6cbe5e22bd559419180a6c2f2855ff607e"+}diff --git a/rust/cloud-storage/.sqlx/query-5dc0e1bcbf170bd9bbf24c739411500b574a43db370a9c995599ae8aaca20f23.json b/rust/cloud-storage/.sqlx/query-5dc0e1bcbf170bd9bbf24c739411500b574a43db370a9c995599ae8aaca20f23.jsonnew file mode 100644index 0000000000..5301e22ea0--- /dev/null+++ b/rust/cloud-storage/.sqlx/query-5dc0e1bcbf170bd9bbf24c739411500b574a43db370a9c995599ae8aaca20f23.json@@ -0,0 +1,71 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n id,\n channel_id,\n thread_id,\n sender_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages\n WHERE id = $1 AND channel_id = $2\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "channel_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 2,+ "name": "thread_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 3,+ "name": "sender_id",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,+ "name": "created_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 6,+ "name": "updated_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 7,+ "name": "edited_at?",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 8,+ "name": "deleted_at?",+ "type_info": "Timestamptz"+ }+ ],+ "parameters": {+ "Left": [+ "Uuid",+ "Uuid"+ ]+ },+ "nullable": [+ false,+ false,+ true,+ false,+ false,+ false,+ false,+ null,+ null+ ]+ },+ "hash": "5dc0e1bcbf170bd9bbf24c739411500b574a43db370a9c995599ae8aaca20f23"+}diff --git a/rust/cloud-storage/.sqlx/query-f0c307220a9a497860462656f53da3e5786501c7b07a41983acb8459df610b8b.json b/rust/cloud-storage/.sqlx/query-f0c307220a9a497860462656f53da3e5786501c7b07a41983acb8459df610b8b.jsonnew file mode 100644index 0000000000..87007e2972--- /dev/null+++ b/rust/cloud-storage/.sqlx/query-f0c307220a9a497860462656f53da3e5786501c7b07a41983acb8459df610b8b.json@@ -0,0 +1,73 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n id,\n channel_id,\n thread_id,\n sender_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages\n WHERE channel_id = $1\n AND (created_at, id) < ($2, $3)\n ORDER BY created_at DESC, id DESC\n LIMIT $4\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "channel_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 2,+ "name": "thread_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 3,+ "name": "sender_id",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,+ "name": "created_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 6,+ "name": "updated_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 7,+ "name": "edited_at?",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 8,+ "name": "deleted_at?",+ "type_info": "Timestamptz"+ }+ ],+ "parameters": {+ "Left": [+ "Uuid",+ "Timestamptz",+ "Uuid",+ "Int8"+ ]+ },+ "nullable": [+ false,+ false,+ true,+ false,+ false,+ false,+ false,+ null,+ null+ ]+ },+ "hash": "f0c307220a9a497860462656f53da3e5786501c7b07a41983acb8459df610b8b"+}diff --git a/rust/cloud-storage/channels/src/domain/models.rs b/rust/cloud-storage/channels/src/domain/models.rsindex 94ed9c0674..a79b49233f 100644--- a/rust/cloud-storage/channels/src/domain/models.rs+++ b/rust/cloud-storage/channels/src/domain/models.rs@@ -296,6 +296,29 @@ pub struct ChannelParticipant {pub left_at: Option<DateTime<Utc>>,}+/// A channel message returned by the message-context endpoint.+#[derive(Debug, Clone)]+pub struct ChannelContextMessage {+ /// Message id.+ pub id: Uuid,+ /// Channel id.+ pub channel_id: Uuid,+ /// Parent thread id for replies.+ pub thread_id: Option<Uuid>,+ /// User who sent the message.+ pub sender_id: String,+ /// Message content.+ pub content: String,+ /// When the message was created.+ pub created_at: DateTime<Utc>,+ /// When the message was last updated.+ pub updated_at: DateTime<Utc>,+ /// When the message was edited.+ pub edited_at: Option<DateTime<Utc>>,+ /// When the message was soft-deleted.+ pub deleted_at: Option<DateTime<Utc>>,+}+/// Raw row returned from the top-level messages query.#[derive(Debug, Clone)]pub struct TopLevelMessageRow {diff --git a/rust/cloud-storage/channels/src/domain/ports.rs b/rust/cloud-storage/channels/src/domain/ports.rsindex 9abc26930d..24ec8a150f 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::events::ChannelEvent;use crate::domain::models::{- AddParticipantsRequest, ChannelAttachment, ChannelAttachmentType, ChannelInfo,- ChannelMessageFilters, ChannelMetadata, ChannelParticipant, CountedReaction,+ AddParticipantsRequest, ChannelAttachment, ChannelAttachmentType, ChannelContextMessage,+ ChannelInfo, ChannelMessageFilters, ChannelMetadata, ChannelParticipant, CountedReaction,CreateChannelRequest, CreateChannelResponse, DeleteMessageQuery, GetOrCreateChannelResponse,GetOrCreateDmRequest, GetOrCreatePrivateRequest, MessageAttachment, MessagePageDirection,MutatedAttachment, MutatedMessage, NewChannelAttachment, PatchChannelRequest,@@ -78,6 +78,15 @@ pub trait ChannelRepo: Send + Sync + 'static {channel_id: Uuid,) -> impl Future<Output = Result<Vec<ChannelParticipant>, Self::Err>> + Send;+ /// Fetch messages around a target message in chronological order.+ fn get_messages_with_context(+ &self,+ channel_id: Uuid,+ message_id: Uuid,+ before: i64,+ after: i64,+ ) -> impl Future<Output = Result<Vec<ChannelContextMessage>, Self::Err>> + Send;+/// Resolve a message id to its top-level parent row. If the message is a thread reply,/// returns the parent; if already top-level, returns itself. Returns `None` if not found.fn resolve_top_level_parent(@@ -334,6 +343,18 @@ pub trait ChannelService: Send + Sync + 'static {channel_id: Uuid,) -> impl Future<Output = Result<Vec<ChannelParticipant>, ChannelMessagesErr>> + Send;+ /// Fetch messages around a target message in chronological order.+ fn get_message_context(+ &self,+ channel_id: Uuid,+ message_id: Uuid,+ before: i64,+ after: i64,+ ) -> impl Future<Output = Result<Vec<ChannelContextMessage>, ChannelMessagesErr>> + Send {+ let _ = (channel_id, before, after);+ async move { Err(ChannelMessagesErr::MessageNotFound(message_id)) }+ }+/// Fetch a centered window of messages around a specific message id.////// The result's `has_more_newer` reports whether newer messages exist outside thediff --git a/rust/cloud-storage/channels/src/domain/service.rs b/rust/cloud-storage/channels/src/domain/service.rsindex 5cbd745a76..ca2dc137f8 100644--- a/rust/cloud-storage/channels/src/domain/service.rs+++ b/rust/cloud-storage/channels/src/domain/service.rs@@ -1,13 +1,14 @@use crate::domain::{events::ChannelEvent,models::{- AddParticipantsRequest, ChannelAttachmentType, ChannelMessage, ChannelMessageFilters,- ChannelParticipant, ChannelType, DeleteMessageQuery, GetOrCreateAction,- GetOrCreateChannelResponse, GetOrCreateDmRequest, GetOrCreatePrivateRequest,- MessagePageDirection, NewChannelAttachment, ParticipantRole, PatchChannelRequest,- PatchMessageRequest, PostMessageRequest, PostMessageResponse, PostReactionRequest,- PostTypingRequest, ReactionAction, ReferencedShareItem, RemoveParticipantsRequest,- ResolvedChannelMessage, SimpleMention, ThreadInfo, ThreadReply, TopLevelMessageRow,+ AddParticipantsRequest, ChannelAttachmentType, ChannelContextMessage, ChannelMessage,+ ChannelMessageFilters, ChannelParticipant, ChannelType, DeleteMessageQuery,+ GetOrCreateAction, GetOrCreateChannelResponse, GetOrCreateDmRequest,+ GetOrCreatePrivateRequest, MessagePageDirection, NewChannelAttachment, ParticipantRole,+ PatchChannelRequest, PatchMessageRequest, PostMessageRequest, PostMessageResponse,+ PostReactionRequest, PostTypingRequest, ReactionAction, ReferencedShareItem,+ RemoveParticipantsRequest, ResolvedChannelMessage, SimpleMention, ThreadInfo, ThreadReply,+ TopLevelMessageRow,},ports::{ChannelAttachmentsPage, ChannelEventDispatcher, ChannelMessagesErr,@@ -1210,6 +1211,21 @@ whereOk(participants)}+ #[tracing::instrument(err, skip(self))]+ async fn get_message_context(+ &self,+ channel_id: Uuid,+ message_id: Uuid,+ before: i64,+ after: i64,+ ) -> Result<Vec<ChannelContextMessage>, ChannelMessagesErr> {+ self.repo+ .get_messages_with_context(channel_id, message_id, before.max(0), after.max(0))+ .await+ .map_err(anyhow::Error::from)+ .map_err(ChannelMessagesErr::Repo)+ }+#[tracing::instrument(err, skip(self))]async fn get_channel_messages_around(&self,diff --git a/rust/cloud-storage/channels/src/domain/service/test.rs b/rust/cloud-storage/channels/src/domain/service/test.rsindex acd28b76a3..805f947d77 100644--- a/rust/cloud-storage/channels/src/domain/service/test.rs+++ b/rust/cloud-storage/channels/src/domain/service/test.rs@@ -2,12 +2,13 @@ use super::*;use crate::domain::{events::ChannelEvent,models::{- ChannelAttachment, ChannelAttachmentType, ChannelInfo, ChannelMessageFilters,- ChannelMetadata, ChannelParticipant, ChannelType, CountedReaction, MessageAttachment,- MessagePageDirection, MutatedAttachment, MutatedMessage, NewChannelAttachment,- ParticipantRole, PatchChannelRequest, PatchMessageRequest, PostMessageRequest,- PostReactionRequest, ReactionAction, ReferencedShareItem, ReferencedShareItemType,- ResolvedChannelMessage, SimpleMention, ThreadData, ThreadReplyRow, TopLevelMessageRow,+ ChannelAttachment, ChannelAttachmentType, ChannelContextMessage, ChannelInfo,+ ChannelMessageFilters, ChannelMetadata, ChannelParticipant, ChannelType, CountedReaction,+ MessageAttachment, MessagePageDirection, MutatedAttachment, MutatedMessage,+ NewChannelAttachment, ParticipantRole, PatchChannelRequest, PatchMessageRequest,+ PostMessageRequest, PostReactionRequest, ReactionAction, ReferencedShareItem,+ ReferencedShareItemType, ResolvedChannelMessage, SimpleMention, ThreadData, ThreadReplyRow,+ TopLevelMessageRow,},ports::{ChannelEventDispatcher, ChannelReferenceSharePermissions, ChannelRepo, MockChannelRepo,@@ -302,6 +303,16 @@ impl ChannelRepo for FakeMutationRepo {Ok(self.state.lock().unwrap().participants.clone())}+ async fn get_messages_with_context(+ &self,+ _channel_id: Uuid,+ _message_id: Uuid,+ _before: i64,+ _after: i64,+ ) -> Result<Vec<ChannelContextMessage>, Self::Err> {+ Ok(vec![])+ }+async fn resolve_top_level_parent(&self,_channel_id: Uuid,diff --git a/rust/cloud-storage/channels/src/inbound/axum_router.rs b/rust/cloud-storage/channels/src/inbound/axum_router.rsindex f88c64b094..dfe0462da8 100644--- a/rust/cloud-storage/channels/src/inbound/axum_router.rs+++ b/rust/cloud-storage/channels/src/inbound/axum_router.rs@@ -8,9 +8,9 @@ pub use crate::domain::models::{PostReactionRequest, PostTypingRequest, RemoveParticipantsRequest,};use crate::domain::models::{- ChannelAttachment, ChannelAttachmentType, ChannelMessage, ChannelMessageKind,- ChannelParticipant, CountedReaction, MessageAttachment, MessagePageDirection, ParticipantRole,- ResolvedChannelMessage, ThreadInfo, ThreadReply,+ ChannelAttachment, ChannelAttachmentType, ChannelContextMessage, ChannelMessage,+ ChannelMessageKind, ChannelParticipant, CountedReaction, MessageAttachment,+ MessagePageDirection, ParticipantRole, ResolvedChannelMessage, ThreadInfo, ThreadReply,};pub use crate::domain::models::{ChannelMessageFilters, NotificationFilters};use crate::domain::ports::{@@ -153,6 +153,17 @@ pub struct ThreadRepliesPath {message_id: Uuid,}+/// Query parameters for the message context endpoint.+#[derive(Debug, Default, Deserialize)]+pub struct MessageContextParams {+ /// Number of older messages to include.+ #[serde(default)]+ before: i64,+ /// Number of newer messages to include.+ #[serde(default)]+ after: i64,+}+/// Path params for channel-level endpoints.#[derive(Debug, Deserialize)]pub struct ChannelPath {@@ -265,6 +276,10 @@ where"/{channel_id}/messages/{message_id}/replies",get(get_thread_replies_handler::<S, Svc>),)+ .route(+ "/{channel_id}/messages/{message_id}/context",+ get(get_message_with_context_handler::<S, Svc>),+ ).route("/{channel_id}/messages/{message_id}/resolve",get(resolve_channel_message_handler::<S, Svc>),@@ -921,6 +936,61 @@ pub async fn get_thread_replies_handler<S: ChannelService, Svc: EntityAccessServ))}+/// Handler for `GET /channels/{channel_id}/messages/{message_id}/context`.+#[utoipa::path(+ get,+ operation_id = "get_message_with_context",+ path = "/channels/{channel_id}/messages/{message_id}/context",+ params(+ ("channel_id" = Uuid, Path, description = "Channel ID"),+ ("message_id" = Uuid, Path, description = "Message ID to get context around"),+ ("before" = Option<i64>, Query, description = "Number of older messages to include"),+ ("after" = Option<i64>, Query, description = "Number of newer messages to include")+ ),+ responses(+ (status = 200, body = GetMessageWithContextResponse),+ (status = 401, body = ErrorResponse),+ (status = 404, body = ErrorResponse),+ (status = 500, body = ErrorResponse),+ )+)]+#[tracing::instrument(+ err,+ skip_all,+ fields(+ channel_id = tracing::field::Empty,+ message_id = tracing::field::Empty,+ before = tracing::field::Empty,+ after = tracing::field::Empty+ )+)]+pub async fn get_message_with_context_handler<S: ChannelService, Svc: EntityAccessService>(+ State(state): State<ChannelsRouterState<S, Svc>>,+ _access: ChannelAccessLevelExtractor<MemberParticipantRole, Svc>,+ Path(path): Path<ThreadRepliesPath>,+ Query(params): Query<MessageContextParams>,+) -> Result<Json<GetMessageWithContextResponse>, ChannelsHandlerErr> {+ let channel_id = path.channel_id;+ let message_id = path.message_id;+ let span = tracing::Span::current();+ span.record("channel_id", tracing::field::display(channel_id));+ span.record("message_id", tracing::field::display(message_id));+ span.record("before", params.before);+ span.record("after", params.after);++ let messages = state+ .service+ .get_message_context(channel_id, message_id, params.before, params.after)+ .await?;++ Ok(Json(GetMessageWithContextResponse {+ messages: messages+ .into_iter()+ .map(ApiChannelContextMessage::from)+ .collect(),+ }))+}+/// Handler for `GET /channels/{channel_id}/messages/{message_id}/resolve`.#[utoipa::path(get,@@ -1112,6 +1182,52 @@ impl From<ChannelMessage> for ApiChannelMessage {}}+/// Response from the message-context endpoint.+#[derive(Debug, Serialize, utoipa::ToSchema)]+pub struct GetMessageWithContextResponse {+ /// Messages around the requested message in chronological order.+ messages: Vec<ApiChannelContextMessage>,+}++/// A channel message returned by the message-context endpoint.+#[derive(Debug, Serialize, utoipa::ToSchema)]+pub struct ApiChannelContextMessage {+ /// Message id.+ id: Uuid,+ /// Channel id.+ channel_id: Uuid,+ /// Parent thread id for replies.+ thread_id: Option<Uuid>,+ /// Sender user id.+ sender_id: String,+ /// Message content.+ content: String,+ /// When the message was created.+ created_at: DateTime<Utc>,+ /// When the message was last updated.+ updated_at: DateTime<Utc>,+ /// When the message was edited.+ edited_at: Option<DateTime<Utc>>,+ /// When the message was soft-deleted.+ deleted_at: Option<DateTime<Utc>>,+}++impl From<ChannelContextMessage> for ApiChannelContextMessage {+ fn from(message: ChannelContextMessage) -> Self {+ Self {+ id: message.id,+ channel_id: message.channel_id,+ thread_id: message.thread_id,+ sender_id: message.sender_id,+ content: message.content,+ created_at: message.created_at,+ updated_at: message.updated_at,+ edited_at: message.edited_at,+ deleted_at: message.deleted_at,+ }+ }+}+/// Thread metadata and preview replies.#[derive(Debug, Serialize, utoipa::ToSchema)]pub struct ApiThreadInfo {diff --git a/rust/cloud-storage/channels/src/inbound/axum_router/test.rs b/rust/cloud-storage/channels/src/inbound/axum_router/test.rsindex 57f7924669..b72fd0c288 100644--- a/rust/cloud-storage/channels/src/inbound/axum_router/test.rs+++ b/rust/cloud-storage/channels/src/inbound/axum_router/test.rs@@ -1,7 +1,7 @@use super::*;use crate::domain::models::{- ChannelAttachment, ChannelMessage, ChannelMessageFilters, ChannelParticipant,- DeleteMessageQuery, GetOrCreateChannelResponse, GetOrCreateDmRequest,+ ChannelAttachment, ChannelContextMessage, ChannelMessage, ChannelMessageFilters,+ ChannelParticipant, DeleteMessageQuery, GetOrCreateChannelResponse, GetOrCreateDmRequest,GetOrCreatePrivateRequest, MessagePageDirection, ParticipantRole, PatchChannelRequest,PatchMessageRequest, PostMessageRequest, PostMessageResponse, PostReactionRequest,PostTypingRequest, RemoveParticipantsRequest,@@ -241,6 +241,27 @@ impl ChannelService for MockService {) -> Result<Vec<crate::domain::models::ThreadReply>, ChannelMessagesErr> {Ok(vec![])}++ async fn get_message_context(+ &self,+ channel_id: Uuid,+ message_id: Uuid,+ _before: i64,+ _after: i64,+ ) -> Result<Vec<ChannelContextMessage>, ChannelMessagesErr> {+ let now = chrono::Utc::now();+ Ok(vec![ChannelContextMessage {+ id: message_id,+ channel_id,+ thread_id: None,+ sender_id: "macro|[email protected]".to_string(),+ content: "message context".to_string(),+ created_at: now,+ updated_at: now,+ edited_at: None,+ deleted_at: None,+ }])+ }}struct ErrorService;@@ -1366,6 +1387,30 @@ async fn thread_replies_returns_404_when_not_found() {assert_eq!(json["message"], "Message not found");}+#[tokio::test]+async fn message_context_returns_flat_context_response() {+ let router = mock_router();+ let channel_id = Uuid::new_v4();+ let message_id = Uuid::new_v4();+ let request = Request::builder()+ .uri(format!(+ "/{channel_id}/messages/{message_id}/context?before=2&after=3"+ ))+ .body(axum::body::Body::empty())+ .unwrap();++ let res = router.oneshot(request).await.unwrap();+ assert_eq!(res.status(), StatusCode::OK);++ let bytes = res.into_body().collect().await.unwrap().to_bytes();+ let json: serde_json::Value = serde_json::from_slice(&bytes).unwrap();+ let messages = json["messages"].as_array().unwrap();+ assert_eq!(messages.len(), 1);+ assert_eq!(messages[0]["id"], message_id.to_string());+ assert_eq!(messages[0]["channel_id"], channel_id.to_string());+ assert_eq!(messages[0]["content"], "message context");+}+// --- Access control tests ---#[tokio::test]@@ -1428,6 +1473,20 @@ async fn non_member_cannot_access_thread_replies() {assert_eq!(res.status(), StatusCode::UNAUTHORIZED);}+#[tokio::test]+async fn non_member_cannot_access_message_context() {+ let router = denied_router();+ let channel_id = Uuid::new_v4();+ let message_id = Uuid::new_v4();+ let request = Request::builder()+ .uri(format!("/{channel_id}/messages/{message_id}/context"))+ .body(axum::body::Body::empty())+ .unwrap();++ let res = router.oneshot(request).await.unwrap();+ assert_eq!(res.status(), StatusCode::UNAUTHORIZED);+}+#[tokio::test]async fn missing_channel_returns_404() {let router = not_found_router();diff --git a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rsindex f63a484c23..d8b949de41 100644--- a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs+++ b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs@@ -3,11 +3,12 @@ mod tests;use crate::domain::{models::{- ChannelAttachment, ChannelAttachmentType, ChannelInfo, ChannelMessageFilters,- ChannelMessageKind, ChannelMetadata, ChannelParticipant, ChannelType, CountedReaction,- CreateChannelRequest, MessageAttachment, MessagePageDirection, MutatedAttachment,- MutatedMessage, NewChannelAttachment, ParticipantRole, PatchChannelRequest,- ResolvedChannelMessage, SimpleMention, ThreadData, ThreadReplyRow, TopLevelMessageRow,+ ChannelAttachment, ChannelAttachmentType, ChannelContextMessage, ChannelInfo,+ ChannelMessageFilters, ChannelMessageKind, ChannelMetadata, ChannelParticipant,+ ChannelType, CountedReaction, CreateChannelRequest, MessageAttachment,+ MessagePageDirection, MutatedAttachment, MutatedMessage, NewChannelAttachment,+ ParticipantRole, PatchChannelRequest, ResolvedChannelMessage, SimpleMention, ThreadData,+ ThreadReplyRow, TopLevelMessageRow,},ports::{ChannelRepo, TopLevelMessagesQueryResult},};@@ -122,6 +123,36 @@ struct ChannelAttachmentRow {created_at: chrono::DateTime<chrono::Utc>,}+/// Intermediate row for message context queries.+#[derive(Debug, sqlx::FromRow)]+struct ContextMessageRow {+ id: Uuid,+ channel_id: Uuid,+ thread_id: Option<Uuid>,+ sender_id: String,+ content: String,+ created_at: chrono::DateTime<chrono::Utc>,+ updated_at: chrono::DateTime<chrono::Utc>,+ edited_at: Option<chrono::DateTime<chrono::Utc>>,+ deleted_at: Option<chrono::DateTime<chrono::Utc>>,+}++impl From<ContextMessageRow> for ChannelContextMessage {+ fn from(row: ContextMessageRow) -> Self {+ Self {+ id: row.id,+ channel_id: row.channel_id,+ thread_id: row.thread_id,+ sender_id: row.sender_id,+ content: row.content,+ created_at: row.created_at,+ updated_at: row.updated_at,+ edited_at: row.edited_at,+ deleted_at: row.deleted_at,+ }+ }+}+/// Intermediate row for channel participants.#[derive(Debug, sqlx::FromRow)]struct ParticipantRow {@@ -1100,6 +1131,109 @@ impl ChannelRepo for PgChannelsRepo {.collect())}+ #[tracing::instrument(err, skip(self))]+ async fn get_messages_with_context(+ &self,+ channel_id: Uuid,+ message_id: Uuid,+ before: i64,+ after: i64,+ ) -> Result<Vec<ChannelContextMessage>, Self::Err> {+ let before = before.max(0);+ let after = after.max(0);++ let target = sqlx::query_as!(+ ContextMessageRow,+ r#"+ SELECT+ id,+ channel_id,+ thread_id,+ sender_id,+ content,+ created_at,+ updated_at,+ edited_at::timestamptz AS "edited_at?",+ deleted_at::timestamptz AS "deleted_at?"+ FROM comms_messages+ WHERE id = $1 AND channel_id = $2+ "#,+ message_id,+ channel_id,+ )+ .fetch_optional(&self.pool)+ .await?;++ let Some(target) = target else {+ return Ok(Vec::new());+ };++ let mut before_messages = sqlx::query_as!(+ ContextMessageRow,+ r#"+ SELECT+ id,+ channel_id,+ thread_id,+ sender_id,+ content,+ created_at,+ updated_at,+ edited_at::timestamptz AS "edited_at?",+ deleted_at::timestamptz AS "deleted_at?"+ FROM comms_messages+ WHERE channel_id = $1+ AND (created_at, id) < ($2, $3)+ ORDER BY created_at DESC, id DESC+ LIMIT $4+ "#,+ channel_id,+ target.created_at,+ target.id,+ before,+ )+ .fetch_all(&self.pool)+ .await?;+ before_messages.reverse();++ let after_messages = sqlx::query_as!(+ ContextMessageRow,+ r#"+ SELECT+ id,+ channel_id,+ thread_id,+ sender_id,+ content,+ created_at,+ updated_at,+ edited_at::timestamptz AS "edited_at?",+ deleted_at::timestamptz AS "deleted_at?"+ FROM comms_messages+ WHERE channel_id = $1+ AND (created_at, id) > ($2, $3)+ ORDER BY created_at ASC, id ASC+ LIMIT $4+ "#,+ channel_id,+ target.created_at,+ target.id,+ after,+ )+ .fetch_all(&self.pool)+ .await?;++ let mut messages = Vec::with_capacity(before_messages.len() + 1 + after_messages.len());+ messages.extend(before_messages);+ messages.push(target);+ messages.extend(after_messages);++ Ok(messages+ .into_iter()+ .map(ChannelContextMessage::from)+ .collect())+ }+#[tracing::instrument(err, skip(self))]async fn resolve_top_level_parent(&self,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 0ad6cfe7d9..9ba23db4e6 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@@ -27,6 +27,8 @@ const MSG1: Uuid = Uuid::from_u128(0x00000000_0000_0000_0000_000000000001);const MSG2: Uuid = Uuid::from_u128(0x00000000_0000_0000_0000_000000000002);const MSG3: Uuid = Uuid::from_u128(0x00000000_0000_0000_0000_000000000003);const REPLY1: Uuid = Uuid::from_u128(0x00000000_0000_0000_0000_00000000b001);+const REPLY2: Uuid = Uuid::from_u128(0x00000000_0000_0000_0000_00000000b002);+const REPLY3: Uuid = Uuid::from_u128(0x00000000_0000_0000_0000_00000000b003);const REPLY5: Uuid = Uuid::from_u128(0x00000000_0000_0000_0000_00000000b005);const DELETED_MSG_ATTACHMENT: Uuid = Uuid::from_u128(0x00000000_0000_0000_0000_00000000a004);const USER_A: &str = "macro|[email protected]";@@ -152,6 +154,35 @@ async fn top_level_ordered_newest_first(pool: Pool<Postgres>) -> anyhow::Result<Ok(())}+#[sqlx::test(+ fixtures(path = "../../../fixtures", scripts("channels_repo")),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn message_context_returns_chronological_window(pool: Pool<Postgres>) -> anyhow::Result<()> {+ let repo = repo(pool);+ let messages = repo.get_messages_with_context(CH1, REPLY2, 2, 1).await?;++ let ids = messages+ .iter()+ .map(|message| message.id)+ .collect::<Vec<_>>();+ assert_eq!(ids, vec![MSG1, REPLY1, REPLY2, REPLY3]);+ assert_eq!(messages[2].thread_id, Some(MSG1));+ Ok(())+}++#[sqlx::test(+ fixtures(path = "../../../fixtures", scripts("channels_repo")),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn message_context_is_bound_to_channel(pool: Pool<Postgres>) -> anyhow::Result<()> {+ let repo = repo(pool);+ let messages = repo.get_messages_with_context(CH2, MSG1, 1, 1).await?;++ assert!(messages.is_empty());+ Ok(())+}+#[sqlx::test(fixtures(path = "../../../fixtures", scripts("channels_repo")),migrator = "MACRO_DB_MIGRATIONS"diff --git a/rust/cloud-storage/document_storage_service/src/api/swagger.rs b/rust/cloud-storage/document_storage_service/src/api/swagger.rsindex a2ce349b11..b9ca47d257 100644--- a/rust/cloud-storage/document_storage_service/src/api/swagger.rs+++ b/rust/cloud-storage/document_storage_service/src/api/swagger.rs@@ -63,10 +63,10 @@ use crate::{},};use channels::inbound::axum_router::{- ApiChannelAttachment, ApiChannelAttachmentsPage, ApiChannelMessage, ApiChannelMessageKind,- ApiChannelMessagesPage, ApiChannelParticipant, ApiCountedReaction, ApiMessageAttachment,- ApiParticipantRole, ApiResolvedChannelMessage, ApiThreadInfo, ApiThreadReply,- ChannelMessageFilters,+ ApiChannelAttachment, ApiChannelAttachmentsPage, ApiChannelContextMessage, ApiChannelMessage,+ ApiChannelMessageKind, ApiChannelMessagesPage, ApiChannelParticipant, ApiCountedReaction,+ ApiMessageAttachment, ApiParticipantRole, ApiResolvedChannelMessage, ApiThreadInfo,+ ApiThreadReply, ChannelMessageFilters, GetMessageWithContextResponse,};use document_sub_type::DocumentSubType;use documents_hex::inbound::axum_router::{@@ -210,6 +210,7 @@ use utoipa::OpenApi;channels::inbound::axum_router::get_channel_messages_handler,channels::inbound::axum_router::post_channel_messages_handler,channels::inbound::axum_router::get_thread_replies_handler,+ channels::inbound::axum_router::get_message_with_context_handler,channels::inbound::axum_router::resolve_channel_message_handler,channels::inbound::axum_router::get_channel_attachments_handler,channels::inbound::axum_router::get_channel_participants_handler,@@ -365,6 +366,8 @@ use utoipa::OpenApi;// ChannelsApiChannelMessagesPage,ApiChannelMessage,+ GetMessageWithContextResponse,+ ApiChannelContextMessage,ApiThreadInfo,ApiThreadReply,ApiChannelMessageKind,