private void OnConversationAdded(object sender, EntityChangedEventArgs <Conversation> e) { var conversationNotification = new EntityNotification <Conversation>(e.Entity, NotificationType.Create); IEnumerable <int> userIds = participationRepository.GetParticipationsByConversationId(e.Entity.Id).Select(participation => participation.UserId); ClientManager.SendMessageToClients(conversationNotification, userIds); }
private void OnParticipationUpdated(object sender, EntityChangedEventArgs <Participation> e) { IEnumerable <string> listOfUsersTyping = from participant in participationRepository.GetParticipationsByConversationId(groupChat.Conversation.Id) where participant.UserTyping.IsUserTyping select userRepository.FindEntityById(participant.UserId).Username; string usersTyping = ChatWindowStringBuilder.CreateUsersTypingMessage(listOfUsersTyping.ToList()); GroupChat.UsersTyping = usersTyping; }
private void OnParticipationAdded(object sender, EntityChangedEventArgs <Participation> e) { Participation participation = e.Entity; List <Participation> conversationParticipants = participationRepository.GetParticipationsByConversationId(participation.ConversationId); var participationNotification = new EntityNotification <Participation>(participation, NotificationType.Create); IEnumerable <int> conversationParticipantUserIds = conversationParticipants.Select(conversationParticipation => conversationParticipation.UserId); ClientManager.SendMessageToClients(participationNotification, conversationParticipantUserIds); List <Participation> otherParticipants = conversationParticipants.Where(conversationParticipant => !conversationParticipant.Equals(participation)).ToList(); otherParticipants.ForEach( otherParticipant => ClientManager.SendMessageToClient(new EntityNotification <Participation>(otherParticipant, NotificationType.Create), participation.UserId)); Conversation conversation = conversationRepository.FindEntityById(participation.ConversationId); SendConversationNotificationToParticipants(conversation, participation.UserId, otherParticipants); }
private string GetConversationParticipants() { var usernames = new List <string>(); var titleBuilder = new StringBuilder(); foreach (Participation participant in participationRepository.GetParticipationsByConversationId(conversation.Id)) { usernames.Add(userRepository.FindEntityById(participant.UserId).Username); } titleBuilder.Append(ChatWindowStringBuilder.CreateUserListTitle(usernames)); return(titleBuilder.ToString()); }
private static bool CheckUserCanEnterConversation(ParticipationRequest participationRequest, ParticipationRepository participationRepository) { Participation newparticipation = participationRequest.Participation; List <Participation> currentParticipantsInConversation = participationRepository.GetParticipationsByConversationId(newparticipation.ConversationId); if (currentParticipantsInConversation.Any(participation => participation.UserId == newparticipation.UserId)) { Log.WarnFormat($"User with id {participationRequest.Participation.UserId} cannot be added to conversation {participationRequest.Participation.ConversationId}, user already exists in this conversation."); return(false); } return(true); }
public void GetParticipationsByConversationIdTest() { const int conversationId = 10; var participationRepository = new ParticipationRepository(); var participation1 = new Participation(1, 1, conversationId); var participation2 = new Participation(2, 2, conversationId); participationRepository.AddEntity(participation1); participationRepository.AddEntity(participation2); var expectedParticipations = new List <Participation> { participation1, participation2 }; IEnumerable <Participation> actualParticipations = participationRepository.GetParticipationsByConversationId(conversationId); Assert.AreEqual(expectedParticipations, actualParticipations); }