Ejemplo n.º 1
0
        public TextMessageModel SendTextMessage(User sender, uint chatId, string text)
        {
            var chat = _repository.GetChat(chatId);

            ValidateUserInChat(chat, sender.Name);
            var message = new TextMessage {
                Date = DateTime.UtcNow, FromUser = sender, Text = text
            };

            _repository.AddMessage(chat, message);
            _updatesService.NotifyAddMessage(message, chat);
            return(TextMessageToModel(message));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddMessage(Guid chatId, string text, Guid?isAnswerFor)
        {
            var authorId = User.Claims.ToList()[0].Value;
            await _chatRep.AddMessage(chatId, text, authorId, isAnswerFor);

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task SendMessage(string author, string text)
        {
            await chatRepository.AddMessage(author, text);

            var messages = (await chatRepository.ChatMessagesOrderedByDateAsync()).ToEnumerable();
            await Clients.All.SendAsync("sendMessage", messages.Select(x => new { x.Author, x.Text, x.CreationDate }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Send([FromBody] Message message)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                if (message.Content.StartsWith("/"))
                {
                    await _publishEndpoint.Publish(message);
                }
                else
                {
                    _chatRepository.AddMessage(message);
                    await _hubContext.Clients.All.SendAsync(ChatHubMethods.ReceiveMessage, message);
                }

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public IActionResult AddMessage([FromBody] Message message)
        {
            message.UserName = User.Identity.Name;
            _repository.AddMessage(message);

            return(Ok());
        }
Ejemplo n.º 6
0
        public Message AddMessage(string chatName, string text, string from)
        {
            if (text.Length > 150 || string.IsNullOrWhiteSpace(text))
            {
                throw new MessageInvalidException(text);
            }

            var chat = _chatRepo.GetChats().SingleOrDefault(c => c.Name == chatName);
            var user = _userRepo.GetUsers().SingleOrDefault(c => c.Username == from);

            if (chat == null)
            {
                return(null);
            }

            var message = new Message(user, text);

            _chatRepo.AddMessage(chat, message);

            if (!chat.Participants.Any(p => p.Username == from))
            {
                _chatRepo.AddParticipant(chat, user);
            }

            return(message);
        }
Ejemplo n.º 7
0
        public async Task <Task <Amazon.DynamoDBv2.Model.PutItemResponse> > SendMessage(int senderId, SendMessage sendMessage, string datetime)
        {
            var messageDb = _mapper.ToMessageDbModel(senderId, sendMessage, datetime);
            var response  = await _chatRepository.AddMessage(messageDb);

            return(response);
        }
Ejemplo n.º 8
0
        public async Task <Message> AddMessage(Message message)
        {
            message.PostedTimeUTC = DateTime.UtcNow;
            message = _chatRepository.AddMessage(message);
            await _chatRepository.SaveChangesAsync();

            return(message);
        }
Ejemplo n.º 9
0
        public void AddMessage(Message model)
        {
            // The user that sent the message
            model.User = _chatRepository.GetUser(model.UserId);
            model.Date = DateTime.UtcNow;

            var id = _chatRepository.AddMessage(model);

            model.Id = id;

            ChatHub.AddMessage(model.RoomId.ToString(), model);
        }
Ejemplo n.º 10
0
        public async Task AddMessage(NewChatMessageModel model)
        {
            var encryptionKey = _configuration.GetEncryptionKey();
            var chatMessage   = new ChatMessage
            {
                MatchId    = model.MatchId,
                Message    = EncryptionHelper.Encrypt(model.Message, encryptionKey),
                SenderId   = model.SenderId,
                ReceiverId = model.ReceiverId
            };

            await _chatRepository.AddMessage(chatMessage);
        }
Ejemplo n.º 11
0
        public void AddMessage(string messageInput, int chatRoomId)
        {
            var sessionUser = _userService.GetSessionUser();

            var message = new Message
            {
                Text        = messageInput,
                ChatRoomId  = chatRoomId,
                UserId      = sessionUser.Id,
                DateCreated = DateTime.Now
            };

            _chatRepository.AddMessage(message);
        }
Ejemplo n.º 12
0
        public async Task Send(string userLogin, string contactLogin, string message)
        {
            var user = await _userRepository.GetAsync(userLogin);

            var contact = await _userRepository.GetAsync(contactLogin);

            if (user == null || contact == null)
            {
                throw new System.Exception("User not found.");
            }
            var chat = await _chatRepository.GetSingleChat(user.Id, contact.Id);

            var msg = new Message(user, contact, message, chat);
            await _chatRepository.AddMessage(msg, chat);
        }
Ejemplo n.º 13
0
        public void AddMessage(string text, int accountId, Chat chat)
        {
            Message message = new Message();

            message.ChatId      = chat.ChatId;
            message.MessageSent = DateTime.Now;
            message.TextMessage = text;

            // Determine whether you're the sender or receiver
            if (chat.ReceiverId == accountId)
            {
                message.SenderIsReceiver = true;
            }
            else
            {
                message.SenderIsReceiver = false;
            }

            chatRepository.AddMessage(message);
        }
Ejemplo n.º 14
0
        public void AddMessage(ChatModel chatModel)
        {
            // Grava a mensagem
            _chatRepository.AddMessage(chatModel);

            // Grava a quantidade de mensagens por usuário
            var countByUser = _chatCountRepository.GetByUser(chatModel.UserId);

            var count = 1;

            if (countByUser != null)
            {
                count = Convert.ToInt32(countByUser.GetValue("Count")) + 1;
                _chatCountRepository.DeleteByUser(chatModel.UserId);
            }

            ChatCountModel chatCountModel = new ChatCountModel(chatModel.UserId, count.ToString());

            _chatCountRepository.Add(chatCountModel);
        }
Ejemplo n.º 15
0
        public IActionResult AddMessage(int chatId, [FromBody] ChatMessage newMessage)
        {
            string token = User.FindFirst("token").Value;
            User   user  = Users.FindByToken(token);

            if (user == null)
            {
                return(Unauthorized());
            }

            var message = Chats.AddMessage(new ChatMessage
            {
                ChatID  = chatId,
                UserID  = user.ID,
                Message = newMessage.Message
            });

            return(Json(new
            {
                success = true,
                data = message
            }));
        }
Ejemplo n.º 16
0
        public async Task Send(NewMessage sendedMessage)
        {
            var message = await chatRepository.AddMessage(sendedMessage.Text, sendedMessage.ChatId, Context.User.Identity.Name);

            await Clients.Users(Context.User.Identity.Name, sendedMessage.UserNameTo).SendAsync("Recived", message);
        }
Ejemplo n.º 17
0
 public void NewMessage(Message message)
 {
     _chatRepo.AddMessage(ObjectTranslator.GetDbMessage(message));
 }