mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-31 06:57:35 +08:00
Merge pull request #178 from nagisa77/codex/implement-user-reaction-rules-and-add-new-types
Update reaction feature
This commit is contained in:
@@ -58,7 +58,15 @@ const iconMap = {
|
|||||||
LIKE: '❤️',
|
LIKE: '❤️',
|
||||||
DISLIKE: '👎',
|
DISLIKE: '👎',
|
||||||
RECOMMEND: '👏',
|
RECOMMEND: '👏',
|
||||||
ANGRY: '😡'
|
ANGRY: '😡',
|
||||||
|
FLUSHED: '😳',
|
||||||
|
STAR_STRUCK: '🤩',
|
||||||
|
ROFL: '🤣',
|
||||||
|
HOLDING_BACK_TEARS: '🥹',
|
||||||
|
MIND_BLOWN: '🤯',
|
||||||
|
POOP: '💩',
|
||||||
|
CLOWN: '🤡',
|
||||||
|
SKULL: '☠️'
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -177,7 +177,15 @@ export default {
|
|||||||
LIKE: '❤️',
|
LIKE: '❤️',
|
||||||
DISLIKE: '👎',
|
DISLIKE: '👎',
|
||||||
RECOMMEND: '👏',
|
RECOMMEND: '👏',
|
||||||
ANGRY: '😡'
|
ANGRY: '😡',
|
||||||
|
FLUSHED: '😳',
|
||||||
|
STAR_STRUCK: '🤩',
|
||||||
|
ROFL: '🤣',
|
||||||
|
HOLDING_BACK_TEARS: '🥹',
|
||||||
|
MIND_BLOWN: '🤯',
|
||||||
|
POOP: '💩',
|
||||||
|
CLOWN: '🤡',
|
||||||
|
SKULL: '☠️'
|
||||||
}
|
}
|
||||||
|
|
||||||
const sanitizeDescription = (text) => {
|
const sanitizeDescription = (text) => {
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ import lombok.Setter;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Table(name = "reactions")
|
@Table(name = "reactions",
|
||||||
|
uniqueConstraints = {
|
||||||
|
@UniqueConstraint(columnNames = {"user_id", "post_id", "type"}),
|
||||||
|
@UniqueConstraint(columnNames = {"user_id", "comment_id", "type"})
|
||||||
|
})
|
||||||
public class Reaction {
|
public class Reaction {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
|||||||
@@ -7,5 +7,13 @@ public enum ReactionType {
|
|||||||
LIKE,
|
LIKE,
|
||||||
DISLIKE,
|
DISLIKE,
|
||||||
RECOMMEND,
|
RECOMMEND,
|
||||||
ANGRY
|
ANGRY,
|
||||||
|
FLUSHED,
|
||||||
|
STAR_STRUCK,
|
||||||
|
ROFL,
|
||||||
|
HOLDING_BACK_TEARS,
|
||||||
|
MIND_BLOWN,
|
||||||
|
POOP,
|
||||||
|
CLOWN,
|
||||||
|
SKULL
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ public class ReactionService {
|
|||||||
.orElseThrow(() -> new IllegalArgumentException("User not found"));
|
.orElseThrow(() -> new IllegalArgumentException("User not found"));
|
||||||
Post post = postRepository.findById(postId)
|
Post post = postRepository.findById(postId)
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Post not found"));
|
.orElseThrow(() -> new IllegalArgumentException("Post not found"));
|
||||||
|
java.util.Optional<Reaction> existing =
|
||||||
|
reactionRepository.findByUserAndPostAndType(user, post, type);
|
||||||
|
if (existing.isPresent()) {
|
||||||
|
reactionRepository.delete(existing.get());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Reaction reaction = new Reaction();
|
Reaction reaction = new Reaction();
|
||||||
reaction.setUser(user);
|
reaction.setUser(user);
|
||||||
reaction.setPost(post);
|
reaction.setPost(post);
|
||||||
@@ -44,6 +50,12 @@ public class ReactionService {
|
|||||||
.orElseThrow(() -> new IllegalArgumentException("User not found"));
|
.orElseThrow(() -> new IllegalArgumentException("User not found"));
|
||||||
Comment comment = commentRepository.findById(commentId)
|
Comment comment = commentRepository.findById(commentId)
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Comment not found"));
|
.orElseThrow(() -> new IllegalArgumentException("Comment not found"));
|
||||||
|
java.util.Optional<Reaction> existing =
|
||||||
|
reactionRepository.findByUserAndCommentAndType(user, comment, type);
|
||||||
|
if (existing.isPresent()) {
|
||||||
|
reactionRepository.delete(existing.get());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Reaction reaction = new Reaction();
|
Reaction reaction = new Reaction();
|
||||||
reaction.setUser(user);
|
reaction.setUser(user);
|
||||||
reaction.setComment(comment);
|
reaction.setComment(comment);
|
||||||
|
|||||||
Reference in New Issue
Block a user