Exemple #1
0
        public ActionResult <IEnumerable <ConversationModel> > Get([FromHeader(Name = "Authorisation")] string userToken)
        {
            User user = _userService.GetUserByToken(userToken);

            if (user == null || !_userService.IsValid(user))
            {
                return(Unauthorized());
            }

            List <ConversationModel> conversations = _conversationService.GetUserConversations(user.Name).ToList();

            foreach (ConversationModel conversation in conversations.Where(c => string.IsNullOrEmpty(c.Text)))
            {
                conversation.Text = _messangesService.GetMessages(conversation.Id, user.Name)
                                    .LastOrDefault()?
                                    .Text;
            }

            return(Ok(conversations));
        }
Exemple #2
0
        public ActionResult <IEnumerable <MessageModel> > Get([FromHeader(Name = "Authorisation")] string userToken,
                                                              [FromRoute] Guid conversationId)
        {
            User user = _userService.GetUserByToken(userToken);

            if (user == null || !_userService.IsValid(user))
            {
                return(Unauthorized());
            }

            Conversation conv = _conversationService.Get(conversationId, user.Name);

            if (conv == null)
            {
                return(NotFound());
            }

            if (!conv.Participants.Contains(user.Name))
            {
                return(Unauthorized("You're not part of the conversation"));
            }

            return(Ok(_messangesService.GetMessages(conversationId, user.Name)));
        }