public async void SendNewChatNoticeAsync(ChatVm newChat, ClientConnection requestorConnection) { try { if (newChat.Users == null) { return; } foreach (var chatUser in newChat.Users) { var clients = connectionsService.GetUserClientConnections(chatUser.UserId); if (clients != null) { IEnumerable <ClientConnection> clientConnectionsWithoutCurrent = clients.Where(connection => requestorConnection != connection); NewChatNotice newChatNotice = new NewChatNotice(newChat); await SendNoticeToClientsAsync(clientConnectionsWithoutCurrent, newChatNotice).ConfigureAwait(false); } } } catch (Exception ex) { Logger.WriteLog(ex); } }
public async void SendNewUsersAddedToChatNoticeAsync(ChatVm chat, ClientConnection clientConnection) { try { List <ChatUserVm> filteredUsers = new List <ChatUserVm>(privacyService.ApplyPrivacySettings(chat.Users)); List <long> newUsersId = new List <long>(chat.Users.Select(chatUser => chatUser.UserId)); List <long> allUsersId = new List <long>((await loadChatsService.GetChatUsersIdAsync(chat.Id.Value).ConfigureAwait(false)).Except(newUsersId)); foreach (long chatUserId in allUsersId) { var clientConnections = connectionsService.GetUserClientConnections(chatUserId); if (clientConnections != null) { if (clientConnection != null) { clientConnections = clientConnections.Where(opt => opt != clientConnection).ToList(); } UsersAddedNotice notice = new UsersAddedNotice(filteredUsers, chat); await SendNoticeToClientsAsync(clientConnections, notice).ConfigureAwait(false); } } foreach (long chatUserId in newUsersId) { var clientConnections = connectionsService.GetUserClientConnections(chatUserId); if (clientConnections != null) { NewChatNotice notice = new NewChatNotice(chat); await SendNoticeToClientsAsync(clientConnections, notice).ConfigureAwait(false); } } } catch (Exception ex) { Logger.WriteLog(ex); } }