mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 22:21:09 +08:00
Add detailed follow notifications
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<User> getSubscribedUsers(String username) {
|
||||
|
||||
Reference in New Issue
Block a user