Skip to content

Commit

Permalink
feat(comment): add is_verified field for comment entity
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Feb 16, 2024
1 parent 50b4944 commit c94a34f
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion conf/artalk.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ email:
access_key_secret: ""
account_name: "[email protected]"

# Multi-push
# Multi-Push
admin_notify:
# Notification template (set to file path to use custom template)
notify_tpl: "default"
Expand Down
2 changes: 2 additions & 0 deletions internal/dao/cook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dao
import (
"github.com/ArtalkJS/Artalk/internal/entity"
"github.com/ArtalkJS/Artalk/internal/utils"
"github.com/samber/lo"
)

// ===============
Expand All @@ -29,6 +30,7 @@ func (dao *Dao) CookComment(c *entity.Comment) entity.CookedComment {
IsPending: c.IsPending,
IsPinned: c.IsPinned,
IsAllowReply: c.IsAllowReply(),
IsVerified: lo.If(user.IsAdmin, true).Else(c.IsVerified),
Rid: c.Rid,
BadgeName: user.BadgeName,
BadgeColor: user.BadgeColor,
Expand Down
7 changes: 4 additions & 3 deletions internal/entity/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ type Comment struct {
PageKey string `gorm:"index;size:255"`
SiteName string `gorm:"index;size:255"`

UserID uint `gorm:"index"`
UA string
IP string
UserID uint `gorm:"index"`
IsVerified bool `gorm:"default:false"`
UA string
IP string

Rid uint `gorm:"index"` // 父评论 ID

Expand Down
1 change: 1 addition & 0 deletions internal/entity/comment_cooked.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type CookedComment struct {
IsPending bool `json:"is_pending"`
IsPinned bool `json:"is_pinned"`
IsAllowReply bool `json:"is_allow_reply"`
IsVerified bool `json:"is_verified"`
Rid uint `json:"rid"`
BadgeName string `json:"badge_name"`
BadgeColor string `json:"badge_color"`
Expand Down
3 changes: 3 additions & 0 deletions ui/artalk/src/api/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface EntityCookedComment {
is_collapsed: boolean
is_pending: boolean
is_pinned: boolean
is_verified: boolean
link: string
nick: string
page_key: string
Expand Down Expand Up @@ -320,6 +321,7 @@ export interface HandlerResponseCommentCreate {
is_collapsed: boolean
is_pending: boolean
is_pinned: boolean
is_verified: boolean
link: string
nick: string
page_key: string
Expand Down Expand Up @@ -360,6 +362,7 @@ export interface HandlerResponseCommentUpdate {
is_collapsed: boolean
is_pending: boolean
is_pinned: boolean
is_verified: boolean
link: string
nick: string
page_key: string
Expand Down
3 changes: 3 additions & 0 deletions ui/artalk/src/comment/renders/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function renderVerifyBadge(ctx: Render) {
$badge.innerText = badgeText.replace('管理员', $t('admin')) // i18n patch
$badge.style.backgroundColor = badgeColor || ''
ctx.$headerBadgeWrap.append($badge)
} else if (ctx.data.is_verified) {
const $verifiedBadge = Utils.createElement(`<span class="atk-verified-icon" title="${$t('emailVerified')}"></span>`) // 邮箱验证徽章
ctx.$headerBadgeWrap.append($verifiedBadge)
}

if (ctx.data.is_pinned) {
Expand Down
1 change: 1 addition & 0 deletions ui/artalk/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const en = {
/* Sidebar */
msgCenter: 'Messages',
ctrlCenter: 'Admin',
emailVerified: 'Email has been verified',

/* General */
frontend: 'Frontend',
Expand Down
1 change: 1 addition & 0 deletions ui/artalk/src/i18n/jp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default defineLocaleExternal('jp', {
/* Sidebar */
msgCenter: '通知センター',
ctrlCenter: 'コントロールセンター',
emailVerified: 'メールアドレスが確認されました',

/* General */
frontend: 'フロントエンド',
Expand Down
1 change: 1 addition & 0 deletions ui/artalk/src/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const zhCN: I18n = {
/* Sidebar */
msgCenter: '通知中心',
ctrlCenter: '控制中心',
emailVerified: '邮箱已验证',

/* General */
frontend: '前端',
Expand Down
1 change: 1 addition & 0 deletions ui/artalk/src/i18n/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default defineLocaleExternal('zh-TW', {
/* Sidebar */
msgCenter: '通知中心',
ctrlCenter: '控制中心',
emailVerified: '郵箱已驗證',

/* General */
frontend: '前端',
Expand Down
10 changes: 10 additions & 0 deletions ui/artalk/src/style/comment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@
background: #f44336;
}

.atk-verified-icon {
height: 1.4em;
width: 1.4em;
background-repeat: no-repeat;
background-position: center;
background-size: contain;
display: block;
background-image: url('data:image/svg+xml,<svg viewBox="0 0 22 22" xmlns="http://www.w3.org/2000/svg" fill="%231d9bf0"><g><path d="M20.396 11c-.018-.646-.215-1.275-.57-1.816-.354-.54-.852-.972-1.438-1.246.223-.607.27-1.264.14-1.897-.131-.634-.437-1.218-.882-1.687-.47-.445-1.053-.75-1.687-.882-.633-.13-1.29-.083-1.897.14-.273-.587-.704-1.086-1.245-1.44S11.647 1.62 11 1.604c-.646.017-1.273.213-1.813.568s-.969.854-1.24 1.44c-.608-.223-1.267-.272-1.902-.14-.635.13-1.22.436-1.69.882-.445.47-.749 1.055-.878 1.688-.13.633-.08 1.29.144 1.896-.587.274-1.087.705-1.443 1.245-.356.54-.555 1.17-.574 1.817.02.647.218 1.276.574 1.817.356.54.856.972 1.443 1.245-.224.606-.274 1.263-.144 1.896.13.634.433 1.218.877 1.688.47.443 1.054.747 1.687.878.633.132 1.29.084 1.897-.136.274.586.705 1.084 1.246 1.439.54.354 1.17.551 1.816.569.647-.016 1.276-.213 1.817-.567s.972-.854 1.245-1.44c.604.239 1.266.296 1.903.164.636-.132 1.22-.447 1.68-.907.46-.46.776-1.044.908-1.681s.075-1.299-.165-1.903c.586-.274 1.084-.705 1.439-1.246.354-.54.551-1.17.569-1.816zM9.662 14.85l-3.429-3.428 1.293-1.302 2.072 2.072 4.4-4.794 1.347 1.246z"></path></g></svg>');
}

.atk-ua {
@extend .badge;
}
Expand Down
2 changes: 1 addition & 1 deletion ui/artalk/src/style/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
border-radius: calc($block-radius / 2);

@media only screen and (max-width: 768px) {
width: 6em;
min-width: 6em;
}

&:active {
Expand Down
3 changes: 3 additions & 0 deletions ui/artalk/src/types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export interface CommentData {
/** 是否置顶 */
is_pinned: boolean

/** 是否已验证 */
is_verified: boolean

/** 徽章文字 */
badge_name?: string

Expand Down

0 comments on commit c94a34f

Please sign in to comment.