Example #1
0
        public async Task <IActionResult> GetConversation(int id, int recipientId, [FromQuery] MessengerPaginationParams messengerPaginationParams)
        {
            var messagesThread = await messenger.GetMessagesThread(id, recipientId, messengerPaginationParams);

            if (messagesThread.Count == 0)
            {
                return(NotFound("Brak wiadomoĊ›ci"));
            }

            var messagesThreadToReturn = mapper.Map <List <MessageDetailsDto> >(messagesThread);

            for (int i = 0; i < messagesThreadToReturn.Count(); i++)
            {
                messagesThreadToReturn[i].OwnerName = messagesThread[i].Conversation.WithSchool ? messagesThread[i].Conversation.Owner.School.Name : messagesThread[i].Conversation.Owner.Rental.Name;
            }

            string photoUrl = messagesThread[0].Conversation.UserId != id ? messagesThread[0].Conversation.User.PhotoUrl : (messagesThread[0].Conversation.WithSchool ? messagesThread[0].Conversation.Owner.School.LogoUrl : null);

            Response.AddPagination(messagesThread.CurrentPage, messagesThread.PageSize, messagesThread.TotalCount, messagesThread.TotalPages);

            return(Ok(new
            {
                messages = messagesThreadToReturn,
                photoUrl
            }));
        }