Example #1
0
 public async Task GetPoll()
 {
     var chat = fillTestDbHelper.Chats.FirstOrDefault();
     var chatUser = chat.ChatUsers.FirstOrDefault();
     var poll = new PollDto
     {
         ConversationId = chat.Id,
         ConversationType = ConversationType.Chat,
         Title = "Poll",
         CreatorId = chatUser.UserId,
         Options = new List<PollOptionDto>
         {
             new PollOptionDto
             {
                 Description = "desc",
                 OptionId = 1
             },
             new PollOptionDto
             {
                 Description = "desc 2",
                 OptionId = 2
             }
         }
     };
     var expectedPoll = await pollsService.SavePollAsync(poll);
     var actualPoll = await pollsService.GetPollAsync(poll.PollId, poll.ConversationId, poll.ConversationType);
     Assert.True(expectedPoll.ConversationId == actualPoll.ConversationId
         && expectedPoll.ConversationType == actualPoll.ConversationType
         && expectedPoll.Title == actualPoll.Title
         && expectedPoll.CreatorId == actualPoll.CreatorId);
 }
Example #2
0
        public async Task HandleAsync()
        {
            try
            {
                var pollDto = await pollsService.GetPollAsync(request.PollId, request.ConversationId, request.ConversationType).ConfigureAwait(false);

                NodeWebSocketCommunicationManager.SendResponse(new PollNodeResponse(request.RequestId, pollDto), current);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
                NodeWebSocketCommunicationManager.SendResponse(new ResultNodeResponse(request.RequestId, ObjectsLibrary.Enums.ErrorCode.UnknownError), current);
            }
        }
        public async Task <bool> CheckEditedMessageAttachmentsAsync(MessageVm message, long userId)
        {
            try
            {
                foreach (var attachment in message.Attachments)
                {
                    switch (attachment.Type)
                    {
                    case AttachmentType.Audio:
                    case AttachmentType.File:
                    case AttachmentType.Picture:
                    case AttachmentType.Video:
                    {
                        if (attachment.Payload is string stringPayload)
                        {
                            var fileInfo = _filesService.GetFileInfoAsync(stringPayload);
                            if (fileInfo == null)
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                    case AttachmentType.ForwardedMessages:
                    {
                        if (attachment.Payload is ForwardedMessagesInfo messagesInfo)
                        {
                            var messages = await _loadMessagesService.GetMessagesByIdAsync(
                                messagesInfo.MessagesGlobalId,
                                messagesInfo.ConversationType,
                                messagesInfo.ConversationId.GetValueOrDefault(),
                                userId).ConfigureAwait(false);

                            if (messages == null || !messages.Any())
                            {
                                return(false);
                            }
                        }
                        else if (attachment.Payload is List <MessageVm> messages)
                        {
                            await _createMessagesService.SaveForwardedMessagesAsync(MessageConverter.GetMessagesDto(messages)).ConfigureAwait(false);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                    case AttachmentType.Poll:
                    {
                        if (attachment.Payload is PollVm poll)
                        {
                            var existingPoll = await _pollsService.GetPollAsync(
                                poll.PollId.GetValueOrDefault(),
                                message.ConversationId.GetValueOrDefault(),
                                message.ConversationType).ConfigureAwait(false);

                            if (existingPoll == null)
                            {
                                poll = await PollConverter.InitPollConversationAsync(poll, message).ConfigureAwait(false);

                                poll.PollId = RandomExtensions.NextGuid();
                                await _pollsService.SavePollAsync(PollConverter.GetPollDto(poll, userId)).ConfigureAwait(false);

                                attachment.Payload = poll;
                            }
                        }
                    }
                    break;

                    case AttachmentType.VoiceMessage:
                    {
                        await ValidateVoiceMessageAttachmentAsync(attachment);
                    }
                    break;
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
                return(false);
            }
        }