Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions js/app/packages/macro-entity/src/queries/search.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useChannelsContext } from '@core/component/ChannelsProvider';
import { blockNameToDefaultFile } from '@core/constant/allBlocks';
import { ENABLE_SEARCH_SERVICE } from '@core/constant/featureFlags';
import { idToDisplayName } from '@core/user';
import { isErr } from '@core/util/maybeResult';
import {
extractSearchSnippet,
Expand Down Expand Up @@ -183,50 +182,51 @@ const useMapSearchResponseItem = () => {
};
}
case 'email': {
const emailResult = result.email_message_search_results.at(0);
const messageHits = result.email_message_search_results.filter(
(m) => m.message_id
);
// NOTE: guaranteed to be empty or singleton array
const threadHits = result.email_message_search_results.filter(
(m) => !m.message_id
);

const singleMessage = messageHits.length === 1;

const search = getSearchData({
results: result.email_message_search_results,
type: 'email',
});

const name = result.name ?? blockNameToDefaultFile('email');

const senderName =
emailResult?.sender ||
result.email_message_search_results.at(1)?.sender ||
idToDisplayName(result.user_id);
// TODO: display sender for each message in the content hit list

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const combinedSenders =
[...new Set(messageHits.map((m) => m.pretty_sender))].join(', ') ||
threadHits.at(0)?.pretty_sender;

// NOTE: this shouldn't happen unless it's a name only match that doesn't produce a name highlight for some reason
// including this as a fallback for now
if (!emailResult) {
return {
type: 'email',
id: result.thread_id,
name,
ownerId: result.owner_id,
createdAt: result.created_at,
updatedAt: result.updated_at,
viewedAt: result.viewed_at ?? undefined,
isRead: false,
isImportant: false,
done: false,
senderName,
search,
};
}
// TODO: we probably want to get the actual latest message info on the full thread
const latestMessageSentAt = Math.max(
...messageHits.map((m) => m.sent_at).filter((m) => m != null)
);

return {
type: 'email',
id: result.thread_id,
name,
ownerId: result.owner_id,
createdAt: emailResult.sent_at ?? result.updated_at,
updatedAt: emailResult.sent_at ?? result.updated_at,
createdAt: latestMessageSentAt ?? result.created_at,
updatedAt: latestMessageSentAt ?? result.updated_at,
viewedAt: result.viewed_at ?? undefined,
isRead: !emailResult.labels.includes('UNREAD'),
isImportant: emailResult.labels.includes('IMPORTANT'),
done: !emailResult.labels.includes('INBOX'),
senderName,
isRead: singleMessage
? !messageHits[0].labels.includes('UNREAD')
: false,
isImportant: singleMessage
? messageHits[0].labels.includes('IMPORTANT')
: false,
done: singleMessage
? !messageHits[0].labels.includes('INBOX')
: false,
senderName: combinedSenders,
search,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import type { DocumentSearchResult } from './documentSearchResult';
import type { DocumentSearchResponseItemFileType } from './documentSearchResponseItemFileType';
import type { DocumentSearchResponseItemSubType } from './documentSearchResponseItemSubType';

/**
* A single response item, part of the DocumentSearchResponse object
Expand All @@ -26,4 +27,5 @@ for consistency in our data model. */
id: string;
name: string;
owner_id: string;
sub_type?: DocumentSearchResponseItemSubType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Generated by orval v7.13.0 🍺
* Do not edit manually.
* search_service
* OpenAPI spec version: 0.1.0
*/
import type { DocumentSubType } from './documentSubType';

export type DocumentSearchResponseItemSubType = null | DocumentSubType;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Generated by orval v7.13.0 🍺
* Do not edit manually.
* search_service
* OpenAPI spec version: 0.1.0
*/

/**
* The document sub type enum represents all values of document sub types.
These values should match the `document_sub_type_value` table in macrodb.
*/
export type DocumentSubType = typeof DocumentSubType[keyof typeof DocumentSubType];


// eslint-disable-next-line @typescript-eslint/no-redeclare
export const DocumentSubType = {
task: 'task',
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import type { SearchHighlight } from './searchHighlight';
import type { EmailSearchResultMessageId } from './emailSearchResultMessageId';
import type { EmailSearchResultScore } from './emailSearchResultScore';
import type { EmailSearchResultSender } from './emailSearchResultSender';
import type { EmailSearchResultSentAt } from './emailSearchResultSentAt';

/**
Expand All @@ -25,13 +24,17 @@ export interface EmailSearchResult {
/** The email message id.
This is only present if the search result is on the message content */
message_id?: EmailSearchResultMessageId;
/** The pretty sender.
If the match is on the subject, the pretty sender is the latest sender on the thread.
This could be the sender's email if there is no contact name for the sender. */
pretty_sender: string;
/** This is only present if the search result is on the message content */
recipients: string[];
/** The score of the result */
score?: EmailSearchResultScore;
/** The sender
This is only present if the search result is on the message content */
sender?: EmailSearchResultSender;
/** The sender.
If the match is on the subject, the sender is the latest sender on the thread. */
sender: string;
/** When the email message was sent
This is only present if the search result is on the message content */
sent_at?: EmailSearchResultSentAt;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ export * from './documentSearchRequestAllOfTwoTerms';
export * from './documentSearchResponse';
export * from './documentSearchResponseItem';
export * from './documentSearchResponseItemFileType';
export * from './documentSearchResponseItemSubType';
export * from './documentSearchResponseItemWithMetadata';
export * from './documentSearchResponseItemWithMetadataAllOf';
export * from './documentSearchResponseItemWithMetadataAllOfMetadata';
export * from './documentSearchResult';
export * from './documentSearchResultNodeId';
export * from './documentSearchResultRawContent';
export * from './documentSearchResultScore';
export * from './documentSubType';
export * from './emailFilters';
export * from './emailSearchParams';
export * from './emailSearchRequest';
Expand All @@ -92,7 +94,6 @@ export * from './emailSearchResponseItemWithMetadataAllOfViewedAt';
export * from './emailSearchResult';
export * from './emailSearchResultMessageId';
export * from './emailSearchResultScore';
export * from './emailSearchResultSender';
export * from './emailSearchResultSentAt';
export * from './emptyResponse';
export * from './errorResponse';
Expand Down
35 changes: 31 additions & 4 deletions js/app/packages/service-clients/service-search/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,16 @@
"description": "Standardized fields that all item types will share.\nThese field names are being aligned across all item types\nfor consistency in our data model."
},
"name": { "type": "string" },
"owner_id": { "type": "string" }
"owner_id": { "type": "string" },
"sub_type": {
"oneOf": [
{ "type": "null" },
{
"$ref": "#/components/schemas/DocumentSubType",
"description": "The sub type of the document if present."
}
]
}
}
},
"DocumentSearchResponseItemWithMetadata": {
Expand Down Expand Up @@ -1364,6 +1373,11 @@
}
}
},
"DocumentSubType": {
"type": "string",
"description": "The document sub type enum represents all values of document sub types.\nThese values should match the `document_sub_type_value` table in macrodb.",
"enum": ["task"]
},
"EmailFilters": {
"type": "object",
"description": "The email filters used to filter down what emails you search over.",
Expand Down Expand Up @@ -1506,7 +1520,15 @@
"EmailSearchResult": {
"type": "object",
"description": "A email message match for a given thread id",
"required": ["recipients", "cc", "bcc", "labels", "highlight"],
"required": [
"sender",
"pretty_sender",
"recipients",
"cc",
"bcc",
"labels",
"highlight"
],
"properties": {
"bcc": {
"type": "array",
Expand All @@ -1529,8 +1551,13 @@
},
"message_id": {
"type": ["string", "null"],
"format": "uuid",
"description": "The email message id.\nThis is only present if the search result is on the message content"
},
"pretty_sender": {
"type": "string",
"description": "The pretty sender.\nIf the match is on the subject, the pretty sender is the latest sender on the thread.\nThis could be the sender's email if there is no contact name for the sender."
},
"recipients": {
"type": "array",
"items": { "type": "string" },
Expand All @@ -1542,8 +1569,8 @@
"description": "The score of the result"
},
"sender": {
"type": ["string", "null"],
"description": "The sender\nThis is only present if the search result is on the message content"
"type": "string",
"description": "The sender.\nIf the match is on the subject, the sender is the latest sender on the thread."
},
"sent_at": {
"type": ["integer", "null"],
Expand Down