{{ formatType(item.type) }}
@@ -115,7 +143,10 @@ export default {
COMMENT_REPLY: 'fas fa-reply',
POST_REVIEWED: 'fas fa-check',
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 = {
@@ -149,34 +180,56 @@ export default {
}
const data = await res.json()
- for (const n of data) {
- if (n.type === 'COMMENT_REPLY') {
- notifications.value.push({
- ...n,
- src: n.comment.author.avatar,
- 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) {
+ for (const n of data) {
+ if (n.type === 'COMMENT_REPLY') {
+ notifications.value.push({
+ ...n,
+ src: n.comment.author.avatar,
+ iconClick: () => {
markRead(n.id)
- router.push(`/users/${n.fromUser.id}`)
+ router.push(`/users/${n.comment.author.id}`)
}
- }
- })
- } else {
- notifications.value.push({
- ...n,
- icon: iconMap[n.type],
- })
+ })
+ } 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 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) {
console.error(e)
}
@@ -194,6 +247,12 @@ export default {
return '帖子审核结果'
case 'POST_UPDATED':
return '关注的帖子有新评论'
+ case 'FOLLOWED_POST':
+ return '关注的用户发布了新文章'
+ case 'USER_FOLLOWED':
+ return '有人关注了你'
+ case 'USER_UNFOLLOWED':
+ return '有人取消关注你'
case 'USER_ACTIVITY':
return '关注的用户有新动态'
default:
diff --git a/src/main/java/com/openisle/model/NotificationType.java b/src/main/java/com/openisle/model/NotificationType.java
index 1771fff28..9a200d800 100644
--- a/src/main/java/com/openisle/model/NotificationType.java
+++ b/src/main/java/com/openisle/model/NotificationType.java
@@ -14,6 +14,12 @@ public enum NotificationType {
POST_REVIEWED,
/** A subscribed post received a new comment */
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 */
USER_ACTIVITY
}
diff --git a/src/main/java/com/openisle/service/PostService.java b/src/main/java/com/openisle/service/PostService.java
index 5aaac2fcf..38528b2ce 100644
--- a/src/main/java/com/openisle/service/PostService.java
+++ b/src/main/java/com/openisle/service/PostService.java
@@ -83,7 +83,14 @@ public class PostService {
// notify followers of author
for (User u : subscriptionService.getSubscribers(author.getUsername())) {
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;
diff --git a/src/main/java/com/openisle/service/SubscriptionService.java b/src/main/java/com/openisle/service/SubscriptionService.java
index 8ce66e028..bed33bae2 100644
--- a/src/main/java/com/openisle/service/SubscriptionService.java
+++ b/src/main/java/com/openisle/service/SubscriptionService.java
@@ -17,6 +17,7 @@ public class SubscriptionService {
private final UserRepository userRepo;
private final PostRepository postRepo;
private final CommentRepository commentRepo;
+ private final NotificationService notificationService;
public void subscribePost(String username, Long postId) {
User user = userRepo.findByUsername(username).orElseThrow();
@@ -60,6 +61,8 @@ public class SubscriptionService {
UserSubscription us = new UserSubscription();
us.setSubscriber(subscriber);
us.setTarget(target);
+ notificationService.createNotification(target,
+ NotificationType.USER_FOLLOWED, null, null, null, subscriber, null);
return userSubRepo.save(us);
});
}
@@ -67,7 +70,11 @@ public class SubscriptionService {
public void unsubscribeUser(String username, String targetName) {
User subscriber = userRepo.findByUsername(username).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 getSubscribedUsers(String username) {