Beispiel #1
0
        public void SendToQueue(Comment comment)
        {
            var db4Thing         = RedditThingConverter.Convert(comment);
            var queueMessageType = db4Thing.IsEdited ? QueueMessageType.Edit : QueueMessageType.Comment;

            pushToQueue(db4Thing, queueMessageType);
        }
Beispiel #2
0
        public DB4Thing GetCommentByUrl(string url)
        {
            url = UrlHelper.ConvertToOAuth(url);

            var qualifiedComment = _reddit.GetCommentAsync(new Uri(url)).Result;

            return(RedditThingConverter.Convert(qualifiedComment));
        }
Beispiel #3
0
        public void PopulateChildren(DB4Thing post)
        {
            // PopulateChildren should only be called on posts
            Assert.That(post.Type == DB4ThingType.Post);

            var qualifiedPost = (Post)getQualifiedThing(post);

            post.Comments = new List <DB4Thing>();

            Task.Run(async() =>
            {
                var postComments = await qualifiedPost.GetCommentsAsync();

                foreach (var postComment in postComments)
                {
                    post.Comments.Add(RedditThingConverter.Convert(postComment));
                }
            }).Wait();
        }
Beispiel #4
0
        public void PopulateParentAndChildren(DB4Thing comment)
        {
            // PopulateParentAndChildren should only be called on comments
            Assert.That(comment.Type == DB4ThingType.Comment);

            // Get comment with children and parent post populated
            var qualifiedComment = (Comment)getQualifiedThing(comment);

            // Set parent post
            comment.ParentPost = RedditThingConverter.Convert(qualifiedComment.Parent);

            // We also want all of the immediate children (comments) of a Post
            if (qualifiedComment.Parent is Post parentPost)
            {
                comment.ParentPost.Comments = new List <DB4Thing>();

                Task.Run(async() =>
                {
                    var postComments = await parentPost.GetCommentsAsync();

                    foreach (var postComment in postComments)
                    {
                        comment.ParentPost.Comments.Add(RedditThingConverter.Convert(postComment));
                    }
                }).Wait();
            }

            // Convert immediate children only
            var childComments = new List <DB4Thing>();

            foreach (Comment childComment in qualifiedComment.Comments)
            {
                childComments.Add(RedditThingConverter.Convert(childComment));
            }

            comment.Comments = childComments;

            // Get the parent thing - this could be the same as ParentPost above or it could be a comment
            var parentThing = _reddit.GetThingByFullnameAsync(comment.ParentId).Result;

            comment.ParentThing = RedditThingConverter.Convert(parentThing);
        }
        public DB4Thing Post(string title, string text, string subredditName = "")
        {
            var subReddit = _subreddit;

            // Since DB4 posts to another subreddit for DeltaLogs and registering multiple interfaces
            // against the DI container is a bit of a pain, default to main subreddit, but switch
            // to DeltaLog subreddit if passed in
            if (!string.IsNullOrEmpty(subredditName))
            {
                subReddit = _reddit.GetSubredditAsync($"/r/{subredditName}").Result;
            }

            // Submit post
            var post = subReddit.SubmitTextPostAsync(title, text).Result;

            // The returned post has basically nothing on it - need to retrieve a post with GetPost
            var oAuthUrl = UrlHelper.ConvertToOAuth(post.Url.AbsoluteUri);
            var fullPost = _reddit.GetPostAsync(new Uri(oAuthUrl)).Result;

            return(RedditThingConverter.Convert(fullPost));
        }
Beispiel #6
0
        public DB4Thing GetThingByFullname(string fullname)
        {
            var unqualifiedComment = _reddit.GetThingByFullnameAsync(fullname).Result;

            return(RedditThingConverter.Convert(unqualifiedComment));
        }
Beispiel #7
0
        public void SendToQueue(PrivateMessage privateMessage)
        {
            var db4Thing = RedditThingConverter.Convert(privateMessage);

            pushToQueue(db4Thing, QueueMessageType.PrivateMessage);
        }