public async Task <Response> CreateResponseAsync() { try { PollDto poll; poll = await pollsService.VotePollAsync( request.PollId, request.ConversationId, request.ConversationType, request.Options, clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false); List <long> nodesId = null; switch (poll.ConversationType) { case ConversationType.Chat: { nodesId = await loadChatsService.GetChatNodeListAsync(poll.ConversationId).ConfigureAwait(false); } break; case ConversationType.Channel: { nodesId = await loadChannelsService.GetChannelNodesIdAsync(poll.ConversationId).ConfigureAwait(false); } break; } nodeNoticeService.SendPollingNodeNoticeAsync( poll.PollId, poll.ConversationId, poll.ConversationType, request.Options, clientConnection.UserId.GetValueOrDefault(), nodesId); return(new PollResponse(request.RequestId, PollConverter.GetPollVm(poll, clientConnection.UserId.GetValueOrDefault()))); } catch (PermissionDeniedException ex) { return(new ResultResponse(request.RequestId, ex.Message, ErrorCode.PermissionDenied)); } catch (ObjectDoesNotExistsException ex) { return(new ResultResponse(request.RequestId, ex.Message, ErrorCode.ObjectDoesNotExists)); } catch (InvalidOperationException ex) { return(new ResultResponse(request.RequestId, ex.Message, ErrorCode.InvalidArgument)); } catch (InvalidSignException ex) { return(new ResultResponse(request.RequestId, ex.Message, ErrorCode.InvalidSign)); } }
public async void SendNewChatMessageNodeNoticeAsync(MessageVm newMessage) { try { IEnumerable <long> nodesIds = await _loadChatsService.GetChatNodeListAsync(newMessage.ConversationId.GetValueOrDefault()).ConfigureAwait(false); newMessage.NodesId = nodesIds; if (newMessage.Attachments != null && newMessage.Attachments.Any()) { var forwardedMessagesAttachment = newMessage.Attachments.FirstOrDefault(message => message.Type == AttachmentType.ForwardedMessages); if (forwardedMessagesAttachment != null) { await _updateMessagesService.UpdateMessagesNodesIdsAsync((List <MessageVm>) forwardedMessagesAttachment.Payload, nodesIds).ConfigureAwait(false); } } NewMessagesNodeNotice notice = new NewMessagesNodeNotice(newMessage); await SendNoticeToNodesAsync(notice, nodesIds).ConfigureAwait(false); } catch (Exception ex) { Logger.WriteLog(ex); } }
public async Task <Response> CreateResponseAsync() { try { List <ChatUserVm> chatUsers = await loadChatsService.GetChatUsersAsync( request.ChatId, clientConnection.UserId.GetValueOrDefault(), 100, request.NavigationUserId.GetValueOrDefault()).ConfigureAwait(false); if (!chatUsers.Any(user => user.UserRole == UserRole.Creator)) { var nodesIds = await loadChatsService.GetChatNodeListAsync(request.ChatId).ConfigureAwait(false); var nodeConnection = connectionsService.GetNodeConnection(nodesIds.FirstOrDefault(id => id != NodeSettings.Configs.Node.Id)); if (nodeConnection != null) { var chat = await nodeRequestSender.GetFullChatInformationAsync(request.ChatId, nodeConnection).ConfigureAwait(false); if (chat != null) { await crossNodeService.NewOrEditChatAsync(chat).ConfigureAwait(false); chatUsers = chat.Users?.Take(100).ToList(); } } } chatUsers.ForEach(item => { if (item.UserInfo != null) { item.UserInfo = privacyService.ApplyPrivacySettings( item.UserInfo, item.UserInfo.Privacy); } }); return(new ChatUsersResponse(request.RequestId, chatUsers)); } catch (GetUsersException ex) { Logger.WriteLog(ex, request); return(new ResultResponse(request.RequestId, "User does not have access to the chat.", ErrorCode.PermissionDenied)); } }