/// <summary> /// ViewMembersInAThread() - view existing members in a chat thread /// </summary> /// <returns></returns> private static async Task ViewMembersInAThread() { Console.WriteLine("\n# Viewing members in a thread"); Console.Write("Enter thread id: "); var threadId = Console.ReadLine(); Uri endpoint = new Uri("https://ACS-INSTANCE.communication.azure.com/"); CommunicationUserCredential communicationUserCredential = new CommunicationUserCredential(token); ChatClient chatClient = new ChatClient(endpoint, communicationUserCredential); ChatThreadClient chatThreadClient = chatClient.GetChatThreadClient(threadId); AsyncPageable <ChatThreadMember> allMembers = chatThreadClient.GetMembersAsync(); await foreach (ChatThreadMember member in allMembers) { Console.WriteLine($"{member.DisplayName}"); } }
public async Task GetAddRemoveMembersAsync() { CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClient(TestEnvironment.ConnectionString); Response <CommunicationUserIdentifier> threadMember1 = await communicationIdentityClient.CreateUserAsync(); Response <CommunicationUserIdentifier> threadMember2 = await communicationIdentityClient.CreateUserAsync(); Response <CommunicationUserIdentifier> threadMember3 = await communicationIdentityClient.CreateUserAsync(); CommunicationUserToken communicationUserToken1 = await communicationIdentityClient.IssueTokenAsync(threadMember1.Value, new[] { CommunicationTokenScope.Chat }); CommunicationUserToken communicationUserToken2 = await communicationIdentityClient.IssueTokenAsync(threadMember2.Value, new[] { CommunicationTokenScope.Chat }); CommunicationUserToken communicationUserToken3 = await communicationIdentityClient.IssueTokenAsync(threadMember3.Value, new[] { CommunicationTokenScope.Chat }); string userToken = communicationUserToken1.Token; string endpoint = TestEnvironment.ChatApiUrl(); string theadCreatorMemberId = communicationUserToken1.User.Id; ChatClient chatClient = new ChatClient( new Uri(endpoint), new CommunicationTokenCredential(userToken)); var chatThreadMember = new ChatThreadMember(new CommunicationUserIdentifier(theadCreatorMemberId)) { DisplayName = "UserDisplayName", ShareHistoryTime = DateTime.MinValue }; ChatThreadClient chatThreadClient = await chatClient.CreateChatThreadAsync(topic : "Hello world!", members : new[] { chatThreadMember }); string threadId = chatThreadClient.Id; #region Snippet:Azure_Communication_Chat_Tests_Samples_GetMembers AsyncPageable <ChatThreadMember> allMembers = chatThreadClient.GetMembersAsync(); await foreach (ChatThreadMember member in allMembers) { Console.WriteLine($"{member.User.Id}:{member.DisplayName}:{member.ShareHistoryTime}"); } #endregion Snippet:Azure_Communication_Chat_Tests_GetMembers var memberId1 = theadCreatorMemberId; var memberId2 = communicationUserToken2.User.Id; var memberId3 = communicationUserToken3.User.Id; #region Snippet:Azure_Communication_Chat_Tests_Samples_AddMembers var members = new[] { new ChatThreadMember(new CommunicationUserIdentifier(memberId1)) { DisplayName = "display name member 1" }, new ChatThreadMember(new CommunicationUserIdentifier(memberId2)) { DisplayName = "display name member 2" }, new ChatThreadMember(new CommunicationUserIdentifier(memberId3)) { DisplayName = "display name member 3" } }; await chatThreadClient.AddMembersAsync(members); #endregion Snippet:Azure_Communication_Chat_Tests_Samples_AddMembers var memberId = memberId2; #region Snippet:Azure_Communication_Chat_Tests_Samples_RemoveMember await chatThreadClient.RemoveMemberAsync(new CommunicationUserIdentifier(memberId)); #endregion Snippet:Azure_Communication_Chat_Tests_Samples_RemoveMember await chatClient.DeleteChatThreadAsync(threadId); }
public async Task E2E_ThreadCreateUpdateGetDelete_MemberAddUpdateRemove_MessageGetSendUpdate_NotificationTyping_ReadReceiptGetSend_Async() { //arr CommunicationUser user1, user2, user3; string token1, token2, token3; CommunicationIdentityClient communicationIdentityClient = CreateInstrumentedCommunicationIdentityClient(); (user1, token1) = await CreateUserAndTokenAsync(communicationIdentityClient); (user2, token2) = await CreateUserAndTokenAsync(communicationIdentityClient); (user3, token3) = await CreateUserAndTokenAsync(communicationIdentityClient); var topic = "Thread Async from C# sdk"; var contentMessage = "This is message 1"; var updatedMessageContent = "This is message 1 updated"; var displayNameMessage = "DisplayName sender message 1"; var updatedTopic = "Updated topic - C# sdk"; var members = new List <ChatThreadMember> { new ChatThreadMember(user1), new ChatThreadMember(user2) }; ChatClient chatClient = CreateInstrumentedChatClient(token1); ChatClient chatClient2 = CreateInstrumentedChatClient(token2); //act ChatThreadClient chatThreadClient = await CreateInstrumentedChatThreadClientAsync(chatClient, topic, members); ChatThreadClient chatThreadClient2 = await CreateInstrumentedChatThreadClientAsync(chatClient, topic, members); await chatThreadClient.UpdateThreadAsync(updatedTopic); ChatThread chatThread = await chatClient.GetChatThreadAsync(chatThreadClient.Id); AsyncPageable <ChatThreadInfo> threads = chatClient.GetChatThreadsInfoAsync(); var threadsCount = threads.ToEnumerableAsync().Result.Count; SendChatMessageResult sendChatMessageResult = await chatThreadClient.SendMessageAsync(contentMessage, ChatMessagePriority.High, displayNameMessage); SendChatMessageResult sendChatMessageResult2 = await chatThreadClient.SendMessageAsync(contentMessage, ChatMessagePriority.High, displayNameMessage); ChatMessage message = await chatThreadClient.GetMessageAsync(sendChatMessageResult.Id); AsyncPageable <ChatMessage> messages = chatThreadClient.GetMessagesAsync(); var getMessagesCount = messages.ToEnumerableAsync().Result.Count; var messageId = sendChatMessageResult.Id; await chatThreadClient.UpdateMessageAsync(messageId, updatedMessageContent); Response <ChatMessage> actualUpdateMessage = await chatThreadClient.GetMessageAsync(messageId); await chatThreadClient.DeleteMessageAsync(messageId); AsyncPageable <ChatMessage> messagesAfterOneDeleted = chatThreadClient.GetMessagesAsync(); ChatMessage deletedChatMessage = messagesAfterOneDeleted.ToEnumerableAsync().Result.First(x => x.Id == messageId); AsyncPageable <ChatThreadMember> chatThreadMembers = chatThreadClient.GetMembersAsync(); var chatThreadMembersCount = chatThreadMembers.ToEnumerableAsync().Result.Count; var newMember = new ChatThreadMember(user3); await chatThreadClient.AddMembersAsync(new List <ChatThreadMember> { newMember }); AsyncPageable <ChatThreadMember> chatThreadMembersAfterOneAdded = chatThreadClient.GetMembersAsync(); var chatThreadMembersAfterOneAddedCount = chatThreadMembersAfterOneAdded.ToEnumerableAsync().Result.Count(); CommunicationUser userToBeRemoved = user3; //Better name for the snippet await chatThreadClient.RemoveMemberAsync(userToBeRemoved); AsyncPageable <ChatThreadMember> chatThreadMembersAfterOneDeleted = chatThreadClient.GetMembersAsync(); var chatThreadMembersAfterOneDeletedCount = chatThreadMembersAfterOneDeleted.ToEnumerableAsync().Result.Count(); Response typingNotificationResponse = await chatThreadClient.SendTypingNotificationAsync(); await chatThreadClient.SendTypingNotificationAsync(); await chatThreadClient.SendReadReceiptAsync(messageId); await chatThreadClient.SendReadReceiptAsync(sendChatMessageResult2.Id); AsyncPageable <ReadReceipt> readReceipts = chatThreadClient.GetReadReceiptsAsync(); var readReceiptsCount = readReceipts.ToEnumerableAsync().Result.Count(); await chatClient.DeleteChatThreadAsync(chatThreadClient.Id); //assert Assert.AreEqual(updatedTopic, chatThread.Topic); Assert.AreEqual(2, chatThread.Members.Count); Assert.AreEqual(contentMessage, message.Content); Assert.AreEqual(displayNameMessage, message.SenderDisplayName); Assert.AreEqual(ChatMessagePriority.High, message.Priority); Assert.AreEqual(2, threadsCount); Assert.AreEqual(5, getMessagesCount); //Including all types Assert.AreEqual(updatedMessageContent, actualUpdateMessage.Value.Content); Assert.IsTrue(deletedChatMessage.DeletedOn.HasValue); Assert.AreEqual(2, chatThreadMembersCount); Assert.AreEqual(3, chatThreadMembersAfterOneAddedCount); Assert.AreEqual(2, chatThreadMembersAfterOneDeletedCount); Assert.AreEqual((int)HttpStatusCode.OK, typingNotificationResponse.Status); //TODO: Commenting out the assert below for now as it is flakey due to server-side delay; currently in investigation // Assert.AreEqual(1, readReceiptsCount); }