Skip to content

Commit

Permalink
feat: added pending property to message (#104)
Browse files Browse the repository at this point in the history
* feat: added `pending` property to message

* refactor: lint fix
  • Loading branch information
vishalnarkhede authored Jun 26, 2023
1 parent 2eeab00 commit 46eef4f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/main/java/io/getstream/chat/java/models/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ public static class MessageSendRequestData {
@JsonProperty("is_pending_message")
private Boolean isPendingMessage;

@Nullable
@JsonProperty("pending")
private Boolean pending;

@Nullable
@JsonProperty("pending_message_metadata")
private Map<String, Object> pendingMessageMetadata;
Expand Down Expand Up @@ -1182,7 +1186,7 @@ public MessageCommitRequest(@NotNull String messageId) {

@Override
protected Call<MessageCommitResponse> generateCall(Client client) {
return client.create(MessageService.class).commit(messageId, this.internalBuild());
return client.create(MessageService.class).commit(messageId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.getstream.chat.java.services;

import io.getstream.chat.java.models.Message.MessageCommitRequestData;
import io.getstream.chat.java.models.Message.MessageCommitResponse;
import io.getstream.chat.java.models.Message.MessageDeleteResponse;
import io.getstream.chat.java.models.Message.MessageGetManyResponse;
Expand Down Expand Up @@ -56,9 +55,7 @@ Call<MessageSearchResponse> search(
@NotNull @ToJson @Query("payload") MessageSearchRequestData messageSearchRequestData);

@POST("messages/{id}/commit")
Call<MessageCommitResponse> commit(
@NotNull @Path("id") String messageId,
@NotNull @Body MessageCommitRequestData messageCommitRequestData);
Call<MessageCommitResponse> commit(@NotNull @Path("id") String messageId);

@Multipart
@Headers("X-Stream-LogRequestBody: false")
Expand Down
29 changes: 25 additions & 4 deletions src/test/java/io/getstream/chat/java/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import io.getstream.chat.java.services.framework.DefaultClient;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -394,6 +391,29 @@ void whenDeletingSvgImage_thenNoException() {
() -> Message.deleteImage(testChannel.getType(), testChannel.getId(), url).request());
}

@DisplayName("Can send a pending message")
@Test
void whenSendingPending() {
String text = "This is a message";
MessageRequestObject messageRequest =
MessageRequestObject.builder().text(text).userId(testUserRequestObject.getId()).build();
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put("boo", "cute");

Message message =
Assertions.assertDoesNotThrow(
() ->
Message.send(testChannel.getType(), testChannel.getId())
.message(messageRequest)
.isPendingMessage(true)
.pendingMessageMetadata(metadata)
.request())
.getMessage();
Assertions.assertNull(message.getDeletedAt());

Assertions.assertDoesNotThrow(() -> Message.commit(message.getId()).request());
}

@DisplayName("Can delete a message")
@Test
void whenDeletingMessage_thenIsDeleted() {
Expand All @@ -405,6 +425,7 @@ void whenDeletingMessage_thenIsDeleted() {
() ->
Message.send(testChannel.getType(), testChannel.getId())
.message(messageRequest)
.pending(true)
.request())
.getMessage();
Assertions.assertNull(message.getDeletedAt());
Expand Down

0 comments on commit 46eef4f

Please sign in to comment.