use of com.azure.android.communication.chat.models.CreateChatThreadResult in project azure-sdk-for-android by Azure.
the class MainActivity method createChatThreadAsyncClient.
public void createChatThreadAsyncClient() {
if (chatAsyncClient == null) {
createChatAsyncClient();
}
// A list of participants to start the thread with.
List<ChatParticipant> participants = new ArrayList<>();
// The display name for the thread participant.
String displayName = "First participant";
participants.add(new ChatParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier(firstUserId)).setDisplayName(displayName));
// The topic for the thread.
final String topic = "General";
// Optional, set a repeat request ID.
final String repeatabilityRequestID = "";
// Options to pass to the create method.
CreateChatThreadOptions createChatThreadOptions = new CreateChatThreadOptions().setTopic(topic).setParticipants(participants).setIdempotencyToken(repeatabilityRequestID);
try {
CreateChatThreadResult createChatThreadResult = chatAsyncClient.createChatThread(createChatThreadOptions).get();
ChatThreadProperties chatThreadProperties = createChatThreadResult.getChatThreadProperties();
threadId = chatThreadProperties.getId();
logAndToast("Created thread with ID: " + threadId);
chatThreadAsyncClient = chatAsyncClient.getChatThreadClient(threadId);
Log.d(TAG, "Created ChatThreadAsyncClient");
} catch (InterruptedException | ExecutionException e) {
Log.e("ChatThreadAsyncClient creation failed", Objects.requireNonNull(e.getMessage()));
}
}
use of com.azure.android.communication.chat.models.CreateChatThreadResult in project azure-sdk-for-android by Azure.
the class ChatAsyncClientTest method canCreateThread.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canCreateThread(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
CompletableFuture<CreateChatThreadResult> completableFuture = this.client.createChatThread(threadRequest);
assertNotNull(completableFuture);
CreateChatThreadResult result = completableFuture.get();
assertNotNull(result);
assertNotNull(result.getChatThreadProperties());
assertNotNull(result.getChatThreadProperties().getId());
}
use of com.azure.android.communication.chat.models.CreateChatThreadResult in project azure-sdk-for-android by Azure.
the class ChatAsyncClientTest method canDeleteChatThread.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canDeleteChatThread(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
CompletableFuture<CreateChatThreadResult> completableFuture1 = this.client.createChatThread(threadRequest);
assertNotNull(completableFuture1);
CreateChatThreadResult result1 = completableFuture1.get();
assertNotNull(result1);
assertNotNull(result1.getChatThreadProperties());
assertNotNull(result1.getChatThreadProperties().getId());
CompletableFuture<Void> completableFuture2 = this.client.deleteChatThread(result1.getChatThreadProperties().getId());
assertNotNull(completableFuture2);
Void result2 = completableFuture2.get();
assertNull(result2);
}
use of com.azure.android.communication.chat.models.CreateChatThreadResult in project azure-sdk-for-android by Azure.
the class ChatAsyncClientTest method canListChatThreadsWithMaxPage.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListChatThreadsWithMaxPage(HttpClient httpClient) throws InterruptedException, ExecutionException {
setupTest(httpClient);
final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
CompletableFuture<CreateChatThreadResult> completableFuture1 = this.client.createChatThread(threadRequest);
assertNotNull(completableFuture1);
CreateChatThreadResult result1 = completableFuture1.get();
assertNotNull(result1);
assertNotNull(result1.getChatThreadProperties());
assertNotNull(result1.getChatThreadProperties().getId());
CompletableFuture<CreateChatThreadResult> completableFuture2 = this.client.createChatThread(threadRequest);
assertNotNull(completableFuture2);
CreateChatThreadResult result2 = completableFuture1.get();
assertNotNull(result2);
assertNotNull(result2.getChatThreadProperties());
assertNotNull(result2.getChatThreadProperties().getId());
PagedAsyncStream<ChatThreadItem> chatAsyncStream = this.client.listChatThreads(new ListChatThreadsOptions().setMaxPageSize(2), null);
CountDownLatch latch = new CountDownLatch(1);
AtomicBoolean gotNullResponse = new AtomicBoolean();
AtomicBoolean gotNullList = new AtomicBoolean();
List<ChatThreadItem> returnedThreads = new ArrayList<ChatThreadItem>();
chatAsyncStream.byPage().forEach(new AsyncStreamHandler<PagedResponse<ChatThreadItem>>() {
@Override
public void onNext(PagedResponse<ChatThreadItem> response) {
if (!gotNullResponse.get()) {
gotNullResponse.set(response == null);
}
if (response != null) {
List<ChatThreadItem> threadsInPage = response.getValue();
if (!gotNullList.get()) {
gotNullResponse.set(threadsInPage == null);
}
if (threadsInPage != null) {
for (ChatThreadItem thread : threadsInPage) {
returnedThreads.add(thread);
}
}
}
}
@Override
public void onError(Throwable throwable) {
latch.countDown();
}
@Override
public void onComplete() {
latch.countDown();
}
});
awaitOnLatch(latch, "canListChatThreads");
Assertions.assertFalse(gotNullResponse.get());
Assertions.assertFalse(gotNullList.get());
// REVISIT: Unreliable assert
// assertTrue(returnedThreads.size() > 0);
}
use of com.azure.android.communication.chat.models.CreateChatThreadResult in project azure-sdk-for-android by Azure.
the class ChatAsyncClientTest method canDeleteChatThreadWithResponse.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canDeleteChatThreadWithResponse(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
CompletableFuture<Response<CreateChatThreadResult>> completableFuture1 = this.client.createChatThreadWithResponse(threadRequest, null);
assertNotNull(completableFuture1);
Response<CreateChatThreadResult> response1 = completableFuture1.get();
assertNotNull(response1);
CreateChatThreadResult result1 = response1.getValue();
assertNotNull(result1);
assertNotNull(result1.getChatThreadProperties());
assertNotNull(result1.getChatThreadProperties().getId());
CompletableFuture<Response<Void>> completableFuture2 = this.client.deleteChatThreadWithResponse(result1.getChatThreadProperties().getId(), null);
assertNotNull(completableFuture2);
Response<Void> response2 = completableFuture2.get();
assertNotNull(response2);
Void result2 = response2.getValue();
assertNull(result2);
}
Aggregations