Skip to content

Commit

Permalink
feat: added support for force_moderation on message (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede authored Jul 26, 2023
1 parent ea01354 commit d71ccba
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/io/getstream/chat/java/models/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,10 @@ public static class MessageSendRequestData {
@JsonProperty("pending")
private Boolean pending;

@Nullable
@JsonProperty("force_moderation")
private Boolean forceModeration;

@Nullable
@JsonProperty("pending_message_metadata")
private Map<String, Object> pendingMessageMetadata;
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/io/getstream/chat/java/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.getstream.chat.java.models.App;
import io.getstream.chat.java.models.App.FileUploadConfigRequestObject;
import io.getstream.chat.java.models.Blocklist;
import io.getstream.chat.java.models.ChannelType;
import io.getstream.chat.java.models.Language;
import io.getstream.chat.java.models.Message;
import io.getstream.chat.java.models.Message.*;
Expand Down Expand Up @@ -514,6 +516,7 @@ void whenRetrievingReplies_thenAreRetrieved() {
@Test
void whenExecutingCommandAction_thenNoException() {
String text = "/giphy boom";

MessageRequestObject messageCreateRequest =
MessageRequestObject.builder().text(text).userId(testUserRequestObject.getId()).build();
Message message =
Expand Down Expand Up @@ -643,4 +646,49 @@ void whenUnpinningAMessage_thenIsUnpinned() {
.getMessage();
Assertions.assertFalse(unPinnedMessage.getPinned());
}

@DisplayName("Can force enable or disable moderation on a message")
@Test
void whenForcingModerationOnAMessage_thenIsForced() {
String text = "This is a shitty message";
Assertions.assertDoesNotThrow(
() -> Blocklist.create().name("swear-blocklist").words(Arrays.asList("shitty")).request());

Assertions.assertDoesNotThrow(() -> Thread.sleep(2000));

Assertions.assertDoesNotThrow(
() ->
ChannelType.update(testChannel.getType())
.blocklist("swear-blocklist")
.blocklistBehavior(ChannelType.BlocklistBehavior.BLOCK)
.request());

Assertions.assertDoesNotThrow(() -> Thread.sleep(5000));

MessageRequestObject messageRequest1 =
MessageRequestObject.builder().text(text).userId(testUserRequestObject.getId()).build();
Message msg1 =
Assertions.assertDoesNotThrow(
() ->
Message.send(testChannel.getType(), testChannel.getId())
.forceModeration(true)
.message(messageRequest1)
.request())
.getMessage();

Assertions.assertTrue(msg1.getText().equals("Message was blocked by moderation policies"));

MessageRequestObject messageRequest2 =
MessageRequestObject.builder().text(text).userId(testUserRequestObject.getId()).build();
Message msg2 =
Assertions.assertDoesNotThrow(
() ->
Message.send(testChannel.getType(), testChannel.getId())
.forceModeration(false)
.message(messageRequest2)
.request())
.getMessage();

Assertions.assertTrue(msg2.getText().equals(text));
}
}

0 comments on commit d71ccba

Please sign in to comment.