private User DoUpNewTopic()
		{
			var forum = new Forum(1);
			var user = GetUser();
			const string ip = "127.0.0.1";
			const string title = "mah title";
			const string text = "mah text";
			var newPost = new NewPost { Title = title, FullText = text, ItemID = 1 };
			var forumService = GetService();
			_mockTopicRepo.Setup(t => t.GetUrlNamesThatStartWith("parsed-title")).Returns(new List<string>());
			_mockTextParser.Setup(t => t.ClientHtmlToHtml("mah text")).Returns("parsed text");
			_mockTextParser.Setup(t => t.EscapeHtmlAndCensor("mah title")).Returns("parsed title");
			_mockPostRepo.Setup(p => p.Create(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<bool>(), It.IsAny<string>(), null, It.IsAny<bool>(), It.IsAny<int>())).Returns(69);
			_mockForumRepo.Setup(x => x.GetForumViewRoles(forum.ForumID)).Returns(new List<string>());
			forumService.PostNewTopic(forum, user, new ForumPermissionContext { UserCanPost = true, UserCanView = true }, newPost, ip, It.IsAny<string>(), x => "");
			return user;
		}
		public void PostNewTopicReturnsTopic()
		{
			var forum = new Forum(1);
			var user = GetUser();
			const string ip = "127.0.0.1";
			const string title = "mah title";
			const string text = "mah text";
			var newPost = new NewPost { Title = title, FullText = text, ItemID = 1 };
			var topicService = GetService();
			_mockForumRepo.Setup(x => x.GetForumViewRoles(forum.ForumID)).Returns(new List<string>());
			_mockTopicRepo.Setup(t => t.GetUrlNamesThatStartWith("parsed-title")).Returns(new List<string>());
			_mockTextParser.Setup(t => t.ClientHtmlToHtml("mah text")).Returns("parsed text");
			_mockTextParser.Setup(t => t.EscapeHtmlAndCensor("mah title")).Returns("parsed title");
			_mockTopicRepo.Setup(t => t.Create(forum.ForumID, "parsed title", 0, 0, user.UserID, user.Name, user.UserID, user.Name, It.IsAny<DateTime>(), false, false, false, false, "parsed-title")).Returns(2);
			var topic = topicService.PostNewTopic(forum, user, new ForumPermissionContext { UserCanPost = true, UserCanView = true }, newPost, ip, It.IsAny<string>(), x => "");
			Assert.AreEqual(2, topic.TopicID);
			Assert.AreEqual(forum.ForumID, topic.ForumID);
			Assert.AreEqual("parsed title", topic.Title);
			Assert.AreEqual(0, topic.ReplyCount);
			Assert.AreEqual(0, topic.ViewCount);
			Assert.AreEqual(user.UserID, topic.StartedByUserID);
			Assert.AreEqual(user.Name, topic.StartedByName);
			Assert.AreEqual(user.UserID, topic.LastPostUserID);
			Assert.AreEqual(user.Name, topic.LastPostName);
			Assert.IsFalse(topic.IsClosed);
			Assert.IsFalse(topic.IsDeleted);
			Assert.IsFalse(topic.IsIndexed);
			Assert.IsFalse(topic.IsPinned);
			Assert.AreEqual("parsed-title", topic.UrlName);
		}
		public void PostNewTopicDoesNotPublishToFeedIfForumHasViewRestrictions()
		{
			var forum = new Forum(1);
			var user = GetUser();
			const string ip = "127.0.0.1";
			const string title = "mah title";
			const string text = "mah text";
			var newPost = new NewPost { Title = title, FullText = text, ItemID = 1 };
			var topicService = GetService();
			_mockForumRepo.Setup(x => x.GetForumViewRoles(forum.ForumID)).Returns(new List<string> { "Admin" });
			_mockTopicRepo.Setup(t => t.GetUrlNamesThatStartWith("parsed-title")).Returns(new List<string>());
			_mockTextParser.Setup(t => t.ClientHtmlToHtml("mah text")).Returns("parsed text");
			_mockTextParser.Setup(t => t.EscapeHtmlAndCensor("mah title")).Returns("parsed title");
			_mockTopicRepo.Setup(t => t.Create(forum.ForumID, "parsed title", 0, 0, user.UserID, user.Name, user.UserID, user.Name, It.IsAny<DateTime>(), false, false, false, false, "parsed-title")).Returns(2);
			var topic = topicService.PostNewTopic(forum, user, new ForumPermissionContext { UserCanPost = true, UserCanView = true }, newPost, ip, It.IsAny<string>(), x => "");
			_eventPublisher.Verify(x => x.ProcessEvent(It.IsAny<string>(), It.IsAny<User>(), EventDefinitionService.StaticEventIDs.NewTopic, true), Times.Once());
		}
		public void PostNewTopicCallsTextParserPlainText()
		{
			var forum = new Forum(1);
			var user = GetUser();
			const string ip = "127.0.0.1";
			const string title = "mah title";
			const string text = "mah text";
			var newPost = new NewPost { Title = title, FullText = text, ItemID = 1, IsPlainText = true };
			var topicService = GetService();
			_mockForumRepo.Setup(x => x.GetForumViewRoles(forum.ForumID)).Returns(new List<string>());
			_mockTopicRepo.Setup(t => t.GetUrlNamesThatStartWith("parsed-title")).Returns(new List<string>());
			_mockTextParser.Setup(t => t.ClientHtmlToHtml("mah text")).Returns("parsed text");
			_mockTextParser.Setup(t => t.EscapeHtmlAndCensor("mah title")).Returns("parsed title");
			topicService.PostNewTopic(forum, user, new ForumPermissionContext { UserCanPost = true, UserCanView = true }, newPost, ip, It.IsAny<string>(), x => "");
			_mockTextParser.Verify(t => t.EscapeHtmlAndCensor("mah title"), Times.Once());
			_mockTextParser.Verify(t => t.ClientHtmlToHtml("mah text"), Times.Exactly(0));
			_mockTextParser.Verify(t => t.ForumCodeToHtml("mah text"), Times.Exactly(1));
		}
