Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACS Chat - Preview 3 - Add single thread participant convenience method #17800

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.paging.PageRetriever;

import java.util.Collections;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.Objects;
Expand Down Expand Up @@ -151,6 +152,47 @@ public Mono<Response<Void>> addParticipantsWithResponse(AddChatParticipantsOptio
}
}

/**
* Adds a participant to a thread. If the participant already exists, no change occurs.
*
* @param participant The new participant.
* @return the completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> addParticipant(ChatParticipant participant) {
try {
return withContext(context -> addParticipants(
new AddChatParticipantsOptions()
.setParticipants(Collections.singletonList(participant)),
context)
.flatMap((Response<Void> res) -> {
return Mono.empty();
}));
} catch (RuntimeException ex) {

return monoError(logger, ex);
}
}

/**
* Adds a participant to a thread. If the participant already exists, no change occurs.
*
* @param participant The new participant.
* @return the completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> addParticipantWithResponse(ChatParticipant participant) {
try {
return withContext(context -> addParticipants(
new AddChatParticipantsOptions()
.setParticipants(Collections.singletonList(participant)),
context));
} catch (RuntimeException ex) {

return monoError(logger, ex);
}
}

/**
* Adds participants to a thread. If participants already exist, no change occurs.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;

import java.util.Collections;

/**
* Sync Client that supports chat thread operations.
*/
Expand Down Expand Up @@ -98,6 +100,32 @@ public Response<Void> addParticipantsWithResponse(AddChatParticipantsOptions opt
return this.client.addParticipants(options, context).block();
}

