示例#1
0
        public Post PostReply(Topic topic, User user, int parentPostID, string ip, bool isFirstInTopic, NewPost newPost, DateTime postTime, string topicLink, Func <User, string> unsubscribeLinkGenerator, string userUrl, Func <Post, string> postLinkGenerator)
        {
            newPost.Title = _textParsingService.Censor(newPost.Title);
            if (newPost.IsPlainText)
            {
                newPost.FullText = _textParsingService.ForumCodeToHtml(newPost.FullText);
            }
            else
            {
                newPost.FullText = _textParsingService.ClientHtmlToHtml(newPost.FullText);
            }
            var postID = _postRepository.Create(topic.TopicID, parentPostID, ip, isFirstInTopic, newPost.IncludeSignature, user.UserID, user.Name, newPost.Title, newPost.FullText, postTime, false, user.Name, null, false, 0);
            var post   = new Post
            {
                PostID         = postID,
                FullText       = newPost.FullText,
                IP             = ip,
                IsDeleted      = false,
                IsEdited       = false,
                IsFirstInTopic = isFirstInTopic,
                LastEditName   = user.Name,
                LastEditTime   = null,
                Name           = user.Name,
                ParentPostID   = parentPostID,
                PostTime       = postTime,
                ShowSig        = newPost.IncludeSignature,
                Title          = newPost.Title,
                TopicID        = topic.TopicID,
                UserID         = user.UserID
            };

            _topicRepository.IncrementReplyCount(topic.TopicID);
            _topicRepository.UpdateLastTimeAndUser(topic.TopicID, user.UserID, user.Name, postTime);
            _forumRepository.UpdateLastTimeAndUser(topic.ForumID, postTime, user.Name);
            _forumRepository.IncrementPostCount(topic.ForumID);
            _topicRepository.MarkTopicForIndexing(topic.TopicID);
            _profileRepository.SetLastPostID(user.UserID, postID);
            if (unsubscribeLinkGenerator != null)
            {
                _subscribedTopicService.NotifySubscribers(topic, user, topicLink, unsubscribeLinkGenerator);
            }
            // <a href="{0}">{1}</a> made a post in the topic: <a href="{2}">{3}</a>
            var message = String.Format(Resources.NewReplyPublishMessage, userUrl, user.Name, postLinkGenerator(post), topic.Title);
            var forumHasViewRestrictions = _forumRepository.GetForumViewRoles(topic.ForumID).Count > 0;

            _eventPublisher.ProcessEvent(message, user, EventDefinitionService.StaticEventIDs.NewPost, forumHasViewRestrictions);
            _broker.NotifyNewPosts(topic, post.PostID);
            _broker.NotifyNewPost(topic, post.PostID);
            var forum = _forumRepository.Get(topic.ForumID);

            _broker.NotifyForumUpdate(forum);
            topic = _topicRepository.Get(topic.TopicID);
            _broker.NotifyTopicUpdate(topic, forum, topicLink);
            return(post);
        }
示例#2
0
        public Post PostReply(Topic topic, User user, int parentPostID, string ip, bool isFirstInTopic, NewPost newPost, DateTime postTime, string topicLink, Func <User, string> unsubscribeLinkGenerator, string userUrl, Func <Post, string> postLinkGenerator)
        {
            newPost.Title = _textParsingService.Censor(newPost.Title);
            // TODO: text parsing is controller, see issue #121 https://github.com/POPWorldMedia/POPForums/issues/121
            var postID = _postRepository.Create(topic.TopicID, parentPostID, ip, isFirstInTopic, newPost.IncludeSignature, user.UserID, user.Name, newPost.Title, newPost.FullText, postTime, false, user.Name, null, false, 0);
            var post   = new Post
            {
                PostID         = postID,
                FullText       = newPost.FullText,
                IP             = ip,
                IsDeleted      = false,
                IsEdited       = false,
                IsFirstInTopic = isFirstInTopic,
                LastEditName   = user.Name,
                LastEditTime   = null,
                Name           = user.Name,
                ParentPostID   = parentPostID,
                PostTime       = postTime,
                ShowSig        = newPost.IncludeSignature,
                Title          = newPost.Title,
                TopicID        = topic.TopicID,
                UserID         = user.UserID
            };

            _topicRepository.IncrementReplyCount(topic.TopicID);
            _topicRepository.UpdateLastTimeAndUser(topic.TopicID, user.UserID, user.Name, postTime);
            _forumRepository.UpdateLastTimeAndUser(topic.ForumID, postTime, user.Name);
            _forumRepository.IncrementPostCount(topic.ForumID);
            _searchIndexQueueRepository.Enqueue(new SearchIndexPayload {
                TenantID = _tenantService.GetTenant(), TopicID = topic.TopicID
            });
            _profileRepository.SetLastPostID(user.UserID, postID);
            if (unsubscribeLinkGenerator != null)
            {
                _subscribedTopicService.NotifySubscribers(topic, user, topicLink, unsubscribeLinkGenerator);
            }
            // <a href="{0}">{1}</a> made a post in the topic: <a href="{2}">{3}</a>
            var message = String.Format(Resources.NewReplyPublishMessage, userUrl, user.Name, postLinkGenerator(post), topic.Title);
            var forumHasViewRestrictions = _forumRepository.GetForumViewRoles(topic.ForumID).Count > 0;

            _eventPublisher.ProcessEvent(message, user, EventDefinitionService.StaticEventIDs.NewPost, forumHasViewRestrictions);
            _broker.NotifyNewPosts(topic, post.PostID);
            _broker.NotifyNewPost(topic, post.PostID);
            var forum = _forumRepository.Get(topic.ForumID);

            _broker.NotifyForumUpdate(forum);
            topic = _topicRepository.Get(topic.TopicID);
            _broker.NotifyTopicUpdate(topic, forum, topicLink);
            return(post);
        }
