Search in sources :

Example 1 with ChatMessageReadReceipt

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

the class MainActivity method listReadReceipts.

public void listReadReceipts(View view) {
    if (chatThreadAsyncClient == null) {
        createChatThreadAsyncClient();
    }
    if (chatThreadAsyncClient != null) {
        // The maximum number of read receipts to be returned per page, optional.
        int maxPageSize = 10;
        // Skips participants up to a specified position in response.
        int skip = 0;
        // Options to pass to the list method.
        ListReadReceiptOptions listReadReceiptOptions = new ListReadReceiptOptions().setMaxPageSize(maxPageSize).setSkip(skip);
        try {
            PagedAsyncStream<ChatMessageReadReceipt> readReceipts = chatThreadAsyncClient.listReadReceipts(listReadReceiptOptions, RequestContext.NONE);
            readReceipts.forEach(readReceipt -> {
                Log.d(TAG, "Got receipt for participant " + ((CommunicationUserIdentifier) readReceipt.getSenderCommunicationIdentifier()).getId() + " for message with id: " + readReceipt.getChatMessageId());
            });
        } catch (Exception e) {
            logAndToast("Listing read receipts failed: " + e.getMessage());
        }
    } else {
        logAndToast("ChatThreadAsyncClient creation failed");
    }
}
Also used : ChatMessageReadReceipt(com.azure.android.communication.chat.models.ChatMessageReadReceipt) ListReadReceiptOptions(com.azure.android.communication.chat.models.ListReadReceiptOptions) ExecutionException(java.util.concurrent.ExecutionException) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier)

Example 2 with ChatMessageReadReceipt

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

the class ChatThreadAsyncClientTest method canListReadReceipts.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListReadReceipts(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupMockTest();
    PagedAsyncStream<ChatMessageReadReceipt> readReceiptPagedAsyncStream = this.chatThreadClient.listReadReceipts(new ListReadReceiptOptions(), null);
    CountDownLatch latch = new CountDownLatch(1);
    List<ChatMessageReadReceipt> readReceiptList = new ArrayList<ChatMessageReadReceipt>();
    readReceiptPagedAsyncStream.forEach(new AsyncStreamHandler<ChatMessageReadReceipt>() {

        @Override
        public void onNext(ChatMessageReadReceipt readReceipt) {
            readReceiptList.add(readReceipt);
        }

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

        @Override
        public void onComplete() {
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "canListReadReceipts");
    assertEquals(readReceiptList.size(), 2);
    assertNotNull(readReceiptList.get(0).getChatMessageId());
    assertNotNull(readReceiptList.get(0).getReadOn());
    assertNotNull(readReceiptList.get(0).getSenderCommunicationIdentifier());
}
Also used : ChatMessageReadReceipt(com.azure.android.communication.chat.models.ChatMessageReadReceipt) ListReadReceiptOptions(com.azure.android.communication.chat.models.ListReadReceiptOptions) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with ChatMessageReadReceipt

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

the class ChatThreadAsyncClientTest method canListReadReceiptsWithOptions.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListReadReceiptsWithOptions(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupMockTest();
    PagedAsyncStream<ChatMessageReadReceipt> readReceiptPagedAsyncStream = this.chatThreadClient.listReadReceipts(new ListReadReceiptOptions(), null);
    CountDownLatch latch = new CountDownLatch(1);
    List<ChatMessageReadReceipt> readReceiptList = new ArrayList<ChatMessageReadReceipt>();
    readReceiptPagedAsyncStream.forEach(new AsyncStreamHandler<ChatMessageReadReceipt>() {

        @Override
        public void onNext(ChatMessageReadReceipt readReceipt) {
            readReceiptList.add(readReceipt);
        }

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

        @Override
        public void onComplete() {
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "canListReadReceiptsWithOptions");
    assertEquals(readReceiptList.size(), 2);
    assertNotNull(readReceiptList.get(0).getChatMessageId());
    assertNotNull(readReceiptList.get(0).getReadOn());
    assertNotNull(readReceiptList.get(0).getSenderCommunicationIdentifier());
}
Also used : ChatMessageReadReceipt(com.azure.android.communication.chat.models.ChatMessageReadReceipt) ListReadReceiptOptions(com.azure.android.communication.chat.models.ListReadReceiptOptions) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ChatMessageReadReceipt (com.azure.android.communication.chat.models.ChatMessageReadReceipt)3 ListReadReceiptOptions (com.azure.android.communication.chat.models.ListReadReceiptOptions)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)1 ExecutionException (java.util.concurrent.ExecutionException)1