예제 #1
0
        public async Task <ActionResult> SendMessage([FromBody] SendMessageRequest req,
                                                     [FromHeader] JwtBody jwt)
        {
            var group = await groupRepo.GetById(req.Title);

            if (group == null)
            {
                return(Json(new BaseResponse(false, "Group does not exist")));
            }

            var sendMessageModel = new SendMessagesModel()
            {
                message        = req.message,
                senderLanguage = jwt.language,
                recipientIds   = group.membersList.Select(m => m.Id).ToList()
            };

            return(RedirectToAction("SendMessages", "ChatController", new RouteValueDictionary
                                    (
                                        new
            {
                messageModal = sendMessageModel,
                jwtBody = jwt
            }
                                    )));
        }
예제 #2
0
        public async Task <JsonResult> SendMessages([FromBody] SendMessagesModel messageModal,
                                                    [FromHeader] JwtBody jwtBody)
        {
            // filter out users
            var recipients = await userRepository
                             .GetAll()
                             .Where(u => messageModal.recipientIds.Contains(u.Id.ToString()))
                             .Where(u => CanSendToUser(jwtBody.id, u))
                             .ToListAsync();

            var sender = await userRepository.GetById(jwtBody.id);

            bool sent = await messagingService.SendMessages(sender, recipients,
                                                            messageModal.message);

            return(Json(new BaseResponse(sent, sent ? null : "Not all users received message")));
        }