/**
* Adds a participant to a thread. If the participant already exists, no change occurs.
*
* @param participant The new participant.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void addParticipant(ChatParticipant participant) {

this.client.addParticipants(new AddChatParticipantsOptions()
.setParticipants(Collections.singletonList(participant))).block();
}

/**
* Adds a participant to a thread. If the participant already exists, no change occurs.
*
* @param participant The new participant.
* @param context The context to associate with this operation.
* @return the completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> addParticipantWithResponse(ChatParticipant participant, Context context) {

return this.client.addParticipants(new AddChatParticipantsOptions()
.setParticipants(Collections.singletonList(participant)), context).block();
}

/**
* Remove a participant from a thread.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,36 @@ public void canAddListAndRemoveParticipantsWithResponseAsync(HttpClient httpClie
}
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void canAddSingleParticipantAsync(HttpClient httpClient) throws InterruptedException {
// Arrange
setupTest(httpClient);
CommunicationUser participant = communicationClient.createUser();

// Action & Assert
StepVerifier.create(chatThreadClient.addParticipant(new ChatParticipant().setUser(participant)))
.assertNext(noResp -> {
PagedIterable<ChatParticipant> participantsResponse = new PagedIterable<>(chatThreadClient.listParticipants());
assertTrue(participantsResponse.stream().anyMatch(p -> p.getUser().getId().equals(participant.getId())));
});
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void canAddSingleParticipantWithResponseAsync(HttpClient httpClient) throws InterruptedException {
// Arrange
setupTest(httpClient);
CommunicationUser participant = communicationClient.createUser();

// Action & Assert
StepVerifier.create(chatThreadClient.addParticipantWithResponse(new ChatParticipant().setUser(participant)))
.assertNext(noResp -> {
PagedIterable<ChatParticipant> participantsResponse = new PagedIterable<>(chatThreadClient.listParticipants());
assertTrue(participantsResponse.stream().anyMatch(p -> p.getUser().getId().equals(participant.getId())));
});
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void canSendThenGetMessage(HttpClient httpClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,34 @@ public void canAddListAndRemoveParticipantsWithResponse(HttpClient httpClient) t
}
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void canAddSingleParticipant(HttpClient httpClient) throws InterruptedException {
// Arrange
setupTest(httpClient);
CommunicationUser participant = communicationClient.createUser();

// Action & Assert
chatThreadClient.addParticipant(new ChatParticipant().setUser(participant));

PagedIterable<ChatParticipant> participantsResponse = chatThreadClient.listParticipants();
assertTrue(participantsResponse.stream().anyMatch(p -> p.getUser().getId().equals(participant.getId())));
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void canAddSingleParticipantWithResponse(HttpClient httpClient) throws InterruptedException {
// Arrange
setupTest(httpClient);
CommunicationUser participant = communicationClient.createUser();

// Action & Assert
chatThreadClient.addParticipantWithResponse(new ChatParticipant().setUser(participant), Context.NONE);

PagedIterable<ChatParticipant> participantsResponse = chatThreadClient.listParticipants();
assertTrue(participantsResponse.stream().anyMatch(p -> p.getUser().getId().equals(participant.getId())));
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void canSendThenGetMessage(HttpClient httpClient) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/identities?api-version=2020-07-20-preview2",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-administration/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"api-supported-versions" : "2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2",
"X-Processing-Time" : "149ms",
"MS-CV" : "s9Hn8MeU7kSSfLV6Aek+pg.0",
"retry-after" : "0",
"X-Azure-Ref" : "0BS2vXwAAAABFLfcCCc1UQqfE9KmBIESYWVZSMzBFREdFMDQwNwA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "200",
"Body" : "{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-8085-557d-5a3a0d000211\"}",
"Date" : "Sat, 14 Nov 2020 01:04:05 GMT",
"x-ms-client-request-id" : "cf4c1049-ba07-4357-bbcb-6bb47bb379c1",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/identities?api-version=2020-07-20-preview2",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-administration/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"api-supported-versions" : "2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2",
"X-Processing-Time" : "144ms",
"MS-CV" : "4TJs6WQD9UCKT3J5PtrNzA.0",
"retry-after" : "0",
"X-Azure-Ref" : "0BS2vXwAAAAAos3wOztJfRKSrueQvVMe6WVZSMzBFREdFMDQwNgA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "200",
"Body" : "{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-8138-557d-5a3a0d000212\"}",
"Date" : "Sat, 14 Nov 2020 01:04:05 GMT",
"x-ms-client-request-id" : "8aa27a48-4a4a-40bb-b2f3-03192f351bf6",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/identities/8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-8085-557d-5a3a0d000211/token?api-version=2020-07-20-preview2",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-administration/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)",
"Content-Type" : "application/json"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"api-supported-versions" : "2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2",
"X-Processing-Time" : "311ms",
"MS-CV" : "BtLQ/s6b7USIw2qIO03c8Q.0",
"retry-after" : "0",
"X-Azure-Ref" : "0BS2vXwAAAADOMC2tgC/cQYyAEIWmuODgWVZSMzBFREdFMDQwNwA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "200",
"Body" : "{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-8085-557d-5a3a0d000211\",\"token\":\"REDACTED\",\"expiresOn\":\"2020-11-15T01:04:04.7844151+00:00\"}",
"Date" : "Sat, 14 Nov 2020 01:04:05 GMT",
"x-ms-client-request-id" : "2ab7af75-d7cb-4a4b-aa86-493d6ab05532",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/chat/threads?api-version=2020-11-01-preview3",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-chat/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)",
"Content-Type" : "application/json"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"Strict-Transport-Security" : "max-age=2592000",
"api-supported-versions" : "2020-09-21-preview2, 2020-11-01-preview3",
"X-Processing-Time" : "895ms",
"MS-CV" : "PJCDOQHDh0e0SSaqL2JRRw.0",
"retry-after" : "0",
"X-Azure-Ref" : "0BS2vXwAAAABVEZdwHoChQrTsA/b7XyYFWVZSMzBFREdFMDQwNgA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "201",
"Body" : "{\"id\":\"19:752f0e5ec85b4080a38c049453658dac@thread.v2\",\"topic\":\"Test\",\"createdOn\":\"2020-11-14T01:04:06Z\",\"createdBy\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-8085-557d-5a3a0d000211\",\"participants\":[{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-8085-557d-5a3a0d000211\",\"displayName\":\"Tester 1\",\"shareHistoryTime\":\"1970-01-01T00:00:00Z\"},{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-8138-557d-5a3a0d000212\",\"displayName\":\"Tester 2\",\"shareHistoryTime\":\"1970-01-01T00:00:00Z\"}]}",
"Date" : "Sat, 14 Nov 2020 01:04:06 GMT",
"Content-Type" : "application/json; charset=utf-8",
"Location" : "https://168.61.22.92/chat/threads/19%3A752f0e5ec85b4080a38c049453658dac@thread.v2"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/identities?api-version=2020-07-20-preview2",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-administration/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"api-supported-versions" : "2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2",
"X-Processing-Time" : "154ms",
"MS-CV" : "3/fFpqlwAEmEz4zTKjyOmQ.0",
"retry-after" : "0",
"X-Azure-Ref" : "0Bi2vXwAAAABFYGhY9ighS6uxj2brkDZbWVZSMzBFREdFMDQwNwA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "200",
"Body" : "{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-86f2-557d-5a3a0d000213\"}",
"Date" : "Sat, 14 Nov 2020 01:04:06 GMT",
"x-ms-client-request-id" : "b9a65185-0ef6-4eee-94e7-f2380abcb68a",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
} ],
"variables" : [ ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/identities?api-version=2020-07-20-preview2",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-administration/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"api-supported-versions" : "2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2",
"X-Processing-Time" : "145ms",
"MS-CV" : "hyfng53c4k6UpzDR76Zb9g.0",
"retry-after" : "0",
"X-Azure-Ref" : "07iyvXwAAAACL7tn1RQyBQKyR8t/kroioWVZSMzBFREdFMDQwNgA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "200",
"Body" : "{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-26c8-557d-5a3a0d0001f8\"}",
"Date" : "Sat, 14 Nov 2020 01:03:41 GMT",
"x-ms-client-request-id" : "4d81daa5-686f-462e-83f3-06af272eef17",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/identities?api-version=2020-07-20-preview2",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-administration/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"api-supported-versions" : "2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2",
"X-Processing-Time" : "147ms",
"MS-CV" : "5gIW7+TDA02QVxAlZtC/Ng.0",
"retry-after" : "0",
"X-Azure-Ref" : "07iyvXwAAAADfReQf5GnWRpTsHUKeS9sFWVZSMzBFREdFMDQwNwA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "200",
"Body" : "{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-277a-557d-5a3a0d0001f9\"}",
"Date" : "Sat, 14 Nov 2020 01:03:41 GMT",
"x-ms-client-request-id" : "10e08f92-1f88-42cf-b413-658bc07a0c1e",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/identities/8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-26c8-557d-5a3a0d0001f8/token?api-version=2020-07-20-preview2",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-administration/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)",
"Content-Type" : "application/json"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"api-supported-versions" : "2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2",
"X-Processing-Time" : "310ms",
"MS-CV" : "34jEQf33Dk2Ql3V3XhDf3g.0",
"retry-after" : "0",
"X-Azure-Ref" : "07iyvXwAAAAAl9e0IoZ4YQ7nXs0CHuLWFWVZSMzBFREdFMDQwNgA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "200",
"Body" : "{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-26c8-557d-5a3a0d0001f8\",\"token\":\"REDACTED\",\"expiresOn\":\"2020-11-15T01:03:41.8099308+00:00\"}",
"Date" : "Sat, 14 Nov 2020 01:03:42 GMT",
"x-ms-client-request-id" : "96b55cbe-166a-47b7-ae10-15235e7a1fd8",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/chat/threads?api-version=2020-11-01-preview3",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-chat/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)",
"Content-Type" : "application/json"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"Strict-Transport-Security" : "max-age=2592000",
"api-supported-versions" : "2020-09-21-preview2, 2020-11-01-preview3",
"X-Processing-Time" : "830ms",
"MS-CV" : "AYO7C/QjBkyMgbySStG77Q.0",
"retry-after" : "0",
"X-Azure-Ref" : "07iyvXwAAAAC4g0E5iNcaRoziCoQjylRGWVZSMzBFREdFMDQwNwA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "201",
"Body" : "{\"id\":\"19:b8e80d4cb5954c029ecf5c89b065df9e@thread.v2\",\"topic\":\"Test\",\"createdOn\":\"2020-11-14T01:03:43Z\",\"createdBy\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-26c8-557d-5a3a0d0001f8\",\"participants\":[{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-26c8-557d-5a3a0d0001f8\",\"displayName\":\"Tester 1\",\"shareHistoryTime\":\"1970-01-01T00:00:00Z\"},{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-277a-557d-5a3a0d0001f9\",\"displayName\":\"Tester 2\",\"shareHistoryTime\":\"1970-01-01T00:00:00Z\"}]}",
"Date" : "Sat, 14 Nov 2020 01:03:42 GMT",
"Content-Type" : "application/json; charset=utf-8",
"Location" : "https://168.61.22.92/chat/threads/19%3Ab8e80d4cb5954c029ecf5c89b065df9e@thread.v2"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.dev.communication.azure.net/identities?api-version=2020-07-20-preview2",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-administration/1.0.0-beta.3 (11.0.9; Windows 10; 10.0)"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"api-supported-versions" : "2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2",
"X-Processing-Time" : "146ms",
"MS-CV" : "wZATr2SRbU6YY9TwSnI2Ow.0",
"retry-after" : "0",
"X-Azure-Ref" : "07yyvXwAAAACyzbCrzVasRrPQ7Gvr1RaxWVZSMzBFREdFMDQwNgA3MDU0Mzk1ZS1jZTFkLTQ1NWUtYWU1ZC0yMzNjYTgzOTA1NTQ=",
"StatusCode" : "200",
"Body" : "{\"id\":\"8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-6429-2cec-557d-5a3a0d0001fa\"}",
"Date" : "Sat, 14 Nov 2020 01:03:43 GMT",
"x-ms-client-request-id" : "0e73d48f-fc6e-48c4-a702-2385e09f9eea",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
} ],
"variables" : [ ]
}
Loading