mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-26 16:10:49 +08:00
Merge branch 'main' of github.com:nagisa77/OpenIsle
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,4 +2,5 @@
|
||||
target
|
||||
openisle.iml
|
||||
node_modules
|
||||
dist
|
||||
dist
|
||||
open-isle.env
|
||||
@@ -79,6 +79,8 @@ public class SecurityConfig {
|
||||
"http://localhost",
|
||||
"http://30.211.97.254:8080",
|
||||
"http://30.211.97.254",
|
||||
"http://192.168.7.70",
|
||||
"http://192.168.7.70:8080",
|
||||
websiteUrl,
|
||||
websiteUrl.replace("://www.", "://")
|
||||
));
|
||||
@@ -4,6 +4,7 @@ import com.openisle.model.Comment;
|
||||
import com.openisle.service.CommentService;
|
||||
import com.openisle.service.CaptchaService;
|
||||
import com.openisle.service.LevelService;
|
||||
import com.openisle.service.ReactionService;
|
||||
import com.openisle.model.CommentSort;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -23,6 +24,7 @@ public class CommentController {
|
||||
private final CommentService commentService;
|
||||
private final LevelService levelService;
|
||||
private final CaptchaService captchaService;
|
||||
private final ReactionService reactionService;
|
||||
|
||||
@Value("${app.captcha.enabled:false}")
|
||||
private boolean captchaEnabled;
|
||||
@@ -70,6 +72,10 @@ public class CommentController {
|
||||
.map(this::toDtoWithReplies)
|
||||
.collect(Collectors.toList());
|
||||
dto.setReplies(replies);
|
||||
List<ReactionDto> reactions = reactionService.getReactionsForComment(comment.getId()).stream()
|
||||
.map(this::toReactionDto)
|
||||
.collect(Collectors.toList());
|
||||
dto.setReactions(reactions);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@@ -109,6 +115,7 @@ public class CommentController {
|
||||
private LocalDateTime createdAt;
|
||||
private AuthorDto author;
|
||||
private List<CommentDto> replies;
|
||||
private List<ReactionDto> reactions;
|
||||
private int reward;
|
||||
}
|
||||
|
||||
@@ -118,4 +125,29 @@ public class CommentController {
|
||||
private String username;
|
||||
private String avatar;
|
||||
}
|
||||
|
||||
private ReactionDto toReactionDto(com.openisle.model.Reaction reaction) {
|
||||
ReactionDto dto = new ReactionDto();
|
||||
dto.setId(reaction.getId());
|
||||
dto.setType(reaction.getType());
|
||||
dto.setUser(reaction.getUser().getUsername());
|
||||
if (reaction.getPost() != null) {
|
||||
dto.setPostId(reaction.getPost().getId());
|
||||
}
|
||||
if (reaction.getComment() != null) {
|
||||
dto.setCommentId(reaction.getComment().getId());
|
||||
}
|
||||
dto.setReward(0);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ReactionDto {
|
||||
private Long id;
|
||||
private com.openisle.model.ReactionType type;
|
||||
private String user;
|
||||
private Long postId;
|
||||
private Long commentId;
|
||||
private int reward;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.openisle.model.Reaction;
|
||||
import com.openisle.model.ReactionType;
|
||||
import com.openisle.service.ReactionService;
|
||||
import com.openisle.service.LevelService;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -15,5 +15,16 @@ public enum ReactionType {
|
||||
MIND_BLOWN,
|
||||
POOP,
|
||||
CLOWN,
|
||||
SKULL
|
||||
SKULL,
|
||||
FIRE,
|
||||
EYES,
|
||||
FROWN,
|
||||
HOT,
|
||||
EAGLE,
|
||||
SPIDER,
|
||||
BAT,
|
||||
CHINA,
|
||||
USA,
|
||||
JAPAN,
|
||||
KOREA
|
||||
}
|
||||
@@ -18,4 +18,6 @@ public interface NotificationRepository extends JpaRepository<Notification, Long
|
||||
List<Notification> findByComment(Comment comment);
|
||||
|
||||
void deleteByTypeAndFromUser(NotificationType type, User fromUser);
|
||||
|
||||
void deleteByTypeAndFromUserAndPost(NotificationType type, User fromUser, Post post);
|
||||
}
|
||||
@@ -30,9 +30,27 @@ public interface ReactionRepository extends JpaRepository<Reaction, Long> {
|
||||
@Query("SELECT COUNT(r) FROM Reaction r WHERE r.user.username = :username AND r.createdAt >= :start")
|
||||
long countByUserAfter(@Param("username") String username, @Param("start") java.time.LocalDateTime start);
|
||||
|
||||
@Query("SELECT COUNT(r) FROM Reaction r WHERE r.type = com.openisle.model.ReactionType.LIKE AND ((r.post IS NOT NULL AND r.post.author.username = :username) OR (r.comment IS NOT NULL AND r.comment.author.username = :username))")
|
||||
@Query("""
|
||||
SELECT COUNT(DISTINCT r.id)
|
||||
FROM Reaction r
|
||||
LEFT JOIN r.post p
|
||||
LEFT JOIN p.author pa
|
||||
LEFT JOIN r.comment c
|
||||
LEFT JOIN c.author ca
|
||||
WHERE r.type = com.openisle.model.ReactionType.LIKE
|
||||
AND (
|
||||
(r.post IS NOT NULL AND pa.username = :username)
|
||||
OR (r.comment IS NOT NULL AND ca.username = :username)
|
||||
)
|
||||
""")
|
||||
long countLikesReceived(@Param("username") String username);
|
||||
|
||||
@Query("SELECT COUNT(r) FROM Reaction r WHERE (r.post IS NOT NULL AND r.post.author.username = :username) OR (r.comment IS NOT NULL AND r.comment.author.username = :username)")
|
||||
@Query("""
|
||||
SELECT COUNT(r) FROM Reaction r
|
||||
LEFT JOIN r.post p
|
||||
LEFT JOIN r.comment c
|
||||
WHERE (p IS NOT NULL AND p.author.username = :username) OR
|
||||
(c IS NOT NULL AND c.author.username = :username)
|
||||
""")
|
||||
long countReceived(@Param("username") String username);
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -35,6 +36,7 @@ public class CommentService {
|
||||
private final NotificationRepository notificationRepository;
|
||||
private final ImageUploader imageUploader;
|
||||
|
||||
@Transactional
|
||||
public Comment addComment(String username, Long postId, String content) {
|
||||
long recent = commentRepository.countByAuthorAfter(username,
|
||||
java.time.LocalDateTime.now().minusMinutes(1));
|
||||
@@ -68,6 +70,7 @@ public class CommentService {
|
||||
return comment;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Comment addReply(String username, Long parentId, String content) {
|
||||
long recent = commentRepository.countByAuthorAfter(username,
|
||||
java.time.LocalDateTime.now().minusMinutes(1));
|
||||
@@ -152,7 +155,7 @@ public class CommentService {
|
||||
return commentRepository.findLastCommentTime(post);
|
||||
}
|
||||
|
||||
@org.springframework.transaction.annotation.Transactional
|
||||
@Transactional
|
||||
public void deleteComment(String username, Long id) {
|
||||
User user = userRepository.findByUsername(username)
|
||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||
@@ -164,7 +167,7 @@ public class CommentService {
|
||||
deleteCommentCascade(comment);
|
||||
}
|
||||
|
||||
@org.springframework.transaction.annotation.Transactional
|
||||
@Transactional
|
||||
public void deleteCommentCascade(Comment comment) {
|
||||
List<Comment> replies = commentRepository.findByParentOrderByCreatedAtAsc(comment);
|
||||
for (Comment c : replies) {
|
||||
@@ -9,6 +9,8 @@ import com.openisle.service.EmailSender;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
@@ -76,23 +78,23 @@ public class NotificationService {
|
||||
emailSender.sendEmail(user.getEmail(), "您有新的回复", pushContent + ", 点击以查看: " + url);
|
||||
sendCustomPush(user, pushContent, url);
|
||||
} else if (type == NotificationType.REACTION && comment != null) {
|
||||
long count = reactionRepository.countReceived(comment.getAuthor().getUsername());
|
||||
if (count % 5 == 0) {
|
||||
String url = websiteUrl + "/messages";
|
||||
sendCustomPush(comment.getAuthor(), "你有新的互动", url);
|
||||
if (comment.getAuthor().getEmail() != null) {
|
||||
emailSender.sendEmail(comment.getAuthor().getEmail(), "你有新的互动", "你有新的互动, 点击以查看: " + url);
|
||||
}
|
||||
}
|
||||
// long count = reactionRepository.countReceived(comment.getAuthor().getUsername());
|
||||
// if (count % 5 == 0) {
|
||||
// String url = websiteUrl + "/messages";
|
||||
// sendCustomPush(comment.getAuthor(), "你有新的互动", url);
|
||||
// if (comment.getAuthor().getEmail() != null) {
|
||||
// emailSender.sendEmail(comment.getAuthor().getEmail(), "你有新的互动", "你有新的互动, 点击以查看: " + url);
|
||||
// }
|
||||
// }
|
||||
} else if (type == NotificationType.REACTION && post != null) {
|
||||
long count = reactionRepository.countReceived(post.getAuthor().getUsername());
|
||||
if (count % 5 == 0) {
|
||||
String url = websiteUrl + "/messages";
|
||||
sendCustomPush(post.getAuthor(), "你有新的互动", url);
|
||||
if (post.getAuthor().getEmail() != null) {
|
||||
emailSender.sendEmail(post.getAuthor().getEmail(), "你有新的互动", "你有新的互动, 点击以查看: " + url);
|
||||
}
|
||||
}
|
||||
// long count = reactionRepository.countReceived(post.getAuthor().getUsername());
|
||||
// if (count % 5 == 0) {
|
||||
// String url = websiteUrl + "/messages";
|
||||
// sendCustomPush(post.getAuthor(), "你有新的互动", url);
|
||||
// if (post.getAuthor().getEmail() != null) {
|
||||
// emailSender.sendEmail(post.getAuthor().getEmail(), "你有新的互动", "你有新的互动, 点击以查看: " + url);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.List;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class PostService {
|
||||
@@ -143,6 +144,7 @@ public class PostService {
|
||||
return post;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Post viewPost(Long id, String viewer) {
|
||||
Post post = postRepository.findById(id)
|
||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||
@@ -164,9 +166,8 @@ public class PostService {
|
||||
if (viewer != null && !viewer.equals(post.getAuthor().getUsername())) {
|
||||
User viewerUser = userRepository.findByUsername(viewer).orElse(null);
|
||||
if (viewerUser != null) {
|
||||
notificationRepository.deleteByTypeAndFromUserAndPost(NotificationType.POST_VIEWED, viewerUser, post);
|
||||
notificationService.createNotification(post.getAuthor(), NotificationType.POST_VIEWED, post, null, null, viewerUser, null, null);
|
||||
} else {
|
||||
notificationService.createNotification(post.getAuthor(), NotificationType.POST_VIEWED, post, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
return post;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user