Exemplo n.º 1
0
        public async Task <PollDto> GetPollAsync(Guid pollId, long conversationId, ConversationType conversationType)
        {
            using (MessengerDbContext context = contextFactory.Create())
            {
                var poll = await context.Polls
                           .Include(opt => opt.Options)
                           .ThenInclude(opt => opt.PollOptionVotes)
                           .FirstOrDefaultAsync(opt =>
                                                opt.PollId == pollId &&
                                                opt.ConvertsationId == conversationId &&
                                                opt.ConversationType == conversationType)
                           .ConfigureAwait(false);

                if (poll == null)
                {
                    var nodeId = await conversationsService.GetConversationNodeIdAsync(conversationType, conversationId).ConfigureAwait(false);

                    var connection = connectionsService.GetNodeConnection(nodeId);
                    if (connection != null)
                    {
                        var loadedPoll = await nodeRequestSender.GetPollInformationAsync(conversationId, conversationType, pollId, connection).ConfigureAwait(false);

                        loadedPoll = await SavePollAsync(loadedPoll).ConfigureAwait(false);

                        return(loadedPoll);
                    }
                }
                return(PollConverter.GetPollDto(poll));
            }
        }
        public async Task HandleAsync()
        {
            try
            {
                if (notice.OptionsId != null && notice.OptionsId.Any())
                {
                    await pollsService.VotePollAsync(
                        notice.PollId,
                        notice.ConversationId,
                        notice.ConversationType,
                        notice.OptionsId,
                        notice.VotedUserId).ConfigureAwait(false);
                }
                else
                {
                    await pollsService.VotePollAsync(
                        notice.PollId,
                        notice.ConversationId,
                        notice.ConversationType,
                        notice.SignedOptions,
                        notice.VotedUserId).ConfigureAwait(false);
                }
            }
            catch (ObjectDoesNotExistsException)
            {
                var pollDto = await nodeRequestSender.GetPollInformationAsync(
                    notice.ConversationId,
                    notice.ConversationType,
                    notice.PollId,
                    nodeConnection).ConfigureAwait(false);

                await pollsService.SavePollAsync(pollDto).ConfigureAwait(false);
            }
        }
Exemplo n.º 3
0
        private async Task DownloadPollAttachmentAsync(AttachmentVm attachment, NodeConnection connection)
        {
            if (attachment.Payload is PollVm pollVm)
            {
                PollDto pollDto = await _nodeRequestSender.GetPollInformationAsync(
                    pollVm.ConversationId.Value,
                    pollVm.ConversationType.Value,
                    pollVm.PollId.Value,
                    connection).ConfigureAwait(false);

                await _pollsService.SavePollAsync(pollDto).ConfigureAwait(false);
            }
        }