Beispiel #5
0
		public bool IsNewPostDupeOrInTimeLimit(NewPost newPost, User user)
		{
			var postID = _profileRepository.GetLastPostID(user.UserID);
			if (postID == null)
				return false;
			var lastPost = _postRepository.Get(postID.Value);
			if (lastPost == null)
				return false;
			var minimumSeconds = _settingsManager.Current.MinimumSecondsBetweenPosts;
			if (DateTime.UtcNow.Subtract(lastPost.PostTime).TotalSeconds < minimumSeconds)
				return true;
			var parsedText = newPost.IsPlainText ? _textParsingService.ForumCodeToHtml(newPost.FullText) : _textParsingService.ClientHtmlToHtml(newPost.FullText);
			if (parsedText == lastPost.FullText)
				return true;
			return false;
		}
		public void PostReplyHitsSubscribedService()
		{
			var topic = new Topic(1);
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string>());
			var newPost = new NewPost { FullText = "mah text", Title = "mah title", IncludeSignature = true };
			topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", u => "", "", x => "");
			_subService.Verify(s => s.NotifySubscribers(topic, user, It.IsAny<string>(), It.IsAny<Func<User, string>>()), Times.Once());
		}
		public void PostReplySetsProfileLastPostID()
		{
			var topic = new Topic(1) { ForumID = 2 };
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string>());
			var newPost = new NewPost { FullText = "mah text", Title = "mah title", IncludeSignature = true };
			var post = topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", u => "", "", x => "");
			_profileRepo.Verify(p => p.SetLastPostID(user.UserID, post.PostID));
		}
		public JsonResult PostReply(NewPost newPost)
		{
			if (this.CurrentUser() == null)
				return Json(new BasicJsonMessage { Message = Resources.LoginToPost, Result = false });
			ForumPermissionContext permissionContext;
			var topic = _topicService.Get(newPost.ItemID);
			if (topic == null)
				return Json(new BasicJsonMessage { Message = Resources.TopicNotExist, Result = false });
			if (topic.IsClosed)
				return Json(new BasicJsonMessage { Message = Resources.Closed, Result = false });
			GetForumByIdWithPermissionContext(topic.ForumID, out permissionContext);
			if (!permissionContext.UserCanView)
				return Json(new BasicJsonMessage { Message = Resources.ForumNoView, Result = false });
			if (!permissionContext.UserCanPost)
				return Json(new BasicJsonMessage { Message = Resources.ForumNoPost, Result = false });
			if (_postService.IsNewPostDupeOrInTimeLimit(newPost, this.CurrentUser()))
				return Json(new BasicJsonMessage { Message = String.Format(Resources.PostWait, _settingsManager.Current.MinimumSecondsBetweenPosts), Result = false });
			if (String.IsNullOrEmpty(newPost.FullText))
				return Json(new BasicJsonMessage { Message = Resources.PostEmpty, Result = false });
			if (newPost.ParentPostID != 0)
			{
				var parentPost = _postService.Get(newPost.ParentPostID);
				if (parentPost == null || parentPost.TopicID != topic.TopicID)
					return Json(new BasicJsonMessage { Message = "This reply attempt is being made to a post in another topic", Result = false });
			}

			var user = this.CurrentUser();
			var topicLink = this.FullUrlHelper("GoToNewestPost", Name, new { id = topic.TopicID });
			Func<User, string> unsubscribeLinkGenerator =
				u => this.FullUrlHelper("Unsubscribe", SubscriptionController.Name, new { topicID = topic.TopicID, authKey = u.AuthorizationKey });
			var helper = new UrlHelper(Request.RequestContext);
			var userProfileUrl = helper.Action("ViewProfile", "Account", new { id = user.UserID });
			Func<Post, string> postLinkGenerator = p => helper.Action("PostLink", "Forum", new { id = p.PostID });
			var post = _topicService.PostReply(topic, user, newPost.ParentPostID, Request.UserHostAddress, false, newPost, DateTime.UtcNow, topicLink, unsubscribeLinkGenerator, userProfileUrl, postLinkGenerator);
			_topicViewCountService.SetViewedTopic(topic, HttpContext);
			var currentUser = this.CurrentUser();
			if (newPost.CloseOnReply && currentUser.IsInRole(PermanentRoles.Moderator))
				_topicService.CloseTopic(topic, currentUser);
			var urlHelper = new UrlHelper(ControllerContext.RequestContext);
			return Json(new BasicJsonMessage { Result = true, Redirect = urlHelper.RouteUrl(new { controller = "Forum", action = "PostLink", id = post.PostID }) });
		}
		public void PostReplyMarksTopicForIndexing()
		{
			var topic = new Topic(1) { ForumID = 2 };
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string>());
			var newPost = new NewPost { FullText = "mah text", Title = "mah title", IncludeSignature = true };
			topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", u => "", "", x => "");
			_topicRepo.Verify(x => x.MarkTopicForIndexing(topic.TopicID), Times.Once());
		}
		public void PostReplyNotifiesBroker()
		{
			var topic = new Topic(1) { ForumID = 2 };
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string>());
			var newPost = new NewPost { FullText = "mah text", Title = "mah title", IncludeSignature = true };
			var forum = new Forum(topic.ForumID);
			_forumRepo.Setup(x => x.Get(topic.ForumID)).Returns(forum);
			_topicRepo.Setup(x => x.Get(topic.TopicID)).Returns(topic);
			topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", u => "", "", x => "");
			_broker.Verify(x => x.NotifyForumUpdate(forum), Times.Once());
			_broker.Verify(x => x.NotifyTopicUpdate(topic, forum, It.IsAny<string>()), Times.Once());
			_broker.Verify(x => x.NotifyNewPost(topic, It.IsAny<int>()), Times.Once());
		}
		public void PostReplyUpdatesForumLastInfo()
		{
			var topic = new Topic(1) { ForumID = 2 };
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string>());
			var newPost = new NewPost { FullText = "mah text", Title = "mah title", IncludeSignature = true };
			topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", u => "", "", x => "");
			_forumRepo.Verify(f => f.UpdateLastTimeAndUser(topic.ForumID, postTime, user.Name));
		}
		public void PostReplyIncrementsTopicReplyCount()
		{
			var topic = new Topic(1);
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string>());
			var newPost = new NewPost { FullText = "mah text", Title = "mah title", IncludeSignature = true };
			topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", u => "", "", x => "");
			_topicRepo.Verify(t => t.IncrementReplyCount(1));
		}
		public void PostReplyHitsTextParserPlainText()
		{
			var topic = new Topic(1);
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string>());
			var newPost = new NewPost { FullText = "mah text", Title = "mah title", IncludeSignature = true, IsPlainText = true };
			topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", u => "", "", x => "");
			_textParser.Verify(t => t.EscapeHtmlAndCensor("mah title"), Times.Once());
			_textParser.Verify(t => t.ClientHtmlToHtml("mah text"), Times.Exactly(0));
			_textParser.Verify(t => t.ForumCodeToHtml("mah text"), Times.Once());
		}
