예제 #1
0
        public async Task <IActionResult> Create(Guid appId, Guid channelId, [FromBody] EditedMessage message)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var messageDto = new Message
            {
                Value      = message.Value,
                CustomData = message.CustomData
            };

            var created = await _messageService.Create(HttpContext.GetCurrentUserId(), appId, channelId, messageDto);

            if (created == null)
            {
                return(NotFound("Channel not found"));
            }

            return(CreatedAtAction(nameof(Get), new { appId, channelId }, created));
        }
예제 #2
0
        public static MessageDto GetMessageDto(EditedMessage editedMessage, Message message)
        {
            MessageDto result = new MessageDto
            {
                SendingTime = message.SendingTime,
                Text        = editedMessage.Text,
                Attachments = editedMessage.Attachments?.Select(attach => new AttachmentDto
                {
                    Hash    = attach.Hash,
                    Payload = attach.Payload,
                    Type    = attach.AttachmentType
                }).ToList(),
                SenderId   = message.SenderId,
                Replyto    = message.Replyto,
                ReceiverId = message.ReceiverId,
                Read       = message.Read,
                GlobalId   = message.GlobalId,
                Deleted    = message.Deleted,
                UpdatedAt  = message.UpdatedAt
            };

            if (message.ChatId != null)
            {
                result.ConversationType = ConversationType.Chat;
                result.ConversationId   = message.ChatId.Value;
            }
            if (message.ChannelId != null)
            {
                result.ConversationType = ConversationType.Channel;
                result.ConversationId   = message.ChannelId.Value;
            }
            if (message.DialogId != null)
            {
                result.ConversationType = ConversationType.Dialog;
                result.ConversationId   = message.DialogId.Value;
            }
            return(result);
        }
예제 #3
0
        public async Task <IActionResult> Edit(Guid appId, Guid channelId, Guid messageId, [FromBody] EditedMessage messageUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var currentUser = HttpContext.GetCurrentUserId();
            var message     = await _messageService.Get(currentUser, appId, channelId, messageId);

            if (message == null)
            {
                return(NotFound("Channel or message not found"));
            }

            message.Value      = messageUpdate.Value;
            message.CustomData = messageUpdate.CustomData;

            var updated = await _messageService.Edit(currentUser, appId, channelId, message);

            if (updated == null)
            {
                return(NotFound("Channel or message not found"));
            }

            return(Ok(updated));
        }