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()));
}
}
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;
}
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()));
}
}
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;
}
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;
}
Aggregations