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