Exemplo n.º 1
0
        private string GetInfoPostOrCommentParentFullname(Things.Info info)
        {
            if (info == null)
            {
                return(null);
            }

            return(info.Posts != null && info.Posts.Count > 0 ? info.Posts[0].Name : info.Comments[0].ParentId);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return information about the current Comment instance via the api/info endpoint.
        /// </summary>
        /// <returns>An instance of this class populated with the retrieved data.</returns>
        public Comment Info()
        {
            Things.Info info = Validate(Dispatch.LinksAndComments.Info(Fullname, Subreddit));
            if (info == null ||
                info.Comments == null ||
                info.Comments.Count == 0 ||
                !Fullname.Equals(info.Comments[0].Name))
            {
                throw new RedditControllerException("Unable to retrieve comment data.");
            }

            return(new Comment(Dispatch, info.Comments[0]));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the post to which this comment belongs.
        /// </summary>
        /// <param name="fullname">The fullname of the comment whose post data we're looking for</param>
        /// <returns>The parent post of this comment.</returns>
        public Post GetRoot(string fullname = null)
        {
            fullname = fullname ?? ParentFullname;
            if (string.IsNullOrWhiteSpace(fullname))
            {
                return(null);
            }

            Things.Info info = null;
            do
            {
                info     = Validate(Dispatch.LinksAndComments.Info(fullname, Subreddit));
                fullname = GetInfoPostOrCommentParentFullname(info);
            } while (info != null && info.Comments != null && info.Comments.Count > 0 &&
                     !string.IsNullOrWhiteSpace(fullname) && !fullname.StartsWith("t3_"));

            return(new Post(Dispatch, fullname).About());
        }