Example #1
0
        private async Task SetTopicFirstPost(PhpbbTopics topic, PhpbbPosts post, AuthenticatedUser author, bool setTopicTitle, bool goForward = false)
        {
            var conn = _context.GetDbConnection();

            var curFirstPost = await conn.QueryFirstOrDefaultAsync <PhpbbPosts>("SELECT * FROM phpbb_posts WHERE post_id = @TopicFirstPostId", new { topic.TopicFirstPostId });

            if (topic.TopicFirstPostId == 0 || goForward || (curFirstPost != null && curFirstPost.PostTime >= post.PostTime))
            {
                if (setTopicTitle)
                {
                    topic.TopicTitle = post.PostSubject.Replace(Constants.REPLY, string.Empty).Trim();
                }
                topic.TopicFirstPostId       = post.PostId;
                topic.TopicFirstPosterColour = author.UserColor !;
                topic.TopicFirstPosterName   = author.Username !;

                await conn.ExecuteAsync(
                    @"UPDATE phpbb_topics 
                         SET topic_title = @TopicTitle, 
                             topic_first_post_id = @TopicFirstPostId, 
                             topic_first_poster_colour = @TopicFirstPosterColour, 
                             topic_first_poster_name = @TopicFirstPosterName
                    WHERE topic_id = @topicId",
                    topic
                    );
            }
        }
Example #2
0
        private async Task SetForumLastPost(PhpbbForums forum, PhpbbPosts post, AuthenticatedUser author, bool hardReset = false)
        {
            if (hardReset || forum.ForumLastPostTime < post.PostTime)
            {
                forum.ForumLastPostId       = post.PostId;
                forum.ForumLastPostSubject  = post.PostSubject;
                forum.ForumLastPostTime     = post.PostTime;
                forum.ForumLastPosterColour = author.UserColor !;
                forum.ForumLastPosterId     = post.PosterId;
                forum.ForumLastPosterName   = author.UserId == Constants.ANONYMOUS_USER_ID ? post.PostUsername : author.Username !;

                var conn = _context.GetDbConnection();

                await conn.ExecuteAsync(
                    @"UPDATE phpbb_forums 
                         SET forum_last_post_id = @ForumLastPostId, 
                             forum_last_post_subject = @ForumLastPostSubject, 
                             forum_last_post_time = @ForumLastPostTime, 
                             forum_last_poster_colour = @ForumLastPosterColour, 
                             forum_last_poster_id = @ForumLastPosterId, 
                             forum_last_poster_name = @ForumLastPosterName 
                       WHERE forum_id = @ForumId",
                    forum
                    );
            }
        }
Example #3
0
        private async Task SetTopicLastPost(PhpbbTopics topic, PhpbbPosts post, AuthenticatedUser author, bool hardReset = false)
        {
            if (hardReset || topic.TopicLastPostTime < post.PostTime)
            {
                topic.TopicLastPostId       = post.PostId;
                topic.TopicLastPostSubject  = post.PostSubject;
                topic.TopicLastPostTime     = post.PostTime;
                topic.TopicLastPosterColour = author.UserColor !;
                topic.TopicLastPosterId     = post.PosterId;
                topic.TopicLastPosterName   = author.UserId == Constants.ANONYMOUS_USER_ID ? post.PostUsername : author.Username !;

                var conn = _context.GetDbConnection();
                await conn.ExecuteAsync(
                    @"UPDATE phpbb_topics 
                         SET topic_last_post_id = @TopicLastPostId, 
                             topic_last_post_subject = @TopicLastPostSubject, 
                             topic_last_post_time = @TopicLastPostTime, 
                             topic_last_poster_colour = @TopicLastPosterColour, 
                             topic_last_poster_id = @TopicLastPosterId, 
                             topic_last_poster_name = @TopicLastPosterName 
                       WHERE topic_id = @TopicId",
                    topic
                    );
            }
        }
Example #4
0
        public async Task CascadePostEdit(PhpbbPosts added)
        {
            var conn = _context.GetDbConnection();

            var curTopic = await conn.QueryFirstOrDefaultAsync <PhpbbTopics>("SELECT * FROM phpbb_topics WHERE topic_id = @topicId", new { added.TopicId });

            var curForum = await conn.QueryFirstOrDefaultAsync <PhpbbForums>("SELECT * FROM phpbb_forums WHERE forum_id = @forumId", new { curTopic.ForumId });

            var usr = await _userService.GetAuthenticatedUserById(added.PosterId);

            if (curTopic.TopicFirstPostId == added.PostId)
            {
                await SetTopicFirstPost(curTopic, added, usr, true);
            }

            if (curTopic.TopicLastPostId == added.PostId)
            {
                await SetTopicLastPost(curTopic, added, usr);
            }

            if (curForum.ForumLastPostId == added.PostId)
            {
                await SetForumLastPost(curForum, added, usr);
            }
        }
