diff --git a/src/main/java/io/getstream/chat/java/models/Flag.java b/src/main/java/io/getstream/chat/java/models/Flag.java index f20961d4..7abfbab6 100644 --- a/src/main/java/io/getstream/chat/java/models/Flag.java +++ b/src/main/java/io/getstream/chat/java/models/Flag.java @@ -5,6 +5,8 @@ import io.getstream.chat.java.models.Flag.FlagCreateRequestData.FlagCreateRequest; import io.getstream.chat.java.models.Flag.FlagDeleteRequestData.FlagDeleteRequest; import io.getstream.chat.java.models.Flag.FlagMessageQueryRequestData.FlagMessageQueryRequest; +import io.getstream.chat.java.models.Flag.QueryFlagReportsRequestData.QueryFlagReportsRequest; +import io.getstream.chat.java.models.Flag.ReviewFlagReportRequestData.ReviewFlagReportRequest; import io.getstream.chat.java.models.Message.Moderation; import io.getstream.chat.java.models.User.UserRequestObject; import io.getstream.chat.java.models.framework.StreamRequest; @@ -102,6 +104,51 @@ public static class MessageFlag { private Date rejectedAt; } + @Data + @NoArgsConstructor + public static class FlagReport { + @NotNull + @JsonProperty("id") + private String Id; + + @Nullable + @JsonProperty("message") + private Message message; + + @Nullable + @JsonProperty("flags_count") + private Integer flagsCount; + + @Nullable + @JsonProperty("message_user_id") + private String messageUserId; + + @Nullable + @JsonProperty("channel_cid") + private String channelCid; + + @Nullable + @JsonProperty("created_at") + private Date createdAt; + + @Nullable + @JsonProperty("updated_at") + private Date updatedAt; + } + + @Data + @NoArgsConstructor + @EqualsAndHashCode(callSuper = true) + public static class ExtendedFlagReport extends FlagReport { + @NotNull + @JsonProperty("review_result") + private String reviewResult; + + @Nullable + @JsonProperty("review_details") + private Map reviewDetails; + } + @Data @NoArgsConstructor public static class MessageModerationResult { @@ -224,7 +271,7 @@ protected Call generateCall(Client client) { buildMethodName = "internalBuild") public static class FlagMessageQueryRequestData { @Nullable - @JsonProperty("filterConditions") + @JsonProperty("filter_conditions") @Singular private Map filterConditions; @@ -252,6 +299,71 @@ protected Call generateCall(Client client) { } } + @Builder( + builderClassName = "QueryFlagReportsRequest", + builderMethodName = "", + buildMethodName = "internalBuild") + public static class QueryFlagReportsRequestData { + @Nullable + @JsonProperty("filter_conditions") + @Singular + private Map filterConditions; + + @Nullable + @JsonProperty("limit") + private Integer limit; + + @Nullable + @JsonProperty("offset") + private Integer offset; + + @Nullable + @JsonProperty("user_id") + private String userId; + + @Nullable + @JsonProperty("user") + private UserRequestObject user; + + public static class QueryFlagReportsRequest extends StreamRequest { + @Override + protected Call generateCall(Client client) { + return client.create(FlagService.class).queryFlagReports(this.internalBuild()); + } + } + } + + @Builder( + builderClassName = "ReviewFlagReportRequest", + builderMethodName = "", + buildMethodName = "internalBuild") + public static class ReviewFlagReportRequestData { + @NotNull + @JsonProperty("review_result") + private String reviewResult; + + @Nullable + @JsonProperty("review_details") + private Map reviewDetails; + + @Nullable + @JsonProperty("user_id") + private String userId; + + public static class ReviewFlagReportRequest extends StreamRequest { + @NotNull private String id; + + public ReviewFlagReportRequest(@NotNull String id) { + this.id = id; + } + + @Override + protected Call generateCall(Client client) { + return client.create(FlagService.class).reviewFlagReport(id, this.internalBuild()); + } + } + } + @Data @NoArgsConstructor @EqualsAndHashCode(callSuper = true) @@ -279,6 +391,24 @@ public static class FlagMessageQueryResponse extends StreamResponseObject { private List flags; } + @Data + @NoArgsConstructor + @EqualsAndHashCode(callSuper = true) + public static class QueryFlagReportsResponse extends StreamResponseObject { + @NotNull + @JsonProperty("flag_reports") + private List flagReports; + } + + @Data + @NoArgsConstructor + @EqualsAndHashCode(callSuper = true) + public static class ReviewFlagReportResponse extends StreamResponseObject { + @NotNull + @JsonProperty("flag_report") + private ExtendedFlagReport flagReport; + } + /** * Creates a create request * @@ -308,4 +438,24 @@ public static FlagDeleteRequest delete() { public static FlagMessageQueryRequest queryMessages() { return new FlagMessageQueryRequest(); } + + /** + * Creates a query flag report request + * + * @return the created request + */ + @NotNull + public static QueryFlagReportsRequest queryFlagReports() { + return new QueryFlagReportsRequest(); + } + + /** + * Creates a review flag report request + * + * @return the created request + */ + @NotNull + public static ReviewFlagReportRequest reviewFlagReport(String id) { + return new ReviewFlagReportRequest(id); + } } diff --git a/src/main/java/io/getstream/chat/java/services/FlagService.java b/src/main/java/io/getstream/chat/java/services/FlagService.java index 2d5a789e..bb019982 100644 --- a/src/main/java/io/getstream/chat/java/services/FlagService.java +++ b/src/main/java/io/getstream/chat/java/services/FlagService.java @@ -6,13 +6,14 @@ import io.getstream.chat.java.models.Flag.FlagDeleteResponse; import io.getstream.chat.java.models.Flag.FlagMessageQueryRequestData; import io.getstream.chat.java.models.Flag.FlagMessageQueryResponse; +import io.getstream.chat.java.models.Flag.QueryFlagReportsRequestData; +import io.getstream.chat.java.models.Flag.QueryFlagReportsResponse; +import io.getstream.chat.java.models.Flag.ReviewFlagReportRequestData; +import io.getstream.chat.java.models.Flag.ReviewFlagReportResponse; import io.getstream.chat.java.services.framework.ToJson; import org.jetbrains.annotations.NotNull; import retrofit2.Call; -import retrofit2.http.Body; -import retrofit2.http.GET; -import retrofit2.http.POST; -import retrofit2.http.Query; +import retrofit2.http.*; public interface FlagService { @@ -25,4 +26,13 @@ public interface FlagService { @GET("moderation/flags/message") Call messageQuery( @NotNull @ToJson @Query("payload") FlagMessageQueryRequestData flagMessageQueryRequestData); + + @POST("moderation/reports") + Call queryFlagReports( + @NotNull @Body QueryFlagReportsRequestData queryFlagReportsRequestData); + + @PATCH("moderation/reports/{id}") + Call reviewFlagReport( + @NotNull @Path("id") String id, + @NotNull @Body ReviewFlagReportRequestData reviewFlagReportRequestData); } diff --git a/src/test/java/io/getstream/chat/java/FlagTest.java b/src/test/java/io/getstream/chat/java/FlagTest.java index acd30bfa..6260401f 100644 --- a/src/test/java/io/getstream/chat/java/FlagTest.java +++ b/src/test/java/io/getstream/chat/java/FlagTest.java @@ -107,4 +107,46 @@ void whenQueryingMessageFlags_thenRetrieved() { response.getFlags().stream() .anyMatch(flag -> flag.getMessage().getId().equals(message.getId()))); } + + @DisplayName("Can look up flag reports") + @Test + void whenQueryingFlagReports_thenRetrieved() { + Message message = Assertions.assertDoesNotThrow(() -> sendTestMessage()); + Assertions.assertDoesNotThrow( + () -> Flag.create().targetMessageId(message.getId()).user(testUserRequestObject).request()); + var flagReports = + Assertions.assertDoesNotThrow( + () -> + Flag.queryFlagReports() + .filterCondition("message_id", message.getId()) + .request() + .getFlagReports()); + Assertions.assertEquals(message.getId(), flagReports.get(0).getMessage().getId()); + } + + @DisplayName("Can send flag report") + @Test + void whenReviewingFlagReports_thenSucceeds() { + Message message = Assertions.assertDoesNotThrow(() -> sendTestMessage()); + Assertions.assertDoesNotThrow( + () -> Flag.create().targetMessageId(message.getId()).user(testUserRequestObject).request()); + var flagReports = + Assertions.assertDoesNotThrow( + () -> + Flag.queryFlagReports() + .filterCondition("message_id", message.getId()) + .request() + .getFlagReports()); + Assertions.assertEquals(message.getId(), flagReports.get(0).getMessage().getId()); + + var report = + Assertions.assertDoesNotThrow( + () -> + Flag.reviewFlagReport(flagReports.get(0).getId()) + .reviewResult("reviewed") + .userId(testUserRequestObject.getId()) + .request() + .getFlagReport()); + Assertions.assertEquals(message.getId(), report.getMessage().getId()); + } }