Skip to content

✨ 添加链接解析与预览#210

Merged
A-kirami merged 1 commit into
mainfrom
feat/link-parse
Dec 2, 2024
Merged

✨ 添加链接解析与预览#210
A-kirami merged 1 commit into
mainfrom
feat/link-parse

Conversation

@A-kirami

@A-kirami A-kirami commented Dec 2, 2024

Copy link
Copy Markdown
Owner

这个 PR 带来了什么样的更改?

  • 错误修复
  • 新功能
  • 文档/注释
  • 代码格式
  • 代码重构
  • 测试用例
  • 性能优化
  • 外观样式
  • 项目构建
  • 依赖环境
  • 持续集成/部署
  • 其他,请描述:

这个 PR 是否存在破坏性变更?

  • 是的,并已在 issue #___ 号中获得批准
  • 没有

描述

  • 支持解析文本中的链接

image

  • 添加链接预览开关(默认启用)

image

  • 支持预览链接

image

动机和背景

方便跳转和预览链接

其他信息

检查工作

  • 我对我的代码进行了注释,特别是在难以理解的部分
  • 我的更改需要更新文档,并且已对文档进行了相应的更改
  • 我添加了测试并且已经在本地通过,以证明我的修复补丁或新功能有效
  • 我已检查并确保更改没有与其他打开的 Pull Requests 重复

@A-kirami A-kirami added the enhancement New feature or request label Dec 2, 2024
@sourcery-ai

sourcery-ai Bot commented Dec 2, 2024

Copy link
Copy Markdown

审核指南由 Sourcery 提供

此 PR 在聊天界面中实现了链接解析和预览功能。实现包括一个链接检测系统,将文本 URL 转换为可点击的链接,添加了一个可配置的链接预览功能,并将这些更改集成到现有的消息处理系统中。

聊天中链接解析和预览的序列图

sequenceDiagram
    participant User
    participant ChatInterface
    participant LinkParser
    participant LinkPreview

    User->>ChatInterface: 发送带有文本的消息
    ChatInterface->>LinkParser: 解析消息中的链接
    LinkParser-->>ChatInterface: 返回带有链接的解析消息
    ChatInterface->>LinkPreview: 检查是否启用链接预览
    alt 启用链接预览
        LinkPreview-->>ChatInterface: 生成链接预览
    end
    ChatInterface-->>User: 显示带有链接和预览的消息
Loading

文件级更改

更改 详情 文件
添加了链接解析功能以将文本 URL 转换为可点击的链接
  • 实现了 linkMessageParse 函数以检测和提取文本消息中的 URL
  • 为 http/https 链接添加了 URL 正则表达式模式匹配
  • 在保留周围文本的同时将检测到的 URL 转换为链接类型元素
src/utils/chat.ts
在常规设置中添加了链接预览配置
  • 在常规设置模式中添加了 enableLinkPreview 布尔标志
  • 创建了新的 UI 开关控件以启用/禁用链接预览
  • 将链接预览的默认值设置为启用
src/views/settings/general.vue
src/stores/general-settings.ts
增强了聊天消息组件以支持链接渲染和预览
  • 更新了 ChatMessageElementText 以使用 linkify-string 进行 URL 检测
  • 修改了 ChatMessage 组件以根据预览设置有条件地解析链接
  • 添加了 target='_blank' 以在新标签页中打开链接
  • 为链接元素添加了悬停效果和样式
src/components/chat/ChatMessageElementText.vue
src/components/chat/ChatMessage.vue
src/components/chat/ChatMessageElementLink.vue
更新了消息适配器以处理链接内容类型
  • 在 OneBot v11 适配器中添加了链接消息类型处理
  • 在 OneBot v12 适配器中添加了链接消息类型处理
src/adapter/onebot/v11/message.ts
src/adapter/onebot/v12/message.ts

提示和命令

与 Sourcery 互动

  • 触发新审核: 在拉取请求上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审核评论。
  • 从审核评论生成 GitHub 问题: 通过回复审核评论请求 Sourcery 创建一个问题。
  • 生成拉取请求标题: 在拉取请求标题的任何地方写 @sourcery-ai 以随时生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任何地方写 @sourcery-ai summary 以随时生成 PR 摘要。您还可以使用此命令指定摘要应插入的位置。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审核功能,例如 Sourcery 生成的拉取请求摘要、审核指南等。
  • 更改审核语言。
  • 添加、删除或编辑自定义审核说明。
  • 调整其他审核设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This PR implements link parsing and preview functionality in the chat interface. The implementation includes a link detection system that converts text URLs into clickable links, adds a configurable link preview feature, and integrates these changes into the existing message handling system.

Sequence diagram for link parsing and preview in chat

sequenceDiagram
    participant User
    participant ChatInterface
    participant LinkParser
    participant LinkPreview

    User->>ChatInterface: Send message with text
    ChatInterface->>LinkParser: Parse message for links
    LinkParser-->>ChatInterface: Return parsed message with links
    ChatInterface->>LinkPreview: Check if link preview is enabled
    alt Link preview enabled
        LinkPreview-->>ChatInterface: Generate link preview
    end
    ChatInterface-->>User: Display message with links and previews
Loading

File-Level Changes

Change Details Files
Added link parsing functionality to convert text URLs into clickable links
  • Implemented linkMessageParse function to detect and extract URLs from text messages
  • Added URL regex pattern matching for http/https links
  • Converts detected URLs into link type elements while preserving surrounding text
src/utils/chat.ts
Added link preview configuration to general settings
  • Added enableLinkPreview boolean flag to general settings schema
  • Created new UI switch control for enabling/disabling link preview
  • Set default value of link preview to enabled
src/views/settings/general.vue
src/stores/general-settings.ts
Enhanced chat message components to support link rendering and preview
  • Updated ChatMessageElementText to use linkify-string for URL detection
  • Modified ChatMessage component to conditionally parse links based on preview settings
  • Added target='_blank' to open links in new tabs
  • Added hover effects and styling for link elements
src/components/chat/ChatMessageElementText.vue
src/components/chat/ChatMessage.vue
src/components/chat/ChatMessageElementLink.vue
Updated message adapters to handle link content type
  • Added link message type handling in OneBot v11 adapter
  • Added link message type handling in OneBot v12 adapter
src/adapter/onebot/v11/message.ts
src/adapter/onebot/v12/message.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@A-kirami - 我已经审查了你的更改,它们看起来很棒!

这是我在审查期间查看的内容
  • 🟢 一般问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目免费 - 如果你喜欢我们的审查,请考虑分享它们 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用反馈来改进你的审查。
Original comment in English

Hey @A-kirami - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions

github-actions Bot commented Dec 2, 2024

Copy link
Copy Markdown

📦️ 此 PR 构建的应用已经准备就绪

平台 文件 大小
🐧 linux-amd64 matcha_0.4.4_linux-amd64 112.75 MB
🍎 macos-amd64 matcha_0.4.4_macos-amd64 24.31 MB
🍎 macos-arm64 matcha_0.4.4_macos-arm64 23.92 MB
🪟 windows-amd64 matcha_0.4.4_windows-amd64 21.98 MB

*从提交 2577a2e 构建

@A-kirami
A-kirami merged commit 4cba5bd into main Dec 2, 2024
@A-kirami
A-kirami deleted the feat/link-parse branch December 2, 2024 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

1 participant