Example #5
0
        public async Task CascadePostAdd(PhpbbPosts added, bool ignoreTopic)
        {
            var conn = _context.GetDbConnection();

            var curTopic = await conn.QueryFirstOrDefaultAsync <PhpbbTopics>("SELECT * FROM phpbb_topics WHERE topic_id = @topicId", new { added.TopicId });

            var curForum = await conn.QueryFirstOrDefaultAsync <PhpbbForums>("SELECT * FROM phpbb_forums WHERE forum_id = @forumId", new { curTopic.ForumId });

            var usr = await _userService.GetAuthenticatedUserById(added.PosterId);

            await SetForumLastPost(curForum, added, usr);

            if (!ignoreTopic)
            {
                await SetTopicLastPost(curTopic, added, usr);
                await SetTopicFirstPost(curTopic, added, usr, false);
            }

            await conn.ExecuteAsync(
                "UPDATE phpbb_topics SET topic_replies = topic_replies + 1, topic_replies_real = topic_replies_real + 1 WHERE topic_id = @topicId; " +
                "UPDATE phpbb_users SET user_posts = user_posts + 1 WHERE user_id = @userId",
                new { curTopic.TopicId, usr.UserId }
                );
        }
Example #6
0
        public async Task CascadePostDelete(PhpbbPosts deleted, bool ignoreTopic, bool ignoreAttachmentsAndReports)
        {
            var conn     = _context.GetDbConnection();
            var curTopic = await _context.PhpbbTopics.AsNoTracking().FirstOrDefaultAsync(t => t.TopicId == deleted.TopicId);

            if (curTopic != null && await _context.PhpbbPosts.AsNoTracking().AnyAsync(p => p.TopicId == deleted.TopicId))
            {
                if (curTopic.TopicLastPostId == deleted.PostId && !ignoreTopic)
                {
                    var lastTopicPost = await(
                        from p in _context.PhpbbPosts.AsNoTracking()
                        where p.TopicId == curTopic.TopicId && p.PostId != deleted.PostId
                        orderby p.PostTime descending
                        select p
                        ).FirstOrDefaultAsync();
                    if (lastTopicPost != null)
                    {
                        var lastTopicPostUser = await _userService.GetAuthenticatedUserById(lastTopicPost.PosterId);
                        await SetTopicLastPost(curTopic, lastTopicPost, lastTopicPostUser, true);
                    }
                }

                if (curTopic.TopicFirstPostId == deleted.PostId && !ignoreTopic)
                {
                    var firstTopicPost = await(
                        from p in _context.PhpbbPosts.AsNoTracking()
                        where p.TopicId == curTopic.TopicId && p.PostId != deleted.PostId
                        orderby p.PostTime ascending
                        select p
                        ).FirstOrDefaultAsync();
                    if (firstTopicPost != null)
                    {
                        var firstPostUser = await _userService.GetAuthenticatedUserById(firstTopicPost.PosterId);
                        await SetTopicFirstPost(curTopic, firstTopicPost, firstPostUser, false, true);
                    }
                }

                if (!ignoreTopic)
                {
                    await conn.ExecuteAsync(
                        "UPDATE phpbb_topics SET topic_replies = GREATEST(topic_replies - 1, 0), topic_replies_real = GREATEST(topic_replies_real - 1, 0) WHERE topic_id = @topicId",
                        new { curTopic.TopicId }
                        );
                }
            }
            else
            {
                await conn.ExecuteAsync("DELETE FROM phpbb_topics WHERE topic_id = @topicId", new { deleted.TopicId });
            }

            if (!ignoreAttachmentsAndReports)
            {
                await conn.ExecuteAsync(
                    "DELETE FROM phpbb_reports WHERE post_id = @postId; " +
                    "DELETE FROM phpbb_attachments WHERE post_msg_id = @postId",
                    new { deleted.PostId }
                    );
            }

            if (curTopic != null)
            {
                var curForum = await conn.QueryFirstOrDefaultAsync <PhpbbForums>("SELECT * FROM phpbb_forums WHERE forum_id = @forumId", new { forumId = curTopic?.ForumId ?? deleted.ForumId });

                if (curForum != null && curForum.ForumLastPostId == deleted.PostId)
                {
                    var lastForumPost = await(
                        from p in _context.PhpbbPosts.AsNoTracking()
                        where p.ForumId == curForum.ForumId && p.PostId != deleted.PostId
                        orderby p.PostTime descending
                        select p
                        ).FirstOrDefaultAsync();
                    if (lastForumPost != null)
                    {
                        var lastForumPostUser = await _userService.GetAuthenticatedUserById(lastForumPost.PosterId);
                        await SetForumLastPost(curForum, lastForumPost, lastForumPostUser, true);
                    }
                }
            }

            await conn.ExecuteAsync(
                "UPDATE phpbb_users SET user_posts = user_posts - 1 WHERE user_id = @posterId",
                new { deleted.PosterId }
                );
        }