Beispiel #14
0
		public JsonResult PostTopic(NewPost newPost)
		{
			if (this.CurrentUser() == null)
				return Json(new BasicJsonMessage { Message = Resources.LoginToPost, Result = false });
			ForumPermissionContext permissionContext;
			var forum = GetForumByIdWithPermissionContext(newPost.ItemID, out permissionContext);
			if (!permissionContext.UserCanView)
				return Json(new BasicJsonMessage {Message = Resources.ForumNoView, Result = false});
			if (!permissionContext.UserCanPost)
				return Json(new BasicJsonMessage {Message = Resources.ForumNoPost, Result = false});
			if (_postService.IsNewPostDupeOrInTimeLimit(newPost, this.CurrentUser()))
				return Json(new BasicJsonMessage { Message = String.Format(Resources.PostWait, _settingsManager.Current.MinimumSecondsBetweenPosts), Result = false });
			if (String.IsNullOrWhiteSpace(newPost.FullText) || String.IsNullOrWhiteSpace(newPost.Title))
				return Json(new BasicJsonMessage { Message = Resources.PostEmpty, Result = false });

			var user = this.CurrentUser();
			var urlHelper = new UrlHelper(ControllerContext.RequestContext);
			var userProfileUrl = urlHelper.Action("ViewProfile", "Account", new { id = user.UserID });
			Func<Topic, string> topicLinkGenerator = t => urlHelper.Action("Topic", "Forum", new { id = t.UrlName });
			var topic = _forumService.PostNewTopic(forum, user, permissionContext, newPost, Request.UserHostAddress, userProfileUrl, topicLinkGenerator);
			_topicViewCountService.SetViewedTopic(topic, HttpContext);
			return Json(new BasicJsonMessage { Result = true, Redirect = urlHelper.RouteUrl(new { controller = "Forum", action = "Topic", id = topic.UrlName }) });
		}
		public void PostReplyDoesNotPublisheEventOnViewRestrictedForum()
		{
			var topic = new Topic(1) { ForumID = 2 };
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string> { "Admin" });
			var newPost = new NewPost { FullText = "mah text", Title = "mah title", IncludeSignature = true };
			topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", u => "", "", x => "");
			_eventPublisher.Verify(x => x.ProcessEvent(It.IsAny<string>(), user, EventDefinitionService.StaticEventIDs.NewPost, true), Times.Once());
		}
