Skip to content

Commit 90e06aa

Browse files
angiurgiuAndrei Giurgiu
andauthored
Angiurgiu/add missing chat thread async client options methods (Azure#21939)
* Removed the item return check on listReadReceipts for Live/Record tests. Removed .sleep statements * Added missing Options methods in ChatThreadAsyncClient * Updated incorrect test name used for logging Co-authored-by: Andrei Giurgiu <agiurg@microsoft.com>
1 parent 01c2d1c commit 90e06aa

File tree

5 files changed

+414
-0
lines changed

5 files changed

+414
-0
lines changed

sdk/communication/azure-communication-chat/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Release History
22

33
## 1.1.0-beta.1 (Unreleased)
4+
- Added method `ChatThreadAsyncClient.listParticipants(ListParticipantsOptions listParticipantsOptions)`
5+
- Added method `ChatThreadAsyncClient.listReadReceipts(ListReadReceiptOptions listReadReceiptOptions)`
46

57
## 1.0.1 (2021-05-27)
68
- Dependency versions updated.

sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatThreadAsyncClient.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,35 @@ public PagedFlux<ChatParticipant> listParticipants() {
345345
return listParticipants(listParticipantsOptions, Context.NONE);
346346
}
347347

348+
/**
349+
* Gets the participants of a thread.
350+
*
351+
* @param listParticipantsOptions The request options.
352+
* @return the participants of a thread.
353+
*/
354+
@ServiceMethod(returns = ReturnType.COLLECTION)
355+
public PagedFlux<ChatParticipant> listParticipants(ListParticipantsOptions listParticipantsOptions) {
356+
final ListParticipantsOptions serviceListParticipantsOptions =
357+
listParticipantsOptions == null ? new ListParticipantsOptions() : listParticipantsOptions;
358+
359+
try {
360+
return pagedFluxConvert(new PagedFlux<>(
361+
() -> withContext(context ->
362+
this.chatThreadClient.listChatParticipantsSinglePageAsync(
363+
chatThreadId,
364+
serviceListParticipantsOptions.getMaxPageSize(),
365+
serviceListParticipantsOptions.getSkip(),
366+
context)
367+
.onErrorMap(CommunicationErrorResponseException.class, e -> translateException(e))),
368+
nextLink -> withContext(context ->
369+
this.chatThreadClient.listChatParticipantsNextSinglePageAsync(nextLink, context)
370+
.onErrorMap(CommunicationErrorResponseException.class, e -> translateException(e)))),
371+
f -> ChatParticipantConverter.convert(f));
372+
} catch (RuntimeException ex) {
373+
return new PagedFlux<>(() -> monoError(logger, ex));
374+
}
375+
}
376+
348377
/**
349378
* Gets the participants of a thread.
350379
*
@@ -821,6 +850,34 @@ public PagedFlux<ChatMessageReadReceipt> listReadReceipts() {
821850
}
822851
}
823852

853+
/**
854+
* Gets read receipts for a thread.
855+
*
856+
* @param listReadReceiptOptions The additional options for this operation.
857+
* @return read receipts for a thread.
858+
*/
859+
@ServiceMethod(returns = ReturnType.COLLECTION)
860+
public PagedFlux<ChatMessageReadReceipt> listReadReceipts(ListReadReceiptOptions listReadReceiptOptions) {
861+
final ListReadReceiptOptions serviceListReadReceiptOptions =
862+
listReadReceiptOptions == null ? new ListReadReceiptOptions() : listReadReceiptOptions;
863+
864+
try {
865+
return pagedFluxConvert(new PagedFlux<>(
866+
() -> withContext(context -> this.chatThreadClient.listChatReadReceiptsSinglePageAsync(
867+
chatThreadId,
868+
serviceListReadReceiptOptions.getMaxPageSize(),
869+
serviceListReadReceiptOptions.getSkip(),
870+
context)
871+
.onErrorMap(CommunicationErrorResponseException.class, e -> translateException(e))),
872+
nextLink -> withContext(context -> this.chatThreadClient.listChatReadReceiptsNextSinglePageAsync(
873+
nextLink, context)
874+
.onErrorMap(CommunicationErrorResponseException.class, e -> translateException(e)))),
875+
f -> ChatMessageReadReceiptConverter.convert(f));
876+
} catch (RuntimeException ex) {
877+
return new PagedFlux<>(() -> monoError(logger, ex));
878+
}
879+
}
880+
824881
/**
825882
* Gets read receipts for a thread.
826883
*

sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatThreadAsyncClientTest.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,43 @@ public void canAddListAndRemoveMembersAsync(HttpClient httpClient) throws Interr
188188
}
189189
}
190190

191+
@ParameterizedTest
192+
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
193+
public void canAddListAndRemoveMembersWithOptionsAsync(HttpClient httpClient) throws InterruptedException {
194+
// Arrange
195+
setupTest(httpClient, "canAddListAndRemoveMembersWithOptionsAsync");
196+
firstAddedParticipant = communicationClient.createUser();
197+
secondAddedParticipant = communicationClient.createUser();
198+
199+
Iterable<ChatParticipant> participants = ChatOptionsProvider.addParticipantsOptions(
200+
firstAddedParticipant.getId(), secondAddedParticipant.getId());
201+
202+
// Act & Assert
203+
StepVerifier.create(chatThreadClient.addParticipants(participants))
204+
.assertNext(noResp -> {
205+
PagedIterable<ChatParticipant> participantsResponse =
206+
new PagedIterable<>(chatThreadClient.listParticipants(new ListParticipantsOptions().setMaxPageSize(2)));
207+
208+
// process the iterableByPage
209+
List<ChatParticipant> returnedParticipants = new ArrayList<ChatParticipant>();
210+
participantsResponse.iterableByPage().forEach(resp -> {
211+
assertEquals(200, resp.getStatusCode());
212+
resp.getItems().forEach(item -> returnedParticipants.add(item));
213+
});
214+
215+
for (ChatParticipant participant : participants) {
216+
assertTrue(checkParticipantsListContainsParticipantId(returnedParticipants,
217+
((CommunicationUserIdentifier) participant.getCommunicationIdentifier()).getId()));
218+
}
219+
assertTrue(returnedParticipants.size() == 4);
220+
});
221+
222+
for (ChatParticipant participant : participants) {
223+
StepVerifier.create(chatThreadClient.removeParticipant(participant.getCommunicationIdentifier()))
224+
.verifyComplete();
225+
}
226+
}
227+
191228
@ParameterizedTest
192229
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
193230
public void canAddListWithContextAndRemoveMembersAsync(HttpClient httpClient) throws InterruptedException {
@@ -747,6 +784,40 @@ public void canSendThenListReadReceipts(HttpClient httpClient) throws Interrupte
747784
});
748785
}
749786

787+
@ParameterizedTest
788+
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
789+
@DisabledIfEnvironmentVariable(
790+
named = "SKIP_LIVE_TEST",
791+
matches = "(?i)(true)")
792+
public void canSendThenListReadReceiptsWithOptions(HttpClient httpClient) throws InterruptedException {
793+
// Arrange
794+
setupTest(httpClient, "canSendThenListReadReceiptsWithOptions");
795+
SendChatMessageOptions messageRequest = ChatOptionsProvider.sendMessageOptions();
796+
AtomicReference<String> messageResponseRef = new AtomicReference<>();
797+
798+
// Action & Assert
799+
StepVerifier.create(
800+
chatThreadClient.sendMessage(messageRequest)
801+
.flatMap(response -> {
802+
messageResponseRef.set(response.getId());
803+
return chatThreadClient.sendReadReceipt(response.getId());
804+
})
805+
)
806+
.assertNext(noResp -> {
807+
PagedIterable<ChatMessageReadReceipt> readReceiptsResponse = new PagedIterable<ChatMessageReadReceipt>(
808+
chatThreadClient.listReadReceipts(new ListReadReceiptOptions().setMaxPageSize(1)));
809+
810+
// process the iterableByPage
811+
List<ChatMessageReadReceipt> returnedReadReceipts = new ArrayList<>();
812+
readReceiptsResponse.iterableByPage().forEach(resp -> {
813+
assertEquals(200, resp.getStatusCode());
814+
resp.getItems().forEach(item -> returnedReadReceipts.add(item));
815+
});
816+
assertTrue(returnedReadReceipts.size() > 0);
817+
checkReadReceiptListContainsMessageId(returnedReadReceipts, messageResponseRef.get());
818+
});
819+
}
820+
750821
@ParameterizedTest
751822
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
752823
@DisabledIfEnvironmentVariable(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
{
2+
"networkCallRecords" : [ {
3+
"Method" : "POST",
4+
"Uri" : "https://REDACTED.communication.azure.com/identities?api-version=2021-03-07",
5+
"Headers" : {
6+
"User-Agent" : "azsdk-java-azure-communication-identity/1.1.0 (1.8.0_262; Windows 10; 10.0)",
7+
"Content-Type" : "application/json"
8+
},
9+
"Response" : {
10+
"Transfer-Encoding" : "chunked",
11+
"X-Cache" : "CONFIG_NOCACHE",
12+
"api-supported-versions" : "2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07, 2021-03-31-preview1",
13+
"retry-after" : "0",
14+
"StatusCode" : "201",
15+
"Date" : "Thu, 27 May 2021 23:51:46 GMT",
16+
"Strict-Transport-Security" : "max-age=2592000",
17+
"X-Processing-Time" : "65ms",
18+
"MS-CV" : "hqKed1k7x0S/mm6LYGzcSw.0",
19+
"X-Azure-Ref" : "0kzCwYAAAAAChuA8zcmkMQYT4vvdf/WISV1NURURHRTA4MDYAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
20+
"Body" : "{\"identity\":{\"id\":\"8:acs:fa5c4fc3-a269-43e2-9eb6-0ca17b388993_0000000a-501f-6485-ceb1-a43a0d0027ee\"}}",
21+
"x-ms-client-request-id" : "1fb6a2f3-9d13-44dd-9825-9aa4b6f8b89f",
22+
"Content-Type" : "application/json; charset=utf-8",
23+
"Request-Context" : "appId="
24+
},
25+
"Exception" : null
26+
}, {
27+
"Method" : "POST",
28+
"Uri" : "https://REDACTED.communication.azure.com/identities?api-version=2021-03-07",
29+
"Headers" : {
30+
"User-Agent" : "azsdk-java-azure-communication-identity/1.1.0 (1.8.0_262; Windows 10; 10.0)",
31+
"Content-Type" : "application/json"
32+
},
33+
"Response" : {
34+
"Transfer-Encoding" : "chunked",
35+
"X-Cache" : "CONFIG_NOCACHE",
36+
"api-supported-versions" : "2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07, 2021-03-31-preview1",
37+
"retry-after" : "0",
38+
"StatusCode" : "201",
39+
"Date" : "Thu, 27 May 2021 23:51:47 GMT",
40+
"Strict-Transport-Security" : "max-age=2592000",
41+
"X-Processing-Time" : "111ms",
42+
"MS-CV" : "Je2DwMX8yk6PS/W8Qa0JtQ.0",
43+
"X-Azure-Ref" : "0kzCwYAAAAABI9YzwMZsyQ7RZMB7krrLBV1NURURHRTA4MDgAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
44+
"Body" : "{\"identity\":{\"id\":\"8:acs:fa5c4fc3-a269-43e2-9eb6-0ca17b388993_0000000a-501f-6519-740a-113a0d0032ad\"}}",
45+
"x-ms-client-request-id" : "fa3f8778-a7de-4f26-8c66-8437cd626f60",
46+
"Content-Type" : "application/json; charset=utf-8",
47+
"Request-Context" : "appId="
48+
},
49+
"Exception" : null
50+
}, {
51+
"Method" : "POST",
52+
"Uri" : "https://REDACTED.communication.azure.com/identities/8:acs:fa5c4fc3-a269-43e2-9eb6-0ca17b388993_0000000a-501f-6485-ceb1-a43a0d0027ee/:issueAccessToken?api-version=2021-03-07",
53+
"Headers" : {
54+
"User-Agent" : "azsdk-java-azure-communication-identity/1.1.0 (1.8.0_262; Windows 10; 10.0)",
55+
"Content-Type" : "application/json"
56+
},
57+
"Response" : {
58+
"Transfer-Encoding" : "chunked",
59+
"X-Cache" : "CONFIG_NOCACHE",
60+
"api-supported-versions" : "2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07, 2021-03-31-preview1",
61+
"retry-after" : "0",
62+
"StatusCode" : "200",
63+
"Date" : "Thu, 27 May 2021 23:51:47 GMT",
64+
"Strict-Transport-Security" : "max-age=2592000",
65+
"X-Processing-Time" : "125ms",
66+
"MS-CV" : "YjGZ7mhh8E6Rucg6dPGMAA.0",
67+
"X-Azure-Ref" : "0kzCwYAAAAABYIwc+TdlCSLiyjspz8M40V1NURURHRTA4MDYAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
68+
"Body" : "{\"token\":\"REDACTED\",\"expiresOn\":\"2021-05-28T23:51:46.9935327+00:00\"}",
69+
"x-ms-client-request-id" : "c8500a20-706c-4282-ae3f-43b4cf963cf8",
70+
"Content-Type" : "application/json; charset=utf-8",
71+
"Request-Context" : "appId="
72+
},
73+
"Exception" : null
74+
}, {
75+
"Method" : "POST",
76+
"Uri" : "https://REDACTED.communication.azure.com/chat/threads?api-version=2021-03-07",
77+
"Headers" : {
78+
"User-Agent" : "azsdk-java-azure-communication-chat/1.0.1 (1.8.0_262; Windows 10; 10.0)",
79+
"Content-Type" : "application/json"
80+
},
81+
"Response" : {
82+
"Transfer-Encoding" : "chunked",
83+
"X-Cache" : "CONFIG_NOCACHE",
84+
"api-supported-versions" : "2020-09-21-preview2, 2020-11-01-preview3, 2021-01-27-preview4, 2021-03-01-preview5, 2021-03-07, 2021-04-05-preview6",
85+
"retry-after" : "0",
86+
"StatusCode" : "201",
87+
"Date" : "Thu, 27 May 2021 23:51:48 GMT",
88+
"Strict-Transport-Security" : "max-age=2592000",
89+
"X-Processing-Time" : "831ms",
90+
"MS-CV" : "iLFmwh1kIEihViH/5X/rxA.0",
91+
"X-Azure-Ref" : "0lDCwYAAAAAAaoMb88uUqRL44OB6f0ZNCV1NURURHRTA4MDgAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
92+
"Body" : "{\"chatThread\":{\"id\":\"19:eXCI9r5t4PcEHdHM4pZi4mjbmVpQsF5gATSJIxz_mL41@thread.v2\",\"topic\":\"Test\",\"createdOn\":\"2021-05-27T23:51:48Z\",\"createdByCommunicationIdentifier\":{\"rawId\":\"8:acs:fa5c4fc3-a269-43e2-9eb6-0ca17b388993_0000000a-501f-6485-ceb1-a43a0d0027ee\",\"communicationUser\":{\"id\":\"8:acs:fa5c4fc3-a269-43e2-9eb6-0ca17b388993_0000000a-501f-6485-ceb1-a43a0d0027ee\"}}}}",
93+
"Content-Type" : "application/json; charset=utf-8",
94+
"Location" : "https://chat-prod-e2e.communication.azure.com/chat/threads/19%3AeXCI9r5t4PcEHdHM4pZi4mjbmVpQsF5gATSJIxz_mL41@thread.v2"
95+
},
96+
"Exception" : null
97+
}, {
98+
"Method" : "POST",
99+
"Uri" : "https://REDACTED.communication.azure.com/identities?api-version=2021-03-07",
100+
"Headers" : {
101+
"User-Agent" : "azsdk-java-azure-communication-identity/1.1.0 (1.8.0_262; Windows 10; 10.0)",
102+
"Content-Type" : "application/json"
103+
},
104+
"Response" : {
105+
"Transfer-Encoding" : "chunked",
106+
"X-Cache" : "CONFIG_NOCACHE",
107+
"api-supported-versions" : "2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07, 2021-03-31-preview1",
108+
"retry-after" : "0",
109+
"StatusCode" : "201",
110+
"Date" : "Thu, 27 May 2021 23:51:48 GMT",
111+
"Strict-Transport-Security" : "max-age=2592000",
112+
"X-Processing-Time" : "62ms",
113+
"MS-CV" : "RXFlmlhlMUGIlISTXhYtpQ.0",
114+
"X-Azure-Ref" : "0lDCwYAAAAAAd6CZA9n1KR6EvuE7we8DcV1NURURHRTA4MDYAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
115+
"Body" : "{\"identity\":{\"id\":\"8:acs:fa5c4fc3-a269-43e2-9eb6-0ca17b388993_0000000a-501f-69c0-ceb1-a43a0d0027ef\"}}",
116+
"x-ms-client-request-id" : "ec9d25d1-bc5e-4723-ab47-5a3aca20234b",
117+
"Content-Type" : "application/json; charset=utf-8",
118+
"Request-Context" : "appId="
119+
},
120+
"Exception" : null
121+
}, {
122+
"Method" : "POST",
123+
"Uri" : "https://REDACTED.communication.azure.com/identities?api-version=2021-03-07",
124+
"Headers" : {
125+
"User-Agent" : "azsdk-java-azure-communication-identity/1.1.0 (1.8.0_262; Windows 10; 10.0)",
126+
"Content-Type" : "application/json"
127+
},
128+
"Response" : {
129+
"Transfer-Encoding" : "chunked",
130+
"X-Cache" : "CONFIG_NOCACHE",
131+
"api-supported-versions" : "2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07, 2021-03-31-preview1",
132+
"retry-after" : "0",
133+
"StatusCode" : "201",
134+
"Date" : "Thu, 27 May 2021 23:51:48 GMT",
135+
"Strict-Transport-Security" : "max-age=2592000",
136+
"X-Processing-Time" : "86ms",
137+
"MS-CV" : "KVZRWdzijkCUR9JK1DndPg.0",
138+
"X-Azure-Ref" : "0lTCwYAAAAACiK5KHtP2BSoA+i+C3ZzNxV1NURURHRTA4MDgAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
139+
"Body" : "{\"identity\":{\"id\":\"8:acs:fa5c4fc3-a269-43e2-9eb6-0ca17b388993_0000000a-501f-6a40-740a-113a0d0032af\"}}",
140+
"x-ms-client-request-id" : "f00f8a1f-f26c-4a6e-ad26-8fe31ad313e5",
141+
"Content-Type" : "application/json; charset=utf-8",
142+
"Request-Context" : "appId="
143+
},
144+
"Exception" : null
145+
}, {
146+
"Method" : "POST",
147+
"Uri" : "https://REDACTED.communication.azure.com/chat/threads/19:eXCI9r5t4PcEHdHM4pZi4mjbmVpQsF5gATSJIxz_mL41@thread.v2/participants/:remove?api-version=2021-03-07",
148+
"Headers" : {
149+
"User-Agent" : "azsdk-java-azure-communication-chat/1.0.1 (1.8.0_262; Windows 10; 10.0)",
150+
"Content-Type" : "application/json"
151+
},
152+
"Response" : {
153+
"X-Cache" : "CONFIG_NOCACHE",
154+
"Strict-Transport-Security" : "max-age=2592000",
155+
"api-supported-versions" : "2020-11-01-preview3, 2021-01-27-preview4, 2021-03-01-preview5, 2021-03-07, 2021-04-05-preview6",
156+
"X-Processing-Time" : "176ms",
157+
"MS-CV" : "h6KGMwolGk6sV5PEJpf/jg.0",
158+
"retry-after" : "0",
159+
"X-Azure-Ref" : "0lTCwYAAAAAA3yWMV3OwYT6KImV3TNXrZV1NURURHRTA4MDYAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
160+
"StatusCode" : "204",
161+
"Date" : "Thu, 27 May 2021 23:51:48 GMT"
162+
},
163+
"Exception" : null
164+
}, {
165+
"Method" : "POST",
166+
"Uri" : "https://REDACTED.communication.azure.com/chat/threads/19:eXCI9r5t4PcEHdHM4pZi4mjbmVpQsF5gATSJIxz_mL41@thread.v2/participants/:remove?api-version=2021-03-07",
167+
"Headers" : {
168+
"User-Agent" : "azsdk-java-azure-communication-chat/1.0.1 (1.8.0_262; Windows 10; 10.0)",
169+
"Content-Type" : "application/json"
170+
},
171+
"Response" : {
172+
"X-Cache" : "CONFIG_NOCACHE",
173+
"Strict-Transport-Security" : "max-age=2592000",
174+
"api-supported-versions" : "2020-11-01-preview3, 2021-01-27-preview4, 2021-03-01-preview5, 2021-03-07, 2021-04-05-preview6",
175+
"X-Processing-Time" : "403ms",
176+
"MS-CV" : "spA6zr1ZB0OHd9VnV0/K2g.0",
177+
"retry-after" : "0",
178+
"X-Azure-Ref" : "0lTCwYAAAAACNNOLqovnwRoHfm01ydwNXV1NURURHRTA4MDgAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
179+
"StatusCode" : "204",
180+
"Date" : "Thu, 27 May 2021 23:51:49 GMT"
181+
},
182+
"Exception" : null
183+
} ],
184+
"variables" : [ ]
185+
}

0 commit comments

Comments
 (0)