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.EscapeHtmlAndCensor(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) { 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); }
public async Task <PrivateMessage> Create(string subject, string fullText, User user, List <User> toUsers) { if (String.IsNullOrWhiteSpace(subject)) { throw new ArgumentNullException("subject"); } if (String.IsNullOrWhiteSpace(fullText)) { throw new ArgumentNullException("fullText"); } if (user == null) { throw new ArgumentNullException("user"); } if (toUsers == null || toUsers.Count == 0) { throw new ArgumentException("toUsers must include at least one user.", "toUsers"); } var names = user.Name; foreach (var toUser in toUsers) { names += ", " + toUser.Name; } var now = DateTime.UtcNow; var pm = new PrivateMessage { Subject = _textParsingService.EscapeHtmlAndCensor(subject), UserNames = names, LastPostTime = now }; pm.PMID = await _privateMessageRepository.CreatePrivateMessage(pm); await _privateMessageRepository.AddUsers(pm.PMID, new List <int> { user.UserID }, now, true); await _privateMessageRepository.AddUsers(pm.PMID, toUsers.Select(u => u.UserID).ToList(), now.AddSeconds(-1), false); var post = new PrivateMessagePost { FullText = _textParsingService.ForumCodeToHtml(fullText), Name = user.Name, PMID = pm.PMID, PostTime = now, UserID = user.UserID }; await _privateMessageRepository.AddPost(post); return(pm); }
public void EditPost(Post post, PostEdit postEdit, User editingUser) { var oldText = post.FullText; post.Title = _textParsingService.EscapeHtmlAndCensor(postEdit.Title); if (postEdit.IsPlainText) { post.FullText = _textParsingService.ForumCodeToHtml(postEdit.FullText); } else { post.FullText = _textParsingService.ClientHtmlToHtml(postEdit.FullText); } post.ShowSig = postEdit.ShowSig; post.LastEditTime = DateTime.UtcNow; post.LastEditName = editingUser.Name; post.IsEdited = true; _postRepository.Update(post); _moderationLogService.LogPost(editingUser, ModerationType.PostEdit, post, postEdit.Comment, oldText); }
public Topic PostNewTopic(Forum forum, User user, ForumPermissionContext permissionContext, NewPost newPost, string ip, string userUrl, Func <Topic, string> topicLinkGenerator, DateTime timeStamp) { if (!permissionContext.UserCanPost || !permissionContext.UserCanView) { throw new Exception(String.Format("User {0} can't post to forum {1}.", user.Name, forum.Title)); } newPost.Title = _textParsingService.EscapeHtmlAndCensor(newPost.Title); if (newPost.IsPlainText) { newPost.FullText = _textParsingService.ForumCodeToHtml(newPost.FullText); } else { newPost.FullText = _textParsingService.ClientHtmlToHtml(newPost.FullText); } var urlName = newPost.Title.ToUniqueUrlName(_topicRepository.GetUrlNamesThatStartWith(newPost.Title.ToUrlName())); //var timeStamp = DateTime.UtcNow; var topicID = _topicRepository.Create(forum.ForumID, newPost.Title, 0, 0, user.UserID, user.Name, user.UserID, user.Name, timeStamp, false, false, false, false, urlName); var postID = _postRepository.Create(topicID, 0, ip, true, newPost.IncludeSignature, user.UserID, user.Name, newPost.Title, newPost.FullText, timeStamp, false, user.Name, null, false, 0, newPost.IsAnonymous, newPost.FileUrl); _forumRepository.UpdateLastTimeAndUser(forum.ForumID, timeStamp, user.Name); _forumRepository.IncrementPostAndTopicCount(forum.ForumID); _profileRepository.SetLastPostID(user.UserID, postID); var topic = new Topic(topicID) { ForumID = forum.ForumID, IsClosed = false, IsDeleted = false, IsIndexed = false, IsPinned = false, LastPostName = user.Name, LastPostTime = timeStamp, LastPostUserID = user.UserID, ReplyCount = 0, StartedByName = user.Name, StartedByUserID = user.UserID, Title = newPost.Title, UrlName = urlName, ViewCount = 0 }; // <a href="{0}">{1}</a> started a new topic: <a href="{2}">{3}</a> var topicLink = topicLinkGenerator(topic); var message = String.Format(Resources.NewPostPublishMessage, userUrl, user.Name, topicLink, topic.Title); var forumHasViewRestrictions = _forumRepository.GetForumViewRoles(forum.ForumID).Count > 0; _eventPublisher.ProcessEvent(message, user, EventDefinitionService.StaticEventIDs.NewTopic, forumHasViewRestrictions); _eventPublisher.ProcessEvent(String.Empty, user, EventDefinitionService.StaticEventIDs.NewPost, true); forum = _forumRepository.Get(forum.ForumID); _broker.NotifyForumUpdate(forum); _broker.NotifyTopicUpdate(topic, forum, topicLink); return(topic); }