private async Task SendDialogMessagesUpdatedNoticeAsync(IEnumerable <MessageDto> messages, ClientConnection clientConnection, long requestorId, long requestorDialogId, bool deleted) { IEnumerable <UserVm> users = await loadDialogsService.GetDialogUsersAsync(requestorDialogId).ConfigureAwait(false); UserVm receiver = users.FirstOrDefault(opt => opt.Id != requestorId); IEnumerable <MessageDto> receiverMessages = messages.Where(opt => opt.ConversationId != requestorDialogId); long?receiverDialogId = receiverMessages?.FirstOrDefault()?.ConversationId; var requestorMessages = receiverMessages != null?messages.Except(receiverMessages) : messages; MessageInfo requestorMessageInfo = new MessageInfo( requestorDialogId, ConversationType.Dialog, requestorMessages.Select(opt => opt.GlobalId)); MessageInfo receiverMessageInfo = new MessageInfo( receiverDialogId.GetValueOrDefault(), ConversationType.Dialog, receiverMessages?.Select(opt => opt.GlobalId)); MessagesUpdatedNotice requestorMessagesUpdatedNotice; MessagesUpdatedNotice receiverMessagesUpdatedNotice; if (deleted) { requestorMessagesUpdatedNotice = new MessagesUpdatedNotice(requestorMessageInfo, null); receiverMessagesUpdatedNotice = new MessagesUpdatedNotice(receiverMessageInfo, null); } else { requestorMessagesUpdatedNotice = new MessagesUpdatedNotice(null, MessageConverter.GetMessagesVm(requestorMessages, clientConnection?.UserId)); receiverMessagesUpdatedNotice = new MessagesUpdatedNotice(null, MessageConverter.GetMessagesVm(receiverMessages, receiver.Id)); } var requestorClients = connectionsService.GetUserClientConnections(requestorId); if (requestorClients != null) { await SendNoticeToClientsAsync(requestorClients.Where(opt => opt != clientConnection), requestorMessagesUpdatedNotice).ConfigureAwait(false); } if (receiver != null) { var receiverClients = connectionsService.GetUserClientConnections(receiver.Id.Value); if (receiverClients != null) { await SendNoticeToClientsAsync(receiverClients, receiverMessagesUpdatedNotice).ConfigureAwait(false); } } }
private async Task SendChannelMessagesUpdatedNoticeAsync(IEnumerable <MessageDto> messages, long conversationId, ClientConnection clientConnection, bool deleted) { MessageInfo messageInfo = new MessageInfo(conversationId, ConversationType.Channel, messages.Select(opt => opt.GlobalId)); MessagesUpdatedNotice notice = deleted ? new MessagesUpdatedNotice(messageInfo, null) : new MessagesUpdatedNotice(null, MessageConverter.GetMessagesVm(messages, clientConnection?.UserId)); List <ClientConnection> clientsConnections = new List <ClientConnection>(); IEnumerable <long> usersId = await loadChannelsService.GetChannelUsersIdAsync(conversationId).ConfigureAwait(false); foreach (long userId in usersId) { var clientConnections = connectionsService.GetUserClientConnections(userId); if (clientConnections != null) { clientsConnections.AddRange(clientConnections); } } clientsConnections.Remove(clientConnection); await SendNoticeToClientsAsync(clientsConnections, notice).ConfigureAwait(false); }
private async Task SendChatMessagesUpdatedNoticeAsync(IEnumerable <MessageDto> messages, long chatId, ClientConnection clientConnection, bool deleted) { IEnumerable <long> chatUsersId = await loadChatsService.GetChatUsersIdAsync(chatId).ConfigureAwait(false); MessageInfo messageInfo = new MessageInfo(chatId, ConversationType.Chat, messages.Select(opt => opt.GlobalId)); MessagesUpdatedNotice notice; if (deleted) { notice = new MessagesUpdatedNotice(messageInfo, null); } else { notice = new MessagesUpdatedNotice(null, MessageConverter.GetMessagesVm(messages, clientConnection?.UserId)); } foreach (long userId in chatUsersId) { var clientConnections = connectionsService.GetUserClientConnections(userId); if (clientConnections != null) { await SendNoticeToClientsAsync(clientConnections.Where(opt => opt != clientConnection), notice).ConfigureAwait(false); } } }