Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 신고 숨김 처리 시 디스코드 알람 발송 기능 구현 #173

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ public void createReportedComment(Feed feed, Long commentId, User user, Reported

reportedCommentService.createReportedComment(comment, user, reportedType);

if (reportedCommentService.shouldHideComment(comment, reportedType)) {
int reportedCount = reportedCommentService.getReportedCountByReportedType(comment, reportedType);
boolean shouldHide = reportedCount >= 3;

if (shouldHide) {
comment.hideComment();
}

messageService.sendDiscordWebhookMessage(
DiscordWebhookMessage.of(
MessageFormatter.formatCommentReportMessage(comment, reportedType, commentCreatedUser)));
MessageFormatter.formatCommentReportMessage(comment, reportedType, commentCreatedUser,
reportedCount, shouldHide)));
}

private Comment getCommentOrException(Long commentId) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/websoso/WSSServer/service/FeedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,16 @@ public void reportFeed(User user, Long feedId, ReportedType reportedType) {

reportedFeedService.createReportedFeed(feed, user, reportedType);

if (reportedFeedService.shouldHideFeed(feed, reportedType)) {
int reportedCount = reportedFeedService.getReportedCountByReportedType(feed, reportedType);
boolean shouldHide = reportedCount >= 3;

if (shouldHide) {
feed.hideFeed();
}

messageService.sendDiscordWebhookMessage(
DiscordWebhookMessage.of(MessageFormatter.formatFeedReportMessage(feed, reportedType)));
DiscordWebhookMessage.of(
MessageFormatter.formatFeedReportMessage(feed, reportedType, reportedCount, shouldHide)));
}

public void reportComment(User user, Long feedId, Long commentId, ReportedType reportedType) {
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/org/websoso/WSSServer/service/MessageFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,48 @@ public class MessageFormatter {
"[신고된 피드 작성자]\n" +
"유저 아이디 : %d\n" +
"유저 닉네임 : %s\n\n" +
"[신고된 피드 내용]\n%s\n```";
"[신고된 피드 내용]\n%s\n\n" +
"[신고 횟수]\n총 신고 횟수 %d회.\n" +
"%s\n```";

private static final String COMMENT_REPORT_MESSAGE =
"```[%s] 피드 댓글 %s 신고가 접수되었습니다.\n\n" +
"[신고된 댓글 작성자]\n" +
"유저 아이디 : %d\n" +
"유저 닉네임 : %s\n\n" +
"[신고된 댓글 내용]\n%s\n```";
"[신고된 댓글 내용]\n%s\n\n" +
"[신고 횟수]\n총 신고 횟수 %d회.\n" +
"%s\n```";

public static String formatFeedReportMessage(Feed feed, ReportedType reportedType, int reportedCount,
boolean isHidden) {
String hiddenMessage = isHidden ? "해당 피드는 숨김 처리되었습니다." : "해당 피드는 숨김 처리되지 않았습니다.";

public static String formatFeedReportMessage(Feed feed, ReportedType reportedType) {
return String.format(
FEED_REPORT_MESSAGE,
LocalDateTime.now().format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)),
reportedType.getDescription(),
feed.getUser().getUserId(),
feed.getUser().getNickname(),
feed.getFeedContent()
feed.getFeedContent(),
reportedCount,
hiddenMessage
);
}

public static String formatCommentReportMessage(Comment comment, ReportedType reportedType, User user) {
public static String formatCommentReportMessage(Comment comment, ReportedType reportedType, User user,
int reportedCount, boolean isHidden) {
String hiddenMessage = isHidden ? "해당 댓글은 숨김 처리되었습니다." : "해당 댓글는 숨김 처리되지 않았습니다.";

return String.format(
COMMENT_REPORT_MESSAGE,
LocalDateTime.now().format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)),
reportedType.getDescription(),
user.getUserId(),
user.getNickname(),
comment.getCommentContent()
comment.getCommentContent(),
reportedCount,
hiddenMessage
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void createReportedComment(Comment comment, User user, ReportedType repor
reportedCommentRepository.save(ReportedComment.create(comment, user, reportedType));
}

public boolean shouldHideComment(Comment comment, ReportedType reportedType) {
return reportedCommentRepository.countByCommentAndReportedType(comment, reportedType) >= 3;
public int getReportedCountByReportedType(Comment comment, ReportedType reportedType) {
return reportedCommentRepository.countByCommentAndReportedType(comment, reportedType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void createReportedFeed(Feed feed, User user, ReportedType reportedType)
reportedFeedRepository.save(ReportedFeed.create(feed, user, reportedType));
}

public boolean shouldHideFeed(Feed feed, ReportedType reportedType) {
return reportedFeedRepository.countByFeedAndReportedType(feed, reportedType) >= 3;
public int getReportedCountByReportedType(Feed feed, ReportedType reportedType) {
return reportedFeedRepository.countByFeedAndReportedType(feed, reportedType);
}

}
Loading