diff --git a/frontend/openchat-client/src/openchat.ts b/frontend/openchat-client/src/openchat.ts index fac28fe339..4f83fa0a88 100644 --- a/frontend/openchat-client/src/openchat.ts +++ b/frontend/openchat-client/src/openchat.ts @@ -394,6 +394,7 @@ import type { BotCommandInstance, InternalBotCommandInstance, ExternalBotCommandInstance, + CaptionedContent, } from "openchat-shared"; import { AuthProvider, @@ -447,6 +448,8 @@ import { deletedUser, OPENCHAT_BOT_USER_ID, AIRDROP_BOT_USER_ID, + isEditableContent, + isCaptionedContent, } from "openchat-shared"; import { failedMessagesStore } from "./stores/failedMessages"; import { diamondDurationToMs } from "./stores/diamond"; @@ -3883,10 +3886,10 @@ export class OpenChat extends OpenChatAgentWorker { private getMessageContent( text: string | undefined, - attachment: AttachmentContent | undefined, + captioned: CaptionedContent | undefined, ): MessageContent { - return attachment - ? { ...attachment, caption: text } + return captioned + ? { ...captioned, caption: text } : ({ kind: "text_content", text: text ?? "", @@ -4022,10 +4025,16 @@ export class OpenChat extends OpenChatAgentWorker { textContent = disableLinksInText(textContent, disabledLinks); } + const captioned = + attachment ?? + (isCaptionedContent(editingEvent.event.content) + ? editingEvent.event.content + : undefined); + const msg = { ...editingEvent.event, edited: true, - content: this.getMessageContent(textContent ?? undefined, attachment), + content: this.getMessageContent(textContent ?? undefined, captioned), }; localMessageUpdates.markContentEdited(msg.messageId, msg.content); draftMessagesStore.delete(messageContext); @@ -7692,17 +7701,8 @@ export class OpenChat extends OpenChatAgentWorker { } } - private contentTypesSupportingEdit = new Set([ - "file_content", - "text_content", - "image_content", - "video_content", - "audio_content", - "giphy_content", - ]); - contentTypeSupportsEdit(contentType: MessageContent["kind"]): boolean { - return this.contentTypesSupportingEdit.has(contentType); + return isEditableContent(contentType); } getBots(includeTestBots: boolean = false) { diff --git a/frontend/openchat-shared/src/domain/chat/chat.ts b/frontend/openchat-shared/src/domain/chat/chat.ts index d753e6d4b0..3ad0f7dd0b 100644 --- a/frontend/openchat-shared/src/domain/chat/chat.ts +++ b/frontend/openchat-shared/src/domain/chat/chat.ts @@ -127,6 +127,28 @@ export function isAttachmentContent(content: MessageContent): content is Attachm } } +export type EditableContent = + | FileContent + | TextContent + | ImageContent + | VideoContent + | AudioContent + | GiphyContent; + +export function isEditableContent(kind: MessageContent["kind"]): kind is EditableContent["kind"] { + switch (kind) { + case "file_content": + case "text_content": + case "image_content": + case "video_content": + case "audio_content": + case "giphy_content": + return true; + default: + return false; + } +} + export function isCaptionedContent(content: MessageContent): content is CaptionedContent { switch (content.kind) { case "image_content": diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 3d66b5b07a..1b670d4844 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -40,6 +40,7 @@ "dotenv-cli": "^7.2.1", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", + "prettier-plugin-svelte": "^3.3.2", "rollup": "^4.22.4", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-cleaner": "^1.0.0", @@ -30401,6 +30402,17 @@ "node": ">=6.0.0" } }, + "node_modules/prettier-plugin-svelte": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/prettier-plugin-svelte/-/prettier-plugin-svelte-3.3.2.tgz", + "integrity": "sha512-kRPjH8wSj2iu+dO+XaUv4vD8qr5mdDmlak3IT/7AOgGIMRG86z/EHOLauFcClKEnOUf4A4nOA7sre5KrJD4Raw==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "prettier": "^3.0.0", + "svelte": "^3.2.0 || ^4.0.0-next.0 || ^5.0.0-next.0" + } + }, "node_modules/pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 984272b5f3..c15016cfcb 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -40,6 +40,7 @@ "dotenv-cli": "^7.2.1", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", + "prettier-plugin-svelte": "^3.3.2", "rollup": "^4.22.4", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-cleaner": "^1.0.0",