Search in sources :

Example 1 with ChatThreadProperties

use of com.azure.android.communication.chat.models.ChatThreadProperties 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()));
    }
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) ArrayList(java.util.ArrayList) ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant) ChatThreadProperties(com.azure.android.communication.chat.models.ChatThreadProperties) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) ExecutionException(java.util.concurrent.ExecutionException) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier)

Example 2 with ChatThreadProperties

use of com.azure.android.communication.chat.models.ChatThreadProperties in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method canUpdateThreadWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canUpdateThreadWithResponse(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    String newTopic = "Update Test";
    Response<Void> updateThreadResponse = this.chatThreadClient.updateTopicWithResponse(newTopic, null).get();
    assertEquals(204, updateThreadResponse.getStatusCode());
    ChatThreadProperties chatThreadProperties = this.client.getChatThreadClient(this.threadId).getProperties().get();
    assertEquals(chatThreadProperties.getTopic(), newTopic);
}
Also used : ChatThreadProperties(com.azure.android.communication.chat.models.ChatThreadProperties) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with ChatThreadProperties

use of com.azure.android.communication.chat.models.ChatThreadProperties in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method canGetExistingChatThread.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canGetExistingChatThread(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());
    String expectedThreadId = result1.getChatThreadProperties().getId();
    CompletableFuture<ChatThreadProperties> completableFuture2 = this.client.getChatThreadClient(expectedThreadId).getProperties();
    assertNotNull(completableFuture2);
    ChatThreadProperties result2 = completableFuture2.get();
    assertNotNull(result2);
    assertNotNull(result2.getId());
    assertEquals(expectedThreadId, result2.getId());
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) ChatThreadProperties(com.azure.android.communication.chat.models.ChatThreadProperties) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with ChatThreadProperties

use of com.azure.android.communication.chat.models.ChatThreadProperties in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method canGetExistingChatThreadWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canGetExistingChatThreadWithResponse(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());
    String expectedThreadId = result1.getChatThreadProperties().getId();
    CompletableFuture<Response<ChatThreadProperties>> completableFuture2 = this.client.getChatThreadClient(expectedThreadId).getPropertiesWithResponse(null);
    assertNotNull(completableFuture2);
    Response<ChatThreadProperties> response2 = completableFuture2.get();
    assertNotNull(response2);
    ChatThreadProperties result2 = response2.getValue();
    assertNotNull(result2);
    assertNotNull(result2.getId());
    assertEquals(expectedThreadId, result2.getId());
}
Also used : Response(com.azure.android.core.rest.Response) CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) ChatThreadProperties(com.azure.android.communication.chat.models.ChatThreadProperties) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with ChatThreadProperties

use of com.azure.android.communication.chat.models.ChatThreadProperties in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method canUpdateThread.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canUpdateThread(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    String newTopic = "Update Test";
    this.chatThreadClient.updateTopic(newTopic).get();
    ChatThreadProperties chatThreadProperties = this.client.getChatThreadClient(this.threadId).getProperties().get();
    assertEquals(chatThreadProperties.getTopic(), newTopic);
}
Also used : ChatThreadProperties(com.azure.android.communication.chat.models.ChatThreadProperties) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ChatThreadProperties (com.azure.android.communication.chat.models.ChatThreadProperties)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)5 CreateChatThreadOptions (com.azure.android.communication.chat.models.CreateChatThreadOptions)3 CreateChatThreadResult (com.azure.android.communication.chat.models.CreateChatThreadResult)3 ExecutionException (java.util.concurrent.ExecutionException)2 ChatErrorResponseException (com.azure.android.communication.chat.models.ChatErrorResponseException)1 ChatParticipant (com.azure.android.communication.chat.models.ChatParticipant)1 CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)1 Response (com.azure.android.core.rest.Response)1 ArrayList (java.util.ArrayList)1