示例#3
0
        public async Task <BasicServiceResponse <Post> > PostReply(User user, int parentPostID, string ip, bool isFirstInTopic, NewPost newPost, DateTime postTime, Func <Topic, string> topicLinkGenerator, Func <User, Topic, string> unsubscribeLinkGenerator, string userUrl, Func <Post, string> postLinkGenerator, Func <Post, string> redirectLinkGenerator)
        {
            if (user == null)
            {
                return(GetReplyFailMessage(Resources.LoginToPost));
            }
            var topic = await _topicRepository.Get(newPost.ItemID);

            if (topic == null)
            {
                return(GetReplyFailMessage(Resources.TopicNotExist));
            }
            if (topic.IsClosed)
            {
                return(GetReplyFailMessage(Resources.Closed));
            }
            var forum = await _forumRepository.Get(topic.ForumID);

            if (forum == null)
            {
                throw new Exception($"That's not good. Trying to reply to a topic orphaned from Forum {topic.ForumID}, which doesn't exist.");
            }
            var permissionContext = await _forumPermissionService.GetPermissionContext(forum, user);

            if (!permissionContext.UserCanView)
            {
                return(GetReplyFailMessage(Resources.ForumNoView));
            }
            if (!permissionContext.UserCanPost)
            {
                return(GetReplyFailMessage(Resources.ForumNoPost));
            }
            newPost.FullText = newPost.IsPlainText ? _textParsingService.ForumCodeToHtml(newPost.FullText) : _textParsingService.ClientHtmlToHtml(newPost.FullText);
            if (await IsNewPostDupeOrInTimeLimit(newPost.FullText, user))
            {
                return(GetReplyFailMessage(string.Format(Resources.PostWait, _settingsManager.Current.MinimumSecondsBetweenPosts)));
            }
            if (string.IsNullOrEmpty(newPost.FullText))
            {
                return(GetReplyFailMessage(Resources.PostEmpty));
            }
            if (newPost.ParentPostID != 0)
            {
                var parentPost = await _postRepository.Get(newPost.ParentPostID);

                if (parentPost == null || parentPost.TopicID != topic.TopicID)
                {
                    return(GetReplyFailMessage("This reply attempt is being made to a post in another topic"));
                }
            }
            newPost.Title = _textParsingService.Censor(newPost.Title);

            var postID = await _postRepository.Create(topic.TopicID, parentPostID, ip, isFirstInTopic, newPost.IncludeSignature, user.UserID, user.Name, newPost.Title, newPost.FullText, postTime, false, user.Name, null, false, 0);

            var post = new Post
            {
                PostID         = postID,
                FullText       = newPost.FullText,
                IP             = ip,
                IsDeleted      = false,
                IsEdited       = false,
                IsFirstInTopic = isFirstInTopic,
                LastEditName   = user.Name,
                LastEditTime   = null,
                Name           = user.Name,
                ParentPostID   = parentPostID,
                PostTime       = postTime,
                ShowSig        = newPost.IncludeSignature,
                Title          = newPost.Title,
                TopicID        = topic.TopicID,
                UserID         = user.UserID
            };
            await _topicRepository.IncrementReplyCount(topic.TopicID);

            await _topicRepository.UpdateLastTimeAndUser(topic.TopicID, user.UserID, user.Name, postTime);

            await _forumRepository.UpdateLastTimeAndUser(topic.ForumID, postTime, user.Name);

            await _forumRepository.IncrementPostCount(topic.ForumID);

            await _searchIndexQueueRepository.Enqueue(new SearchIndexPayload { TenantID = _tenantService.GetTenant(), TopicID = topic.TopicID });

            await _profileRepository.SetLastPostID(user.UserID, postID);

            var topicLink = topicLinkGenerator(topic);

            if (unsubscribeLinkGenerator != null)
            {
                await _subscribedTopicsService.NotifySubscribers(topic, user, topicLink, unsubscribeLinkGenerator);
            }
            // <a href="{0}">{1}</a> made a post in the topic: <a href="{2}">{3}</a>
            var message = string.Format(Resources.NewReplyPublishMessage, userUrl, user.Name, postLinkGenerator(post), topic.Title);
            var forumHasViewRestrictions = _forumRepository.GetForumViewRoles(topic.ForumID).Result.Count > 0;
            await _eventPublisher.ProcessEvent(message, user, EventDefinitionService.StaticEventIDs.NewPost, forumHasViewRestrictions);

            topic = await _topicRepository.Get(topic.TopicID);

            forum = await _forumRepository.Get(forum.ForumID);

            _broker.NotifyNewPosts(topic, post.PostID);
            _broker.NotifyNewPost(topic, post.PostID);
            _broker.NotifyForumUpdate(forum);
            _broker.NotifyTopicUpdate(topic, forum, topicLink);
            _topicViewCountService.SetViewedTopic(topic);
            if (newPost.CloseOnReply && user.IsInRole(PermanentRoles.Moderator))
            {
                await _moderationLogService.LogTopic(user, ModerationType.TopicClose, topic, null);

                await _topicRepository.CloseTopic(topic.TopicID);
            }
            var redirectLink = redirectLinkGenerator(post);

            return(new BasicServiceResponse <Post> {
                Data = post, Message = null, Redirect = redirectLink, IsSuccessful = true
            });
        }