Skip to content

Commit 5c415db

Browse files
authored
[CHA-794] Add Query Threads (#180)
* Add Query Threads * Fix lint * Fix ambigous Thread.sleep * Reuse test user
1 parent 866d832 commit 5c415db

File tree

5 files changed

+525
-5
lines changed

5 files changed

+525
-5
lines changed
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
package io.getstream.chat.java.models;
2+
3+
import com.fasterxml.jackson.annotation.*;
4+
import io.getstream.chat.java.exceptions.StreamException;
5+
import io.getstream.chat.java.models.framework.StreamRequest;
6+
import io.getstream.chat.java.models.framework.StreamResponseObject;
7+
import io.getstream.chat.java.services.ThreadService;
8+
import io.getstream.chat.java.services.framework.Client;
9+
import java.util.Date;
10+
import java.util.List;
11+
import java.util.Map;
12+
import lombok.*;
13+
import org.jetbrains.annotations.NotNull;
14+
import org.jetbrains.annotations.Nullable;
15+
import retrofit2.Call;
16+
17+
/** Represents thread functionality in Stream Chat. */
18+
@Data
19+
public class Thread {
20+
/** A thread participant. */
21+
@Data
22+
@NoArgsConstructor
23+
public static class ThreadParticipant {
24+
@Nullable
25+
@JsonProperty("app_pk")
26+
private Integer appPk;
27+
28+
@Nullable
29+
@JsonProperty("channel_cid")
30+
private String channelCid;
31+
32+
@Nullable
33+
@JsonProperty("last_thread_message_at")
34+
private Date lastThreadMessageAt;
35+
36+
@Nullable
37+
@JsonProperty("thread_id")
38+
private String threadId;
39+
40+
@Nullable
41+
@JsonProperty("user_id")
42+
private String userId;
43+
44+
@Nullable
45+
@JsonProperty("user")
46+
private User user;
47+
48+
@Nullable
49+
@JsonProperty("created_at")
50+
private Date createdAt;
51+
52+
@Nullable
53+
@JsonProperty("left_thread_at")
54+
private Date leftThreadAt;
55+
56+
@Nullable
57+
@JsonProperty("last_read_at")
58+
private Date lastReadAt;
59+
60+
@Nullable
61+
@JsonProperty("custom")
62+
private Map<String, Object> custom;
63+
}
64+
65+
/** A thread object containing thread data and metadata. */
66+
@Data
67+
@NoArgsConstructor
68+
public static class ThreadObject {
69+
@Nullable
70+
@JsonProperty("app_pk")
71+
private Integer appPk;
72+
73+
@NotNull
74+
@JsonProperty("channel_cid")
75+
private String channelCid;
76+
77+
@Nullable
78+
@JsonProperty("channel")
79+
private Channel channel;
80+
81+
@NotNull
82+
@JsonProperty("parent_message_id")
83+
private String parentMessageId;
84+
85+
@Nullable
86+
@JsonProperty("parent_message")
87+
private Message parentMessage;
88+
89+
@NotNull
90+
@JsonProperty("created_by_user_id")
91+
private String createdByUserId;
92+
93+
@Nullable
94+
@JsonProperty("created_by")
95+
private User createdBy;
96+
97+
@Nullable
98+
@JsonProperty("reply_count")
99+
private Integer replyCount;
100+
101+
@Nullable
102+
@JsonProperty("participant_count")
103+
private Integer participantCount;
104+
105+
@Nullable
106+
@JsonProperty("active_participant_count")
107+
private Integer activeParticipantCount;
108+
109+
@Nullable
110+
@JsonProperty("thread_participants")
111+
private List<ThreadParticipant> participants;
112+
113+
@Nullable
114+
@JsonProperty("last_message_at")
115+
private Date lastMessageAt;
116+
117+
@NotNull
118+
@JsonProperty("created_at")
119+
private Date createdAt;
120+
121+
@NotNull
122+
@JsonProperty("updated_at")
123+
private Date updatedAt;
124+
125+
@Nullable
126+
@JsonProperty("deleted_at")
127+
private Date deletedAt;
128+
129+
@NotNull
130+
@JsonProperty("title")
131+
private String title;
132+
133+
@Nullable
134+
@JsonProperty("custom")
135+
private Map<String, Object> custom;
136+
137+
@Nullable
138+
@JsonProperty("latest_replies")
139+
private List<Message> latestReplies;
140+
141+
@Nullable
142+
@JsonProperty("read")
143+
private List<Channel.ChannelRead> read;
144+
145+
@Nullable
146+
@JsonProperty("draft")
147+
private Draft.DraftObject draft;
148+
}
149+
150+
/** Response for querying threads. */
151+
@Data
152+
@NoArgsConstructor
153+
@EqualsAndHashCode(callSuper = true)
154+
public static class QueryThreadsResponse extends StreamResponseObject {
155+
@NotNull
156+
@JsonProperty("threads")
157+
private List<ThreadObject> threads;
158+
159+
@Nullable
160+
@JsonProperty("next")
161+
private String next;
162+
163+
@Nullable
164+
@JsonProperty("prev")
165+
private String prev;
166+
}
167+
168+
/** Request data for querying threads. */
169+
@Builder(
170+
builderClassName = "QueryThreadsRequest",
171+
builderMethodName = "",
172+
buildMethodName = "internalBuild")
173+
public static class QueryThreadsRequestData {
174+
@Nullable
175+
@JsonProperty("filter")
176+
private Map<String, Object> filter;
177+
178+
@Singular
179+
@Nullable
180+
@JsonProperty("sort")
181+
private List<Sort> sorts;
182+
183+
@Nullable
184+
@JsonProperty("watch")
185+
private Boolean watch;
186+
187+
@Nullable
188+
@JsonProperty("user_id")
189+
private String userId;
190+
191+
@Nullable
192+
@JsonProperty("user")
193+
private User.UserRequestObject user;
194+
195+
@Nullable
196+
@JsonProperty("limit")
197+
private Integer limit;
198+
199+
@Nullable
200+
@JsonProperty("next")
201+
private String next;
202+
203+
@Nullable
204+
@JsonProperty("prev")
205+
private String prev;
206+
207+
public static class QueryThreadsRequest extends StreamRequest<QueryThreadsResponse> {
208+
public QueryThreadsRequest() {}
209+
210+
@Override
211+
protected Call<QueryThreadsResponse> generateCall(Client client) throws StreamException {
212+
return client.create(ThreadService.class).queryThreads(this.internalBuild());
213+
}
214+
}
215+
}
216+
217+
/**
218+
* Queries threads based on the provided parameters
219+
*
220+
* @return the created request
221+
*/
222+
@NotNull
223+
public static QueryThreadsRequestData.QueryThreadsRequest queryThreads() {
224+
return new QueryThreadsRequestData.QueryThreadsRequest();
225+
}
226+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.getstream.chat.java.services;
2+
3+
import io.getstream.chat.java.models.Thread.QueryThreadsRequestData;
4+
import io.getstream.chat.java.models.Thread.QueryThreadsResponse;
5+
import org.jetbrains.annotations.NotNull;
6+
import retrofit2.Call;
7+
import retrofit2.http.*;
8+
9+
public interface ThreadService {
10+
@POST("threads")
11+
Call<QueryThreadsResponse> queryThreads(
12+
@NotNull @Body QueryThreadsRequestData queryThreadsRequestData);
13+
}

src/test/java/io/getstream/chat/java/BasicTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static void cleanChannels() throws StreamException {
7272
}
7373

7474
// wait for the channels to delete
75-
Assertions.assertDoesNotThrow(() -> Thread.sleep(500));
75+
Assertions.assertDoesNotThrow(() -> java.lang.Thread.sleep(500));
7676
}
7777
}
7878
}
@@ -109,7 +109,7 @@ private static void cleanUsers() throws StreamException {
109109
}
110110

