Beispiel #1
0
        /// <summary>
        /// Returns a list with all the comments belonging to a given post, in reverse chronological order
        /// </summary>
        /// <param name="actualRequest">the client request to be handled</param>
        /// <returns>the response to the given request</returns>
        private async Task <ActualRequest> GetAllCommentsForPostAsync(ActualRequest actualRequest)
        {
            Request request = actualRequest.Request;
            int     postId  = Convert.ToInt32(request.Argument.ToString());
            List <CommentSockets> comments = await postRepo.GetAllCommentsForPost(postId);

            Request response = new Request
            {
                ActionType = ActionType.POST_GET_COMMENTS.ToString(),
                Argument   = JsonSerializer.Serialize(comments)
            };
            List <byte[]> userAvatars = new List <byte[]>();

            if (comments != null && comments.Count > 0)
            {
                foreach (var comment in comments)
                {
                    try {
                        var readAvatarFile = File.ReadAllBytes($"{FILE_PATH}/Users/{comment.Owner.UserId}/avatar.jpg");
                        userAvatars.Add(ImagesUtil.ResizeImage(readAvatarFile, 20, 20));
                    }
                    catch (Exception e) {
                        Console.WriteLine("No avatar found for user ");
                    }
                }
            }
            return(new ActualRequest
            {
                Request = response,
                Images = userAvatars
            });
        }