feat: improve notification details

This commit is contained in:
Tim
2025-07-11 13:43:01 +08:00
parent 1e1d3dceb4
commit 2657aae369
2 changed files with 50 additions and 1 deletions

View File

@@ -67,6 +67,29 @@
进行了表态
</div>
</template>
<template v-else-if="item.type === 'POST_VIEWED'">
<div class="notif-content-container">
<router-link class="notif-content-text" @click="markRead(item.id)" :to="`/users/${item.fromUser.id}`">
{{ item.fromUser.username }}
</router-link>
查看了您的帖子
<router-link class="notif-content-text" @click="markRead(item.id)" :to="`/posts/${item.post.id}`">
{{ sanitizeDescription(item.post.title) }}
</router-link>
</div>
</template>
<template v-else-if="item.type === 'POST_UPDATED'">
<div class="notif-content-container">
您关注的帖子
<router-link class="notif-content-text" @click="markRead(item.id)" :to="`/posts/${item.post.id}`">
{{ sanitizeDescription(item.post.title) }}
</router-link>
下面有新评论
<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>
</div>
</template>
<template v-else-if="item.type === 'USER_FOLLOWED'">
<div class="notif-content-container">
<router-link class="notif-content-text" @click="markRead(item.id)" :to="`/users/${item.fromUser.id}`">
@@ -225,6 +248,27 @@ export default {
}
}
})
} else if (n.type === 'POST_VIEWED') {
notifications.value.push({
...n,
src: n.fromUser ? n.fromUser.avatar : null,
icon: n.fromUser ? undefined : iconMap[n.type],
iconClick: () => {
if (n.fromUser) {
markRead(n.id)
router.push(`/users/${n.fromUser.id}`)
}
}
})
} else if (n.type === 'POST_UPDATED') {
notifications.value.push({
...n,
src: n.comment.author.avatar,
iconClick: () => {
markRead(n.id)
router.push(`/users/${n.comment.author.id}`)
}
})
} else if (n.type === 'USER_FOLLOWED' || n.type === 'USER_UNFOLLOWED') {
notifications.value.push({
...n,

View File

@@ -105,7 +105,12 @@ public class PostService {
post.setViews(post.getViews() + 1);
post = postRepository.save(post);
if (viewer != null && !viewer.equals(post.getAuthor().getUsername())) {
notificationService.createNotification(post.getAuthor(), NotificationType.POST_VIEWED, post, null, null);
User viewerUser = userRepository.findByUsername(viewer).orElse(null);
if (viewerUser != null) {
notificationService.createNotification(post.getAuthor(), NotificationType.POST_VIEWED, post, null, null, viewerUser, null);
} else {
notificationService.createNotification(post.getAuthor(), NotificationType.POST_VIEWED, post, null, null);
}
}
return post;
}