mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-10 04:37:29 +08:00
Merge pull request #140 from nagisa77/q6ts56-codex
Improve reaction notification detail
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
>
|
>
|
||||||
<img v-if="item.src" :src="item.src" class="timeline-img" />
|
<img v-if="item.src" :src="item.src" class="timeline-img" />
|
||||||
<i v-else-if="item.icon" :class="item.icon"></i>
|
<i v-else-if="item.icon" :class="item.icon"></i>
|
||||||
|
<span v-else-if="item.emoji" class="timeline-emoji">{{ item.emoji }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="timeline-content">
|
<div class="timeline-content">
|
||||||
<slot name="item" :item="item">{{ item.content }}</slot>
|
<slot name="item" :item="item">{{ item.content }}</slot>
|
||||||
@@ -63,6 +64,11 @@ export default {
|
|||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.timeline-emoji {
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.timeline-item::before {
|
.timeline-item::before {
|
||||||
content: '';
|
content: '';
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -45,6 +45,28 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-else-if="item.type === 'REACTION' && item.post && !item.comment">
|
||||||
|
<div class="notif-content-container">
|
||||||
|
<span class="notif-user">{{ item.fromUser.username }} </span> 对我的文章
|
||||||
|
<span>
|
||||||
|
<router-link class="notif-content-text" @click="markRead(item.id)" :to="`/posts/${item.post.id}`">
|
||||||
|
{{ sanitizeDescription(item.post.title) }}
|
||||||
|
</router-link>
|
||||||
|
</span>
|
||||||
|
表达了 "{{ item.emoji }}"
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="item.type === 'REACTION' && item.comment">
|
||||||
|
<div class="notif-content-container">
|
||||||
|
<span class="notif-user">{{ item.fromUser.username }} </span> 对我的评论
|
||||||
|
<span>
|
||||||
|
<router-link class="notif-content-text" @click="markRead(item.id)" :to="`/posts/${item.post.id}#comment-${item.comment.id}`">
|
||||||
|
{{ sanitizeDescription(item.comment.content) }}
|
||||||
|
</router-link>
|
||||||
|
</span>
|
||||||
|
表达了 "{{ item.emoji }}"
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div class="notif-content-container">
|
<div class="notif-content-container">
|
||||||
{{ formatType(item.type) }}
|
{{ formatType(item.type) }}
|
||||||
@@ -91,12 +113,18 @@ export default {
|
|||||||
const iconMap = {
|
const iconMap = {
|
||||||
POST_VIEWED: 'fas fa-eye',
|
POST_VIEWED: 'fas fa-eye',
|
||||||
COMMENT_REPLY: 'fas fa-reply',
|
COMMENT_REPLY: 'fas fa-reply',
|
||||||
REACTION: 'fas fa-thumbs-up',
|
|
||||||
POST_REVIEWED: 'fas fa-check',
|
POST_REVIEWED: 'fas fa-check',
|
||||||
POST_UPDATED: 'fas fa-comment-dots',
|
POST_UPDATED: 'fas fa-comment-dots',
|
||||||
USER_ACTIVITY: 'fas fa-user'
|
USER_ACTIVITY: 'fas fa-user'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const reactionEmojiMap = {
|
||||||
|
LIKE: '❤️',
|
||||||
|
DISLIKE: '👎',
|
||||||
|
RECOMMEND: '👏',
|
||||||
|
ANGRY: '😡'
|
||||||
|
}
|
||||||
|
|
||||||
const sanitizeDescription = (text) => {
|
const sanitizeDescription = (text) => {
|
||||||
return stripMarkdown(text)
|
return stripMarkdown(text)
|
||||||
}
|
}
|
||||||
@@ -131,6 +159,17 @@ export default {
|
|||||||
router.push(`/users/${n.comment.author.id}`)
|
router.push(`/users/${n.comment.author.id}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else if (n.type === 'REACTION') {
|
||||||
|
notifications.value.push({
|
||||||
|
...n,
|
||||||
|
emoji: reactionEmojiMap[n.reactionType],
|
||||||
|
iconClick: () => {
|
||||||
|
if (n.fromUser) {
|
||||||
|
markRead(n.id)
|
||||||
|
router.push(`/users/${n.fromUser.id}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
notifications.value.push({
|
notifications.value.push({
|
||||||
...n,
|
...n,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.openisle.controller;
|
|||||||
|
|
||||||
import com.openisle.model.Notification;
|
import com.openisle.model.Notification;
|
||||||
import com.openisle.model.NotificationType;
|
import com.openisle.model.NotificationType;
|
||||||
|
import com.openisle.model.ReactionType;
|
||||||
import com.openisle.model.Comment;
|
import com.openisle.model.Comment;
|
||||||
import com.openisle.model.Post;
|
import com.openisle.model.Post;
|
||||||
import com.openisle.service.NotificationService;
|
import com.openisle.service.NotificationService;
|
||||||
@@ -56,6 +57,12 @@ public class NotificationController {
|
|||||||
dto.setParentComment(toCommentDto(parent));
|
dto.setParentComment(toCommentDto(parent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (n.getFromUser() != null) {
|
||||||
|
dto.setFromUser(toAuthorDto(n.getFromUser()));
|
||||||
|
}
|
||||||
|
if (n.getReactionType() != null) {
|
||||||
|
dto.setReactionType(n.getReactionType());
|
||||||
|
}
|
||||||
dto.setApproved(n.getApproved());
|
dto.setApproved(n.getApproved());
|
||||||
dto.setRead(n.isRead());
|
dto.setRead(n.isRead());
|
||||||
dto.setCreatedAt(n.getCreatedAt());
|
dto.setCreatedAt(n.getCreatedAt());
|
||||||
@@ -98,6 +105,8 @@ public class NotificationController {
|
|||||||
private PostDto post;
|
private PostDto post;
|
||||||
private CommentDto comment;
|
private CommentDto comment;
|
||||||
private CommentDto parentComment;
|
private CommentDto parentComment;
|
||||||
|
private AuthorDto fromUser;
|
||||||
|
private ReactionType reactionType;
|
||||||
private Boolean approved;
|
private Boolean approved;
|
||||||
private boolean read;
|
private boolean read;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
|
|||||||
@@ -37,6 +37,14 @@ public class Notification {
|
|||||||
@JoinColumn(name = "comment_id")
|
@JoinColumn(name = "comment_id")
|
||||||
private Comment comment;
|
private Comment comment;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "from_user_id")
|
||||||
|
private User fromUser;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "reaction_type")
|
||||||
|
private ReactionType reactionType;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
private Boolean approved;
|
private Boolean approved;
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,19 @@ public class NotificationService {
|
|||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
public Notification createNotification(User user, NotificationType type, Post post, Comment comment, Boolean approved) {
|
public Notification createNotification(User user, NotificationType type, Post post, Comment comment, Boolean approved) {
|
||||||
|
return createNotification(user, type, post, comment, approved, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Notification createNotification(User user, NotificationType type, Post post, Comment comment, Boolean approved,
|
||||||
|
User fromUser, ReactionType reactionType) {
|
||||||
Notification n = new Notification();
|
Notification n = new Notification();
|
||||||
n.setUser(user);
|
n.setUser(user);
|
||||||
n.setType(type);
|
n.setType(type);
|
||||||
n.setPost(post);
|
n.setPost(post);
|
||||||
n.setComment(comment);
|
n.setComment(comment);
|
||||||
n.setApproved(approved);
|
n.setApproved(approved);
|
||||||
|
n.setFromUser(fromUser);
|
||||||
|
n.setReactionType(reactionType);
|
||||||
return notificationRepository.save(n);
|
return notificationRepository.save(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class ReactionService {
|
|||||||
reaction.setType(type);
|
reaction.setType(type);
|
||||||
reaction = reactionRepository.save(reaction);
|
reaction = reactionRepository.save(reaction);
|
||||||
if (!user.getId().equals(post.getAuthor().getId())) {
|
if (!user.getId().equals(post.getAuthor().getId())) {
|
||||||
notificationService.createNotification(post.getAuthor(), NotificationType.REACTION, post, null, null);
|
notificationService.createNotification(post.getAuthor(), NotificationType.REACTION, post, null, null, user, type);
|
||||||
}
|
}
|
||||||
return reaction;
|
return reaction;
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ public class ReactionService {
|
|||||||
reaction.setType(type);
|
reaction.setType(type);
|
||||||
reaction = reactionRepository.save(reaction);
|
reaction = reactionRepository.save(reaction);
|
||||||
if (!user.getId().equals(comment.getAuthor().getId())) {
|
if (!user.getId().equals(comment.getAuthor().getId())) {
|
||||||
notificationService.createNotification(comment.getAuthor(), NotificationType.REACTION, null, comment, null);
|
notificationService.createNotification(comment.getAuthor(), NotificationType.REACTION, comment.getPost(), comment, null, user, type);
|
||||||
}
|
}
|
||||||
return reaction;
|
return reaction;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user