Skip to content

Commit

Permalink
feat: added support for pending messages (#100)
Browse files Browse the repository at this point in the history
* feat: added support for pending messages

* feat: add commit pending message endpoint

* refactor: fixing lint issues
  • Loading branch information
vishalnarkhede authored May 25, 2023
1 parent 40b93f9 commit 7105068
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/io/getstream/chat/java/models/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,30 @@ public static class DeviceError {
private String errorMessage;
}

@Builder
@Setter
public static class AsyncModerationCallback {
@Nullable
@JsonProperty("mode")
private String mode;

@Nullable
@JsonProperty("server_url")
private String serverUrl;
}

@Builder
@Setter
public static class AsyncModerationConfigRequestObject {
@Nullable
@JsonProperty("callback")
private AsyncModerationCallback callback;

@Nullable
@JsonProperty("timeout_ms")
private Number timeoutMs;
}

@Builder
@Setter
public static class FileUploadConfigRequestObject {
Expand Down Expand Up @@ -665,6 +689,11 @@ public static class AppUpdateRequestData {
@JsonInclude(Include.NON_NULL)
private Boolean asyncURLEnrichEnabled;

@Nullable
@JsonProperty("async_moderation_config")
@JsonInclude(Include.NON_NULL)
private AsyncModerationConfigRequestObject asyncModerationConfig;

@Nullable
@JsonProperty("sqs_url")
@JsonInclude(Include.NON_NULL)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/getstream/chat/java/models/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,10 @@ public static class ChannelGetResponse extends StreamResponseObject {
@JsonProperty("pinned_messages")
private List<Message> pinnedMessages;

@Nullable
@JsonProperty("pending_messages")
private List<Message> pendingMessages;

@Nullable
@JsonProperty("watcher_count")
private Integer watcher_count;
Expand Down
47 changes: 47 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 @@ -5,6 +5,7 @@
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.Message.MessageCommitRequestData.MessageCommitRequest;
import io.getstream.chat.java.models.Message.MessagePartialUpdateRequestData.MessagePartialUpdateRequest;
import io.getstream.chat.java.models.Message.MessageRunCommandActionRequestData.MessageRunCommandActionRequest;
import io.getstream.chat.java.models.Message.MessageSearchRequestData.MessageSearchRequest;
Expand Down Expand Up @@ -695,6 +696,14 @@ public static class MessageSendRequestData {
@JsonProperty("skip_push")
private Boolean skipPush;

@Nullable
@JsonProperty("is_pending_message")
private Boolean isPendingMessage;

@Nullable
@JsonProperty("pending_message_metadata")
private Map<String, Object> pendingMessageMetadata;

public static class MessageSendRequest extends StreamRequest<MessageSendResponse> {
@NotNull private String channelId;

Expand Down Expand Up @@ -1159,6 +1168,25 @@ protected Call<MessageTranslateResponse> generateCall(Client client) {
}
}

@Builder(
builderClassName = "MessageCommitRequest",
builderMethodName = "",
buildMethodName = "internalBuild")
public static class MessageCommitRequestData {
public static class MessageCommitRequest extends StreamRequest<MessageCommitResponse> {
@NotNull private String messageId;

public MessageCommitRequest(@NotNull String messageId) {
this.messageId = messageId;
}

@Override
protected Call<MessageCommitResponse> generateCall(Client client) {
return client.create(MessageService.class).commit(messageId, this.internalBuild());
}
}
}

@Builder(
builderClassName = "MessagePartialUpdateRequest",
builderMethodName = "",
Expand Down Expand Up @@ -1224,6 +1252,15 @@ public static class MessageUpdateResponse extends StreamResponseObject {
private Message message;
}

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public static class MessageCommitResponse extends StreamResponseObject {
@NotNull
@JsonProperty("message")
private Message message;
}

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
Expand Down Expand Up @@ -1489,6 +1526,16 @@ public static MessageTranslateRequest translate(@NotNull String messageId) {
return new MessageTranslateRequest(messageId);
}

/**
* Creates a commit message request
*
* @param messageId the pending message id to commit
* @return the created request
*/
@NotNull
public static MessageCommitRequest commit(@NotNull String messageId) {
return new MessageCommitRequest(messageId);
}
/**
* Creates a flag request
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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;
import io.getstream.chat.java.models.Message.MessageGetRepliesResponse;
Expand Down Expand Up @@ -53,6 +55,11 @@ Call<MessageUpdateResponse> update(
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);

@Multipart
@Headers("X-Stream-LogRequestBody: false")
@POST("channels/{type}/{id}/file")
Expand Down

0 comments on commit 7105068

Please sign in to comment.