Search in sources :

Example 1 with ChatParticipant

use of com.azure.android.communication.chat.models.ChatParticipant 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 ChatParticipant

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

the class AddChatParticipantsOptionsConverter method convert.

/**
 * Maps from a {@link ChatParticipant} Iterable to
 * {@link com.azure.android.communication.chat.implementation.models.AddChatParticipantsOptions}.
 */
public static com.azure.android.communication.chat.implementation.models.AddChatParticipantsOptions convert(Iterable<ChatParticipant> participants, ClientLogger logger) {
    if (participants == null) {
        return null;
    }
    List<com.azure.android.communication.chat.implementation.models.ChatParticipant> innerParticipants = new ArrayList<>();
    for (ChatParticipant participant : participants) {
        innerParticipants.add(ChatParticipantConverter.convert(participant, logger));
    }
    com.azure.android.communication.chat.implementation.models.AddChatParticipantsOptions addChatThreadMembersOptions = new com.azure.android.communication.chat.implementation.models.AddChatParticipantsOptions().setParticipants(innerParticipants);
    return addChatThreadMembersOptions;
}
Also used : ArrayList(java.util.ArrayList) ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant)

Example 3 with ChatParticipant

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

the class ChatThreadAsyncClientTest method canAddSingleParticipant.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canAddSingleParticipant(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    this.chatThreadClient.addParticipant(new ChatParticipant().setCommunicationIdentifier(this.firstThreadParticipant)).get();
    PagedAsyncStream<ChatParticipant> participantPagedAsyncStream = this.chatThreadClient.listParticipants(new ListParticipantsOptions(), null);
    CountDownLatch latch = new CountDownLatch(1);
    List<ChatParticipant> returnedParticipants = new ArrayList<ChatParticipant>();
    participantPagedAsyncStream.forEach(new AsyncStreamHandler<ChatParticipant>() {

        @Override
        public void onNext(ChatParticipant participant) {
            returnedParticipants.add(participant);
        }

        @Override
        public void onError(Throwable throwable) {
            latch.countDown();
        }

        @Override
        public void onComplete() {
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "canAddSingleParticipant");
    assertTrue(returnedParticipants.size() > 0);
    for (ChatParticipant participant : returnedParticipants) {
        assertNotNull(participant);
        assertNotNull(participant.getDisplayName());
        assertNotNull(participant.getShareHistoryTime());
        assertNotNull(participant.getCommunicationIdentifier());
        assertTrue(participant.getCommunicationIdentifier() instanceof CommunicationUserIdentifier);
        assertNotNull(((CommunicationUserIdentifier) participant.getCommunicationIdentifier()).getId());
    }
    if (TEST_MODE != TestMode.PLAYBACK) {
        assertTrue(super.checkParticipantsListContainsParticipantId(returnedParticipants, this.firstThreadParticipant.getId()));
    }
}
Also used : ArrayList(java.util.ArrayList) ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant) ListParticipantsOptions(com.azure.android.communication.chat.models.ListParticipantsOptions) CountDownLatch(java.util.concurrent.CountDownLatch) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with ChatParticipant

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

the class ChatClientTestBase method generateParticipant.

public static ChatParticipant generateParticipant(String id, String displayName) {
    ChatParticipant chatParticipant = new ChatParticipant();
    chatParticipant.setCommunicationIdentifier(new CommunicationUserIdentifier(id));
    chatParticipant.setDisplayName(displayName);
    return chatParticipant;
}
Also used : ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier)

Example 5 with ChatParticipant

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

the class ChatClientTestBase method createThreadOptions.

protected static CreateChatThreadOptions createThreadOptions(String userId1, String userId2) {
    List<ChatParticipant> participants = new ArrayList<ChatParticipant>();
    participants.add(generateParticipant(userId1, "Tester 1"));
    participants.add(generateParticipant(userId2, "Tester 2"));
    CreateChatThreadOptions options = new CreateChatThreadOptions().setTopic("Test").setParticipants(participants);
    return options;
}
Also used : ArrayList(java.util.ArrayList) ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions)

Aggregations

ChatParticipant (com.azure.android.communication.chat.models.ChatParticipant)11 ArrayList (java.util.ArrayList)7 CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 ListParticipantsOptions (com.azure.android.communication.chat.models.ListParticipantsOptions)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ExecutionException (java.util.concurrent.ExecutionException)4 ChatErrorResponseException (com.azure.android.communication.chat.models.ChatErrorResponseException)2 CreateChatThreadOptions (com.azure.android.communication.chat.models.CreateChatThreadOptions)2 AddChatParticipantsResult (com.azure.android.communication.chat.models.AddChatParticipantsResult)1 ChatThreadProperties (com.azure.android.communication.chat.models.ChatThreadProperties)1 CreateChatThreadResult (com.azure.android.communication.chat.models.CreateChatThreadResult)1 StringJoiner (java.util.StringJoiner)1