mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-27 08:30:47 +08:00
Merge branch 'main' of github.com:nagisa77/OpenIsle
This commit is contained in:
@@ -67,6 +67,34 @@
|
|||||||
进行了表态
|
进行了表态
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</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}`">
|
||||||
|
{{ item.fromUser.username }}
|
||||||
|
</router-link>
|
||||||
|
开始关注你了
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="item.type === 'USER_UNFOLLOWED'">
|
||||||
|
<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>
|
||||||
|
取消关注你了
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="item.type === 'FOLLOWED_POST'">
|
||||||
|
<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>
|
<template v-else>
|
||||||
<div class="notif-content-container">
|
<div class="notif-content-container">
|
||||||
{{ formatType(item.type) }}
|
{{ formatType(item.type) }}
|
||||||
@@ -115,7 +143,10 @@ export default {
|
|||||||
COMMENT_REPLY: 'fas fa-reply',
|
COMMENT_REPLY: 'fas fa-reply',
|
||||||
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',
|
||||||
|
FOLLOWED_POST: 'fas fa-feather-alt',
|
||||||
|
USER_FOLLOWED: 'fas fa-user-plus',
|
||||||
|
USER_UNFOLLOWED: 'fas fa-user-minus'
|
||||||
}
|
}
|
||||||
|
|
||||||
const reactionEmojiMap = {
|
const reactionEmojiMap = {
|
||||||
@@ -149,34 +180,56 @@ export default {
|
|||||||
}
|
}
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
|
|
||||||
for (const n of data) {
|
for (const n of data) {
|
||||||
if (n.type === 'COMMENT_REPLY') {
|
if (n.type === 'COMMENT_REPLY') {
|
||||||
notifications.value.push({
|
notifications.value.push({
|
||||||
...n,
|
...n,
|
||||||
src: n.comment.author.avatar,
|
src: n.comment.author.avatar,
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
markRead(n.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)
|
markRead(n.id)
|
||||||
router.push(`/users/${n.fromUser.id}`)
|
router.push(`/users/${n.comment.author.id}`)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
} else if (n.type === 'REACTION') {
|
||||||
} else {
|
notifications.value.push({
|
||||||
notifications.value.push({
|
...n,
|
||||||
...n,
|
emoji: reactionEmojiMap[n.reactionType],
|
||||||
icon: iconMap[n.type],
|
iconClick: () => {
|
||||||
})
|
if (n.fromUser) {
|
||||||
|
markRead(n.id)
|
||||||
|
router.push(`/users/${n.fromUser.id}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (n.type === 'USER_FOLLOWED' || n.type === 'USER_UNFOLLOWED') {
|
||||||
|
notifications.value.push({
|
||||||
|
...n,
|
||||||
|
icon: iconMap[n.type],
|
||||||
|
iconClick: () => {
|
||||||
|
if (n.fromUser) {
|
||||||
|
markRead(n.id)
|
||||||
|
router.push(`/users/${n.fromUser.id}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (n.type === 'FOLLOWED_POST') {
|
||||||
|
notifications.value.push({
|
||||||
|
...n,
|
||||||
|
icon: iconMap[n.type],
|
||||||
|
iconClick: () => {
|
||||||
|
if (n.post) {
|
||||||
|
markRead(n.id)
|
||||||
|
router.push(`/posts/${n.post.id}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
notifications.value.push({
|
||||||
|
...n,
|
||||||
|
icon: iconMap[n.type],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
@@ -194,6 +247,12 @@ export default {
|
|||||||
return '帖子审核结果'
|
return '帖子审核结果'
|
||||||
case 'POST_UPDATED':
|
case 'POST_UPDATED':
|
||||||
return '关注的帖子有新评论'
|
return '关注的帖子有新评论'
|
||||||
|
case 'FOLLOWED_POST':
|
||||||
|
return '关注的用户发布了新文章'
|
||||||
|
case 'USER_FOLLOWED':
|
||||||
|
return '有人关注了你'
|
||||||
|
case 'USER_UNFOLLOWED':
|
||||||
|
return '有人取消关注你'
|
||||||
case 'USER_ACTIVITY':
|
case 'USER_ACTIVITY':
|
||||||
return '关注的用户有新动态'
|
return '关注的用户有新动态'
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ public enum NotificationType {
|
|||||||
POST_REVIEWED,
|
POST_REVIEWED,
|
||||||
/** A subscribed post received a new comment */
|
/** A subscribed post received a new comment */
|
||||||
POST_UPDATED,
|
POST_UPDATED,
|
||||||
|
/** Someone you follow published a new post */
|
||||||
|
FOLLOWED_POST,
|
||||||
|
/** Someone started following you */
|
||||||
|
USER_FOLLOWED,
|
||||||
|
/** Someone unfollowed you */
|
||||||
|
USER_UNFOLLOWED,
|
||||||
/** A user you subscribe to created a post or comment */
|
/** A user you subscribe to created a post or comment */
|
||||||
USER_ACTIVITY
|
USER_ACTIVITY
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,14 @@ public class PostService {
|
|||||||
// notify followers of author
|
// notify followers of author
|
||||||
for (User u : subscriptionService.getSubscribers(author.getUsername())) {
|
for (User u : subscriptionService.getSubscribers(author.getUsername())) {
|
||||||
if (!u.getId().equals(author.getId())) {
|
if (!u.getId().equals(author.getId())) {
|
||||||
notificationService.createNotification(u, NotificationType.USER_ACTIVITY, post, null, null);
|
notificationService.createNotification(
|
||||||
|
u,
|
||||||
|
NotificationType.FOLLOWED_POST,
|
||||||
|
post,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
author,
|
||||||
|
null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return post;
|
return post;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class SubscriptionService {
|
|||||||
private final UserRepository userRepo;
|
private final UserRepository userRepo;
|
||||||
private final PostRepository postRepo;
|
private final PostRepository postRepo;
|
||||||
private final CommentRepository commentRepo;
|
private final CommentRepository commentRepo;
|
||||||
|
private final NotificationService notificationService;
|
||||||
|
|
||||||
public void subscribePost(String username, Long postId) {
|
public void subscribePost(String username, Long postId) {
|
||||||
User user = userRepo.findByUsername(username).orElseThrow();
|
User user = userRepo.findByUsername(username).orElseThrow();
|
||||||
@@ -60,6 +61,8 @@ public class SubscriptionService {
|
|||||||
UserSubscription us = new UserSubscription();
|
UserSubscription us = new UserSubscription();
|
||||||
us.setSubscriber(subscriber);
|
us.setSubscriber(subscriber);
|
||||||
us.setTarget(target);
|
us.setTarget(target);
|
||||||
|
notificationService.createNotification(target,
|
||||||
|
NotificationType.USER_FOLLOWED, null, null, null, subscriber, null);
|
||||||
return userSubRepo.save(us);
|
return userSubRepo.save(us);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -67,7 +70,11 @@ public class SubscriptionService {
|
|||||||
public void unsubscribeUser(String username, String targetName) {
|
public void unsubscribeUser(String username, String targetName) {
|
||||||
User subscriber = userRepo.findByUsername(username).orElseThrow();
|
User subscriber = userRepo.findByUsername(username).orElseThrow();
|
||||||
User target = findUser(targetName).orElseThrow();
|
User target = findUser(targetName).orElseThrow();
|
||||||
userSubRepo.findBySubscriberAndTarget(subscriber, target).ifPresent(userSubRepo::delete);
|
userSubRepo.findBySubscriberAndTarget(subscriber, target).ifPresent(us -> {
|
||||||
|
userSubRepo.delete(us);
|
||||||
|
notificationService.createNotification(target,
|
||||||
|
NotificationType.USER_UNFOLLOWED, null, null, null, subscriber, null);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getSubscribedUsers(String username) {
|
public List<User> getSubscribedUsers(String username) {
|
||||||
|
|||||||
Reference in New Issue
Block a user