diff --git a/src/adapter/onebot/v11/message.ts b/src/adapter/onebot/v11/message.ts index 7262fb0..f2e9e4f 100644 --- a/src/adapter/onebot/v11/message.ts +++ b/src/adapter/onebot/v11/message.ts @@ -20,6 +20,7 @@ import type { ImageContent, AudioContent, VideoContent, + LinkContent, ForwardContent, ForwardContentNode, ContentMapping, @@ -346,6 +347,10 @@ const messageBuildStrategy: MessageBuildStrategy = { }) }, + link: (content: LinkContent): TextMessage => { + return createMessage('text', { text: content.data.url }) + }, + forward: (): ForwardMessage => { throw new Error('未实现消息段, 跳过') }, diff --git a/src/adapter/onebot/v12/message.ts b/src/adapter/onebot/v12/message.ts index 56d8744..1c55124 100644 --- a/src/adapter/onebot/v12/message.ts +++ b/src/adapter/onebot/v12/message.ts @@ -12,6 +12,7 @@ import type { ImageContent, AudioContent, VideoContent, + LinkContent, ContentMapping, } from '~/adapter/content' import type { Message as AdapterMessage, MessageBuildStrategy, MessageParseStrategy } from '~/adapter/message' @@ -133,6 +134,10 @@ const messageBuildStrategy: MessageBuildStrategy = { video: (content: VideoContent): VideoMessage => { return createMessage('video', { file_id: content.data.id }) }, + + link: (content: LinkContent): TextMessage => { + return createMessage('text', { text: content.data.url }) + }, } const messageParseStrategy: MessageParseStrategy = { diff --git a/src/auto-imports.d.ts b/src/auto-imports.d.ts index 1e993f5..487e5bf 100644 --- a/src/auto-imports.d.ts +++ b/src/auto-imports.d.ts @@ -74,6 +74,8 @@ declare global { const isReadonly: typeof import('vue')['isReadonly'] const isRef: typeof import('vue')['isRef'] const isWindows11: typeof import('./utils/utils')['isWindows11'] + const linkMessageParse: typeof import('./utils/chat')['linkMessageParse'] + const linkParse: typeof import('./utils/chat')['linkParse'] const logger: typeof import('@tauri-apps/plugin-log') const makeDestructurable: typeof import('@vueuse/core')['makeDestructurable'] const mapActions: typeof import('pinia')['mapActions'] @@ -427,6 +429,7 @@ declare module 'vue' { readonly isReadonly: UnwrapRef readonly isRef: UnwrapRef readonly isWindows11: UnwrapRef + readonly linkMessageParse: UnwrapRef readonly logger: UnwrapRef readonly makeDestructurable: UnwrapRef readonly mapActions: UnwrapRef diff --git a/src/components/chat/ChatMessage.vue b/src/components/chat/ChatMessage.vue index e0403d2..7546495 100644 --- a/src/components/chat/ChatMessage.vue +++ b/src/components/chat/ChatMessage.vue @@ -14,8 +14,12 @@ const behav = new Behav() const state = useStateStore() +const general = useGeneralSettingsStore() + const scene = $computed(() => message.scene) +const msgElements = $computed(() => general.enableLinkPreview ? linkMessageParse(scene.message) : scene.message) + const isUserMsg = $computed(() => scene.sender_id === state.user?.id) const userName = scene.detail_type === 'group' ? scene.member.card || scene.user_name : scene.user_name @@ -44,8 +48,6 @@ async function resendMessage(): Promise { async function pokeUser(): Promise { await behav.pokeUser(state.user!.id, scene.user_id, 'group_id' in scene ? scene.group_id : undefined) } - -const general = useGeneralSettingsStore()