111111
// wait for the channels to delete
112-
Assertions.assertDoesNotThrow(() -> Thread.sleep(500));
112+
Assertions.assertDoesNotThrow(() -> java.lang.Thread.sleep(500));
113113
}
114114
}
115115
}
@@ -239,7 +239,7 @@ protected static Message sendTestMessage() throws StreamException {
239239
*/
240240
protected void pause() {
241241
try {
242-
Thread.sleep(6000);
242+
java.lang.Thread.sleep(6000);
243243
} catch (InterruptedException e) {
244244
// Do nothing
245245
}
@@ -261,7 +261,7 @@ protected static void waitFor(Supplier<Boolean> predicate, Long askInterval, Lon
261261
return;
262262
}
263263

264-
Assertions.assertDoesNotThrow(() -> Thread.sleep(askInterval));
264+
Assertions.assertDoesNotThrow(() -> java.lang.Thread.sleep(askInterval));
265265
}
266266
}
267267
}

src/test/java/io/getstream/chat/java/ExportUsersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void exportUsersTest() {
3030
taskCompleted = true;
3131
break;
3232
}
33-
Assertions.assertDoesNotThrow(() -> Thread.sleep(500));
33+
Assertions.assertDoesNotThrow(() -> java.lang.Thread.sleep(500));
3434
}
3535
Assertions.assertTrue(taskCompleted);
3636
}

0 commit comments

Comments
 (0)