Beispiel #16
0
		public ActionResult PostReply(int id, int quotePostID = 0, int replyID = 0)
		{
			var user = this.CurrentUser();
			if (user == null)
				return Content(Resources.LoginToPost);
			var topic = _topicService.Get(id);
			if (topic == null)
				return Content(Resources.TopicNotExist);
			var forum = _forumService.Get(topic.ForumID);
			if (forum == null)
				throw new Exception(String.Format("TopicID {0} references ForumID {1}, which does not exist.", topic.TopicID, topic.ForumID));
			if (topic.IsClosed)
				return Content(Resources.Closed);
			var permissionContext = _forumService.GetPermissionContext(forum, this.CurrentUser(), topic);
			if (!permissionContext.UserCanView)
				return Content(Resources.ForumNoView);
			if (!permissionContext.UserCanPost)
				return Content(Resources.ForumNoPost);

			var title = topic.Title;
			if (!title.ToLower().StartsWith("re:"))
				title = "Re: " + title;
			var profile = _profileService.GetProfile(user);
			var forcePlainText = _mobileDetectionWrapper.IsMobileDevice(HttpContext);
			var newPost = new NewPost { ItemID = topic.TopicID, Title = title, IncludeSignature = profile.Signature.Length > 0, IsPlainText = forcePlainText || profile.IsPlainText, IsImageEnabled = _settingsManager.Current.AllowImages, ParentPostID = replyID };

			if (quotePostID != 0)
			{
				var post = _postService.Get(quotePostID);
				newPost.FullText = _postService.GetPostForQuote(post, user, forcePlainText);
			}

			if (forum.IsQAForum)
			{
				newPost.IncludeSignature = false;
				if (newPost.ParentPostID == 0)
				{
					ViewBag.IsQA = true;
					return View("NewReply", newPost);
				}
				return View("NewComment", newPost);
			}
			return View("NewReply", newPost);
		}
		public void PostReplyReturnsHydratedObject()
		{
			var topic = new Topic(1);
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string>());
			_postRepo.Setup(p => p.Create(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), false, true, It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), false, It.IsAny<string>(), null, false, 0)).Returns(123);
			_textParser.Setup(t => t.ClientHtmlToHtml("mah text")).Returns("parsed text");
			_textParser.Setup(t => t.EscapeHtmlAndCensor("mah title")).Returns("parsed title");
			var newPost = new NewPost { FullText = "mah text", Title = "mah title", IncludeSignature = true };
			var post = topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", u => "", "", x => "");
			Assert.AreEqual(topic.TopicID, post.TopicID);
			Assert.AreEqual("parsed text", post.FullText);
			Assert.AreEqual("127.0.0.1", post.IP);
			Assert.IsFalse(post.IsDeleted);
			Assert.IsFalse(post.IsEdited);
			Assert.IsFalse(post.IsFirstInTopic);
			Assert.AreEqual(user.Name, post.LastEditName);
			Assert.IsNull(post.LastEditTime);
			Assert.AreEqual(user.Name, post.Name);
			Assert.AreEqual(0, post.ParentPostID);
			Assert.AreEqual(123, post.PostID);
			Assert.AreEqual(postTime, post.PostTime);
			Assert.IsTrue(post.ShowSig);
			Assert.AreEqual("parsed title", post.Title);
			Assert.AreEqual(user.UserID, post.UserID);
		}
