-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: 实现 GitHub 风格的评论 emoji 反应功能 #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bumps [pycparser](https://github.com/eliben/pycparser) from 2.23 to 3.0. - [Release notes](https://github.com/eliben/pycparser/releases) - [Commits](eliben/pycparser@release_v2.23...release_v3.00) --- updated-dependencies: - dependency-name: pycparser dependency-version: '3.0' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]>
…y with 8 updates Bumps the production-dependencies group with 8 updates in the / directory: | Package | From | To | | --- | --- | --- | | [coverage](https://github.com/coveragepy/coveragepy) | `7.8.0` | `7.13.1` | | [django-compressor](https://github.com/django-compressor/django-compressor) | `4.5.1` | `4.6.0` | | [greenlet](https://github.com/python-greenlet/greenlet) | `3.2.2` | `3.3.0` | | [markdown](https://github.com/Python-Markdown/markdown) | `3.10` | `3.10.1` | | [prettytable](https://github.com/prettytable/prettytable) | `3.16.0` | `3.17.0` | | [rcssmin](https://github.com/ndparker/rcssmin) | `1.1.2` | `1.2.2` | | [rjsmin](https://github.com/ndparker/rjsmin) | `1.2.2` | `1.2.5` | | [simplejson](https://github.com/simplejson/simplejson) | `3.20.1` | `3.20.2` | Updates `coverage` from 7.8.0 to 7.13.1 - [Release notes](https://github.com/coveragepy/coveragepy/releases) - [Changelog](https://github.com/coveragepy/coveragepy/blob/main/CHANGES.rst) - [Commits](coveragepy/coveragepy@7.8.0...7.13.1) Updates `django-compressor` from 4.5.1 to 4.6.0 - [Changelog](https://github.com/django-compressor/django-compressor/blob/develop/docs/changelog.txt) - [Commits](django-compressor/django-compressor@4.5.1...4.6) Updates `greenlet` from 3.2.2 to 3.3.0 - [Changelog](https://github.com/python-greenlet/greenlet/blob/master/CHANGES.rst) - [Commits](python-greenlet/greenlet@3.2.2...3.3.0) Updates `markdown` from 3.10 to 3.10.1 - [Release notes](https://github.com/Python-Markdown/markdown/releases) - [Changelog](https://github.com/Python-Markdown/markdown/blob/master/docs/changelog.md) - [Commits](Python-Markdown/markdown@3.10.0...3.10.1) Updates `prettytable` from 3.16.0 to 3.17.0 - [Release notes](https://github.com/prettytable/prettytable/releases) - [Changelog](https://github.com/prettytable/prettytable/blob/main/CHANGELOG.md) - [Commits](prettytable/prettytable@3.16.0...3.17.0) Updates `rcssmin` from 1.1.2 to 1.2.2 - [Changelog](https://github.com/ndparker/rcssmin/blob/master/CHANGES) - [Commits](ndparker/rcssmin@1.1.2...1.2.2) Updates `rjsmin` from 1.2.2 to 1.2.5 - [Changelog](https://github.com/ndparker/rjsmin/blob/master/CHANGES) - [Commits](ndparker/rjsmin@1.2.2...1.2.5) Updates `simplejson` from 3.20.1 to 3.20.2 - [Release notes](https://github.com/simplejson/simplejson/releases) - [Changelog](https://github.com/simplejson/simplejson/blob/master/CHANGES.txt) - [Commits](simplejson/simplejson@v3.20.1...v3.20.2) --- updated-dependencies: - dependency-name: coverage dependency-version: 7.13.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: production-dependencies - dependency-name: django-compressor dependency-version: 4.6.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: production-dependencies - dependency-name: greenlet dependency-version: 3.3.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: production-dependencies - dependency-name: markdown dependency-version: 3.10.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-dependencies - dependency-name: prettytable dependency-version: 3.17.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: production-dependencies - dependency-name: rcssmin dependency-version: 1.2.2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: production-dependencies - dependency-name: rjsmin dependency-version: 1.2.5 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-dependencies - dependency-name: simplejson dependency-version: 3.20.2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-dependencies ... Signed-off-by: dependabot[bot] <[email protected]>
…on-dependencies-951b3f51bb chore(deps): bump the production-dependencies group across 1 directory with 8 updates
…r-3.0 chore(deps): bump pycparser from 2.23 to 3.0
Bumps [setuptools](https://github.com/pypa/setuptools) from 78.1.1 to 80.10.1. - [Release notes](https://github.com/pypa/setuptools/releases) - [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst) - [Commits](pypa/setuptools@v78.1.1...v80.10.1) --- updated-dependencies: - dependency-name: setuptools dependency-version: 80.10.1 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]>
…ls-80.10.1 chore(deps): bump setuptools from 78.1.1 to 80.10.1
实现了类似 GitHub 的评论 emoji 反应功能: Backend: - 新增 CommentReaction 模型,支持 8 种 emoji(👍👎❤️😄🎉😕🚀👀) - 添加 unique_together 约束,确保每个用户对每条评论的每种 emoji 只能点一次 - 实现 get_reactions_summary() 方法,返回反应统计和用户列表 - 新增 CommentReactionView API 端点: - GET /comment/<id>/react(公开访问,获取统计) - POST /comment/<id>/react(需登录,切换反应) - 添加数据库迁移文件 0005_commentreaction.py - 在 admin.py 中注册 CommentReactionAdmin Frontend: - 新增 reactionPicker.js Alpine.js 组件,处理反应交互逻辑 - 采用 SSR + API 混合架构: - 初始数据通过 data-reactions 属性从服务器端渲染 - 更新操作通过 API 完成,避免页面重载 - 实现美观的登录提示模态框,替代浏览器 alert() - 实现 toast 通知系统,显示操作成功/失败消息 - 添加 hover tooltip,显示点赞用户列表 - 支持深色模式 - 添加平滑的 CSS 动画(fadeIn, scaleIn, slideInRight) Template: - 更新 comment_item_modern.html,集成反应 UI - 为未登录用户显示 🔒 提示 - 添加 emoji 选择器,支持 8 种表情 - 在 base.html 中添加 data-authenticated 标识 Template Tags: - 新增 to_json 过滤器,安全地将 Python 对象转为 JSON - 新增 get_reactions_for_user 过滤器,获取带用户状态的反应数据 Features: - 登录用户可以点击 emoji 添加反应,再次点击取消 - 显示每种 emoji 的计数和点赞状态 - 鼠标悬停显示点赞用户名单(前5个+剩余数量) - 未登录用户点击会显示美观的登录引导弹窗 - 401 错误自动处理并重定向到登录页 - CSRF 保护和安全验证 - 响应式设计,支持移动端 Performance: - 使用 SSR 初始数据,避免首屏额外 API 请求 - 使用数据库索引优化查询性能 - select_related 优化关联查询 🤖 Generated with Claude Code
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #890 +/- ##
==========================================
- Coverage 77.99% 77.54% -0.45%
==========================================
Files 82 82
Lines 3985 4066 +81
==========================================
+ Hits 3108 3153 +45
- Misses 877 913 +36
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
功能概述
实现了类似 GitHub 的评论 emoji 反应系统,用户可以对评论进行情感表达。
主要特性
Backend 后端
CommentReaction模型,支持 8 种 emoji(👍👎❤️😄🎉😕🚀👀)get_reactions_summary()方法返回反应统计和用户列表GET /comment/<id>/react- 获取统计(公开访问)POST /comment/<id>/react- 切换反应(需登录)Frontend 前端
reactionPicker.jsAlpine.js 组件用户体验
技术实现
架构设计
采用 SSR + API 混合架构:
data-reactions属性从服务器端渲染性能优化
select_related优化关联查询修改的文件
Backend
comments/models.py- 新增 CommentReaction 模型comments/views.py- 新增 CommentReactionView APIcomments/urls.py- 新增路由comments/admin.py- 注册管理界面comments/migrations/0005_commentreaction.py- 数据库迁移Frontend
frontend/src/components/reactionPicker.js- 新增 Alpine.js 组件frontend/src/main.js- 注册组件frontend/src/styles/main.css- 新增动画样式Templates
templates/comments/tags/comment_item_modern.html- 集成反应 UItemplates/share_layout/base.html- 添加认证状态标识blog/templatetags/blog_tags.py- 新增模板过滤器测试建议
截图
可以添加功能截图
🤖 Generated with Claude Code