Skip to content

Commit

Permalink
fix: attach file information into message metadata for a quick retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Dec 19, 2024
1 parent 0271774 commit 40f99e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
17 changes: 14 additions & 3 deletions web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import { memo, useEffect, useState } from 'react'

import { usePath } from '@/hooks/usePath'

import { toGibibytes } from '@/utils/converter'
import { getFileInfo } from '@/utils/file'

import Icon from '../FileUploadPreview/Icon'

const DocMessage = ({ id }: { id: string }) => {
const DocMessage = ({
id,
metadata,
}: {
id: string
metadata: Record<string, unknown> | undefined
}) => {
const { onViewFile } = usePath()
const [fileInfo, setFileInfo] = useState<
{ filename: string; id: string } | undefined
Expand All @@ -29,10 +36,14 @@ const DocMessage = ({ id }: { id: string }) => {
<Icon type="pdf" />
<div className="w-full">
<h6 className="line-clamp-1 w-4/5 overflow-hidden font-medium">
{fileInfo?.filename}
{metadata && 'filename' in metadata
? (metadata.filename as string)
: fileInfo?.filename}
</h6>
<p className="text-[hsla(var(--text-secondary)] line-clamp-1 overflow-hidden truncate">
{fileInfo?.id ?? id}
{metadata && 'size' in metadata
? toGibibytes(Number(metadata.size))
: (fileInfo?.id ?? id)}
</p>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ const MessageContainer: React.FC<
<>
{image && <ImageMessage image={image} />}
{attachedFile && (
<DocMessage id={props.attachments?.[0]?.file_id ?? props.id} />
<DocMessage
id={props.attachments?.[0]?.file_id ?? props.id}
metadata={props.metadata}
/>
)}

{editMessage === props.id ? (
Expand Down
6 changes: 6 additions & 0 deletions web/utils/threadMessageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ThreadMessageBuilder {

content: ThreadContent[] = []
attachments: Attachment[] = []
metadata: Record<string, unknown> = {}

constructor(messageRequest: MessageRequestBuilder) {
this.messageRequest = messageRequest
Expand All @@ -33,6 +34,7 @@ export class ThreadMessageBuilder {
completed_at: timestamp,
object: 'thread.message',
content: this.content,
metadata: this.metadata,
}
}

Expand Down Expand Up @@ -68,6 +70,10 @@ export class ThreadMessageBuilder {
},
],
})
this.metadata = {
filename: fileUpload.name,
size: fileUpload.file?.size,
}
}

return this
Expand Down

0 comments on commit 40f99e9

Please sign in to comment.