Beispiel #18
0
		public ActionResult PostTopic(int id)
		{
			var user = this.CurrentUser();
			if (user == null)
				return Content(Resources.LoginToPost);
			ForumPermissionContext permissionContext;
			var forum = GetForumByIdWithPermissionContext(id, out permissionContext);
			if (!permissionContext.UserCanView)
				return Content(Resources.ForumNoView);
			if (!permissionContext.UserCanPost)
				return Content(Resources.ForumNoPost);

			var profile = _profileService.GetProfile(user);
			var newPost = new NewPost { ItemID = forum.ForumID, IncludeSignature = profile.Signature.Length > 0, IsPlainText = _mobileDetectionWrapper.IsMobileDevice(HttpContext) || profile.IsPlainText, IsImageEnabled = _settingsManager.Current.AllowImages };
			return View("NewTopic", newPost);
		}
Beispiel #19
0
		public Topic PostNewTopic(Forum forum, User user, ForumPermissionContext permissionContext, NewPost newPost, string ip, string userUrl, Func<Topic, string> topicLinkGenerator)
		{
			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);
			_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;
		}
Beispiel #20
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.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 void PostReplyHitsRepo()
		{
			var topic = new Topic(1) { Title = "" };
			var user = GetUser();
			var postTime = DateTime.UtcNow;
			var topicService = GetTopicService();
			_forumRepo.Setup(x => x.GetForumViewRoles(It.IsAny<int>())).Returns(new List<string>());
			var newPost = new NewPost {FullText = "mah text", Title = "mah title", IncludeSignature = true};
			_textParser.Setup(t => t.ClientHtmlToHtml(newPost.FullText)).Returns("parsed text");
			_textParser.Setup(t => t.EscapeHtmlAndCensor(newPost.Title)).Returns("parsed title");
			topicService.PostReply(topic, user, 0, "127.0.0.1", false, newPost, postTime, "", It.IsAny<Func<User, string>>(), "", x => "");
			_postRepo.Verify(p => p.Create(topic.TopicID, 0, "127.0.0.1", false, true, user.UserID, user.Name, "parsed title", "parsed text", postTime, false, user.Name, null, false, 0));
		}