Skip to content
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
226 changes: 226 additions & 0 deletions src/main/java/io/getstream/chat/java/models/Thread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
package io.getstream.chat.java.models;

import com.fasterxml.jackson.annotation.*;
import io.getstream.chat.java.exceptions.StreamException;
import io.getstream.chat.java.models.framework.StreamRequest;
import io.getstream.chat.java.models.framework.StreamResponseObject;
import io.getstream.chat.java.services.ThreadService;
import io.getstream.chat.java.services.framework.Client;
import java.util.Date;
import java.util.List;
import java.util.Map;
import lombok.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import retrofit2.Call;

/** Represents thread functionality in Stream Chat. */
@Data
public class Thread {
/** A thread participant. */
@Data
@NoArgsConstructor
public static class ThreadParticipant {
@Nullable
@JsonProperty("app_pk")
private Integer appPk;

@Nullable
@JsonProperty("channel_cid")
private String channelCid;

@Nullable
@JsonProperty("last_thread_message_at")
private Date lastThreadMessageAt;

@Nullable
@JsonProperty("thread_id")
private String threadId;

@Nullable
@JsonProperty("user_id")
private String userId;

@Nullable
@JsonProperty("user")
private User user;

@Nullable
@JsonProperty("created_at")
private Date createdAt;

@Nullable
@JsonProperty("left_thread_at")
private Date leftThreadAt;

@Nullable
@JsonProperty("last_read_at")
private Date lastReadAt;

@Nullable
@JsonProperty("custom")
private Map<String, Object> custom;
}

/** A thread object containing thread data and metadata. */
@Data
@NoArgsConstructor
public static class ThreadObject {
@Nullable
@JsonProperty("app_pk")
private Integer appPk;

@NotNull
@JsonProperty("channel_cid")
private String channelCid;

@Nullable
@JsonProperty("channel")
private Channel channel;

@NotNull
@JsonProperty("parent_message_id")
private String parentMessageId;

@Nullable
@JsonProperty("parent_message")
private Message parentMessage;

@NotNull
@JsonProperty("created_by_user_id")
private String createdByUserId;

@Nullable
@JsonProperty("created_by")
private User createdBy;

@Nullable
@JsonProperty("reply_count")
private Integer replyCount;

@Nullable
@JsonProperty("participant_count")
private Integer participantCount;

@Nullable
@JsonProperty("active_participant_count")
private Integer activeParticipantCount;

@Nullable
@JsonProperty("thread_participants")
private List<ThreadParticipant> participants;

@Nullable
@JsonProperty("last_message_at")
private Date lastMessageAt;

@NotNull
@JsonProperty("created_at")
private Date createdAt;

@NotNull
@JsonProperty("updated_at")
private Date updatedAt;

@Nullable
@JsonProperty("deleted_at")
private Date deletedAt;

@NotNull
@JsonProperty("title")
private String title;

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

@Nullable
@JsonProperty("latest_replies")
private List<Message> latestReplies;

@Nullable
@JsonProperty("read")
private List<Channel.ChannelRead> read;

@Nullable
@JsonProperty("draft")
private Draft.DraftObject draft;
}

/** Response for querying threads. */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public static class QueryThreadsResponse extends StreamResponseObject {
@NotNull
@JsonProperty("threads")
private List<ThreadObject> threads;

@Nullable
@JsonProperty("next")
private String next;

@Nullable
@JsonProperty("prev")
private String prev;
}

/** Request data for querying threads. */
@Builder(
builderClassName = "QueryThreadsRequest",
builderMethodName = "",
buildMethodName = "internalBuild")
public static class QueryThreadsRequestData {
@Nullable
@JsonProperty("filter")
private Map<String, Object> filter;

@Singular
@Nullable
@JsonProperty("sort")
private List<Sort> sorts;

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

@Nullable
@JsonProperty("user_id")
private String userId;

@Nullable
@JsonProperty("user")
private User.UserRequestObject user;

@Nullable
@JsonProperty("limit")
private Integer limit;

@Nullable
@JsonProperty("next")
private String next;

@Nullable
@JsonProperty("prev")
private String prev;

public static class QueryThreadsRequest extends StreamRequest<QueryThreadsResponse> {
public QueryThreadsRequest() {}

@Override
protected Call<QueryThreadsResponse> generateCall(Client client) throws StreamException {
return client.create(ThreadService.class).queryThreads(this.internalBuild());
}
}
}

/**
* Queries threads based on the provided parameters
*
* @return the created request
*/
@NotNull
public static QueryThreadsRequestData.QueryThreadsRequest queryThreads() {
return new QueryThreadsRequestData.QueryThreadsRequest();
}
}
13 changes: 13 additions & 0 deletions src/main/java/io/getstream/chat/java/services/ThreadService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.getstream.chat.java.services;

import io.getstream.chat.java.models.Thread.QueryThreadsRequestData;
import io.getstream.chat.java.models.Thread.QueryThreadsResponse;
import org.jetbrains.annotations.NotNull;
import retrofit2.Call;
import retrofit2.http.*;

public interface ThreadService {
@POST("threads")
Call<QueryThreadsResponse> queryThreads(
@NotNull @Body QueryThreadsRequestData queryThreadsRequestData);
}
8 changes: 4 additions & 4 deletions src/test/java/io/getstream/chat/java/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static void cleanChannels() throws StreamException {
}

// wait for the channels to delete
Assertions.assertDoesNotThrow(() -> Thread.sleep(500));
Assertions.assertDoesNotThrow(() -> java.lang.Thread.sleep(500));
}
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ private static void cleanUsers() throws StreamException {
}

// wait for the channels to delete
Assertions.assertDoesNotThrow(() -> Thread.sleep(500));
Assertions.assertDoesNotThrow(() -> java.lang.Thread.sleep(500));
}
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ protected static Message sendTestMessage() throws StreamException {
*/
protected void pause() {
try {
Thread.sleep(6000);
java.lang.Thread.sleep(6000);
} catch (InterruptedException e) {
// Do nothing
}
Expand All @@ -261,7 +261,7 @@ protected static void waitFor(Supplier<Boolean> predicate, Long askInterval, Lon
return;
}

Assertions.assertDoesNotThrow(() -> Thread.sleep(askInterval));
Assertions.assertDoesNotThrow(() -> java.lang.Thread.sleep(askInterval));
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/io/getstream/chat/java/ExportUsersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void exportUsersTest() {
taskCompleted = true;
break;
}
Assertions.assertDoesNotThrow(() -> Thread.sleep(500));
Assertions.assertDoesNotThrow(() -> java.lang.Thread.sleep(500));
}
Assertions.assertTrue(taskCompleted);
}
Expand Down
Loading