示例#1
0
		public Post GetFirstInTopic(Topic topic)
		{
			var post = _postRepository.GetFirstInTopic(topic.TopicID);
			if (post == null)
				throw new Exception("No first post found for TopicID " + topic.TopicID);
			return post;
		}
        public void NotifyTopicUpdate(Topic topic, Forum forum, string topicLink)
        {
            var isForumViewRestricted = _forumRepo.GetForumViewRoles(forum.ForumID).Count > 0;

            _timeFormattingService.Init(null);
            var recentHubContext = GlobalHost.ConnectionManager.GetHubContext <Recent>();
            var result           = new
            {
                Link  = topicLink,
                Image = "NewIndicator.png",
                topic.TopicID,
                topic.StartedByName,
                topic.Title,
                ForumTitle = forum.Title,
                topic.ViewCount,
                topic.ReplyCount,
                LastPostTime = _timeFormattingService.GetFormattedTime(topic.LastPostTime),
                Utc          = topic.LastPostTime.ToString("o"),
                topic.LastPostName
            };
            var forumHubContext = GlobalHost.ConnectionManager.GetHubContext <Forums>();

            if (isForumViewRestricted)
            {
                recentHubContext.Clients.Group("forum" + forum.ForumID).notifyRecentUpdate(result);
            }
            else
            {
                recentHubContext.Clients.All.notifyRecentUpdate(result);
            }
            forumHubContext.Clients.Group(forum.ForumID.ToString()).notifyUpdatedTopic(result);
        }
		public void MarkSubNullUser()
		{
			var service = GetService();
			var topic = new Topic(456);
			service.MarkSubscribedTopicViewed(null, topic);
			_mockSubRepo.Verify(s => s.MarkSubscribedTopicViewed(It.IsAny<int>(), It.IsAny<int>()), Times.Never());
		}
示例#4
0
		public void NotifyTopicUpdate(Topic topic, Forum forum, string topicLink)
		{
			var isForumViewRestricted = _forumRepo.GetForumViewRoles(forum.ForumID).Count > 0;
			_timeFormattingService.Init(null);
			var recentHubContext = GlobalHost.ConnectionManager.GetHubContext<Recent>();
			var result = new
				{
					Link = topicLink,
					Image = "NewIndicator.png",
					topic.TopicID,
					topic.StartedByName,
					topic.Title,
					ForumTitle = forum.Title,
					topic.ViewCount,
					topic.ReplyCount,
					LastPostTime = _timeFormattingService.GetFormattedTime(topic.LastPostTime),
					Utc = topic.LastPostTime.ToString("o"),
					topic.LastPostName
				};
			var forumHubContext = GlobalHost.ConnectionManager.GetHubContext<Forums>();
			if (isForumViewRestricted)
				recentHubContext.Clients.Group("forum" + forum.ForumID).notifyRecentUpdate(result);
			else
				recentHubContext.Clients.All.notifyRecentUpdate(result);
			forumHubContext.Clients.Group(forum.ForumID.ToString()).notifyUpdatedTopic(result);
		}
		public void TryRemoveSubTopicNullUser()
		{
			var service = GetService();
			var topic = new Topic(456);
			service.TryRemoveSubscribedTopic(null, topic);
			_mockSubRepo.Verify(s => s.RemoveSubscribedTopic(It.IsAny<int>(), It.IsAny<int>()), Times.Never());
		}
		public void TryRemoveSubTopic()
		{
			var service = GetService();
			var user = new User(123, DateTime.MaxValue);
			var topic = new Topic(456);
			service.TryRemoveSubscribedTopic(user, topic);
			_mockSubRepo.Verify(s => s.RemoveSubscribedTopic(user.UserID, topic.TopicID), Times.Once());
		}
示例#7
0
		public DateTime? GetTopicReadStatus(User user, Topic topic)
		{
			if (user != null)
			{
				return _lastReadRepository.GetLastReadTimeForTopic(user.UserID, topic.TopicID);
			}
			return null;
		}
示例#8
0
		public void MarkTopicRead(User user, Topic topic)
		{
			if (user == null)
				throw new ArgumentNullException("user");
			if (topic == null)
				throw new ArgumentNullException("topic");
			_lastReadRepository.SetTopicRead(user.UserID, topic.TopicID, DateTime.UtcNow);
		}
		public void RemoveFaveTopic()
		{
			var service = GetService();
			var user = new User(123, DateTime.MaxValue);
			var topic = new Topic(456);
			service.RemoveFavoriteTopic(user, topic);
			_mockFaveRepo.Verify(s => s.RemoveFavoriteTopic(user.UserID, topic.TopicID), Times.Once());
		}
		public void OpenOnClosedTopic()
		{
			var topic = new Topic(5) { IsClosed = true };
			var controller = GetController();
			_mockTopicService.Setup(t => t.Get(topic.TopicID)).Returns(topic);
			controller.ToggleClosed(topic.TopicID);
			_mockTopicService.Verify(t => t.CloseTopic(topic, It.IsAny<User>()), Times.Exactly(0));
			_mockTopicService.Verify(t => t.OpenTopic(topic, It.IsAny<User>()), Times.Exactly(1));
		}
		public void UnpinOnPinnedTopic()
		{
			var topic = new Topic(5) { IsPinned = true };
			var controller = GetController();
			_mockTopicService.Setup(t => t.Get(topic.TopicID)).Returns(topic);
			controller.TogglePin(topic.TopicID);
			_mockTopicService.Verify(t => t.PinTopic(topic, It.IsAny<User>()), Times.Exactly(0));
			_mockTopicService.Verify(t => t.UnpinTopic(topic, It.IsAny<User>()), Times.Exactly(1));
		}
示例#12
0
		public void GetPostsPagerContextConstructed()
		{
			var topic = new Topic(1) { ReplyCount = 20 };
			var postService = GetService();
			_settings.Setup(s => s.PostsPerPage).Returns(3);
			PagerContext pagerContext;
			postService.GetPosts(topic, false, 4, out pagerContext);
			Assert.AreEqual(7, pagerContext.PageCount);
			Assert.AreEqual(4, pagerContext.PageIndex);
		}
示例#13
0
		public void GetPostsReplyCountCalledOnIncludeDeleted()
		{
			var topic = new Topic(1) { ReplyCount = 20 };
			var postService = GetService();
			_settings.Setup(s => s.PostsPerPage).Returns(2);
			_postRepo.Setup(p => p.GetReplyCount(topic.TopicID, true)).Returns(21);
			PagerContext pagerContext;
			postService.GetPosts(topic, true, 4, out pagerContext);
			_postRepo.Verify(p => p.GetReplyCount(topic.TopicID, true), Times.Once());
			Assert.AreEqual(11, pagerContext.PageCount);
		}
示例#14
0
		public void GetPostsPageSizeAndStartRowCalcdCorrectly()
		{
			var topic = new Topic(1) {ReplyCount = 20};
			var postService = GetService();
			_settings.Setup(s => s.PostsPerPage).Returns(2);
			PagerContext pagerContext;
			postService.GetPosts(topic, false, 4, out pagerContext);
			_postRepo.Verify(p => p.Get(1, false, 7, 2), Times.Once());
			_postRepo.Verify(p => p.GetReplyCount(It.IsAny<int>(), It.IsAny<bool>()), Times.Never());
			Assert.AreEqual(11, pagerContext.PageCount);
			Assert.AreEqual(2, pagerContext.PageSize);
		}
		public void GoodIdAndGuidCallsTryUnsubAndReturnsModel()
		{
			var controller = GetController();
			var topic = new Topic(123);
			var user = new User(456, DateTime.MinValue) { AuthorizationKey = Guid.NewGuid() };
			_topicService.Setup(t => t.Get(topic.TopicID)).Returns(topic);
			_userService.Setup(u => u.GetUserByAuhtorizationKey(user.AuthorizationKey)).Returns(user);
			var model = (TopicUnsubscribeContainer) controller.Unsubscribe(topic.TopicID, user.AuthorizationKey.ToString()).ViewData.Model;
			Assert.AreSame(topic, model.Topic);
			Assert.AreSame(user, model.User);
			_subService.Verify(s => s.TryRemoveSubscribedTopic(user, topic));
		}
示例#16
0
		public List<Post> GetPosts(Topic topic, int lastLoadedPostID, bool includeDeleted, out PagerContext pagerContext)
		{
			var allPosts = _postRepository.Get(topic.TopicID, includeDeleted);
			var lastIndex = allPosts.FindIndex(p => p.PostID == lastLoadedPostID);
			if (lastIndex < 0)
				throw new Exception(String.Format("PostID {0} is not a part of TopicID {1}.", lastLoadedPostID, topic.TopicID));
			var posts = allPosts.Skip(lastIndex + 1).ToList();
			var pageSize = _settingsManager.Current.PostsPerPage;
			var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(allPosts.Count) / Convert.ToDouble(pageSize)));
			pagerContext = new PagerContext { PageCount = totalPages, PageIndex = totalPages, PageSize = pageSize };
			return posts;
		}
示例#17
0
		public List<Post> GetPosts(Topic topic, bool includeDeleted, int pageIndex, out PagerContext pagerContext)
		{
			var pageSize = _settingsManager.Current.PostsPerPage;
			var startRow = ((pageIndex - 1) * pageSize) + 1;
			var posts = _postRepository.Get(topic.TopicID, includeDeleted, startRow, pageSize);
			int postCount;
			if (includeDeleted)
				postCount = _postRepository.GetReplyCount(topic.TopicID, true);
			else
				postCount = topic.ReplyCount + 1;
			var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(postCount) / Convert.ToDouble(pageSize)));
			pagerContext = new PagerContext { PageCount = totalPages, PageIndex = pageIndex, PageSize = pageSize };
			return posts;
		}
		public void ProcessView(Topic topic, HttpContextBase context)
		{
			if (context.Request.Cookies[CookieKey] != null)
			{
				int topicID;
				if (int.TryParse(context.Request.Cookies[CookieKey].Value, out topicID))
				{
					if (topicID != topic.TopicID)
						_topicRepository.IncrementViewCount(topic.TopicID);
				}
			}
			else
				_topicRepository.IncrementViewCount(topic.TopicID);
			SetViewedTopic(topic, context);
		}
		public void NotifySubscribers(Topic topic, User postingUser, string topicLink, Func<User, string> unsubscribeLinkGenerator)
		{
			new Thread(() => {
				var users = _subscribedTopicsRepository.GetSubscribedUsersThatHaveViewed(topic.TopicID);
				foreach (var user in users)
				{
					if (user.UserID != postingUser.UserID)
					{
						var unsubScribeLink = unsubscribeLinkGenerator(user);
						_subscribedTopicEmailComposer.ComposeAndQueue(topic, user, topicLink, unsubScribeLink);
					}
				}
				_subscribedTopicsRepository.MarkSubscribedTopicUnviewed(topic.TopicID);
			}).Start();
		}
		public void ComposeAndQueue(Topic topic, User user, string topicLink, string unsubscribeLink)
		{
			var settings = _settingsManager.Current;
			var body = String.Format(Resources.SubscribedEmailBody, settings.ForumTitle, topic.Title, topicLink, unsubscribeLink, settings.MailSignature, Environment.NewLine);
			var message = new QueuedEmailMessage
			              	{
			              		Body = body, 
								Subject =String.Format(Resources.SubscribedEmailSubject, topic.Title), 
								ToEmail = user.Email, 
								ToName = user.Name, 
								FromEmail = settings.MailerAddress, 
								FromName = settings.ForumTitle, 
								QueueTime = DateTime.UtcNow
			              	};
			_queuedQueuedEmailRepo.CreateMessage(message);
		}
示例#21
0
		private void TestForIndex(Topic topic, string testWord, int increment, int multiplier, bool cap, List<SearchWord> wordList, List<String> junkList)
		{
			testWord = testWord.ToLower();
			if (junkList.IndexOf(testWord) < 0)
			{
				var foundWord = wordList.Find(w => w.Word == testWord);
				if (foundWord != null)
				{
					foundWord.Rank += increment * multiplier;
					// cap the word frequency score
					if (cap && foundWord.Rank > 120) foundWord.Rank = 120;
				}
				else wordList.Add(new SearchWord { Rank = 1, TopicID = topic.TopicID, Word = testWord });
			}
		}
示例#22
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;
		}
示例#23
0
		public void SetAnswer(User user, Topic topic, Post post, string userUrl, string topicUrl)
		{
			if (user.UserID != topic.StartedByUserID)
				throw new SecurityException("Only the user that started a topic may set its answer.");
			if (post == null || post.TopicID != topic.TopicID)
				throw new InvalidOperationException("You can't use a post as an answer unless it's a child of the topic.");
			var answerUser = _userRepository.GetUser(post.UserID);
			if (answerUser != null // answer user is still valid
				&& !topic.AnswerPostID.HasValue && // an answer wasn't already chosen
				topic.StartedByUserID != post.UserID) // the answer isn't coming from the question asker
			{
				// <a href="{0}">{1}</a> chose an answer for the question: <a href="{2}">{3}</a>
				var message = String.Format(Resources.QuestionAnswered, userUrl, user.Name, topicUrl, topic.Title);
				_eventPublisher.ProcessEvent(message, answerUser, EventDefinitionService.StaticEventIDs.QuestionAnswered, false);
			}
			_topicRepository.UpdateAnswerPostID(topic.TopicID, post.PostID);
		}
示例#24
0
		public void UpdateLast(Topic topic)
		{
			var post = _postRepository.GetLastInTopic(topic.TopicID);
			_topicRepository.UpdateLastTimeAndUser(topic.TopicID, post.UserID, post.Name, post.PostTime);
		}
示例#25
0
		public void RecalculateReplyCount(Topic topic)
		{
			var replyCount = _postRepository.GetReplyCount(topic.TopicID, false);
			_topicRepository.UpdateReplyCount(topic.TopicID, replyCount);
		}
示例#26
0
		public void UpdateTitleAndForum(Topic topic, Forum forum, string newTitle, User user)
		{
			if (user.IsInRole(PermanentRoles.Moderator))
			{
				var oldTopic = _topicRepository.Get(topic.TopicID);
				if (oldTopic.ForumID != forum.ForumID)
					_moderationLogService.LogTopic(user, ModerationType.TopicMoved, topic, forum, String.Format("Moved from {0} to {1}", oldTopic.ForumID, forum.ForumID));
				if (oldTopic.Title != newTitle)
					_moderationLogService.LogTopic(user, ModerationType.TopicRenamed, topic, forum, String.Format("Renamed from \"{0}\" to \"{1}\"", oldTopic.Title, newTitle));
				var urlName = newTitle.ToUniqueUrlName(_topicRepository.GetUrlNamesThatStartWith(newTitle.ToUrlName()));
				topic.UrlName = urlName;
				_topicRepository.UpdateTitleAndForum(topic.TopicID, forum.ForumID, newTitle, urlName);
				_topicRepository.MarkTopicForIndexing(topic.TopicID);
				_forumService.UpdateCounts(forum);
				_forumService.UpdateLast(forum);
				var oldForum = _forumService.Get(oldTopic.ForumID);
				_forumService.UpdateCounts(oldForum);
				_forumService.UpdateLast(oldForum);
			}
			else
				throw new InvalidOperationException("User must be Moderator to update topic title or move topic.");
		}
示例#27
0
		public void UndeleteTopic(Topic topic, User user)
		{
			if (user.IsInRole(PermanentRoles.Moderator))
			{
				_moderationLogService.LogTopic(user, ModerationType.TopicUndelete, topic, null);
				_topicRepository.UndeleteTopic(topic.TopicID);
				RecalculateReplyCount(topic);
				var forum = _forumService.Get(topic.ForumID);
				_forumService.UpdateCounts(forum);
				_forumService.UpdateLast(forum);
			}
			else
				throw new InvalidOperationException("User must be Moderator to undelete topic.");
		}
示例#28
0
		public void HardDeleteTopic(Topic topic, User user)
		{
			if (user.IsInRole(PermanentRoles.Admin))
			{
				_moderationLogService.LogTopic(user, ModerationType.TopicDeletePermanently, topic, null);
				_searchRepository.DeleteAllIndexedWordsForTopic(topic.TopicID);
				_topicRepository.HardDeleteTopic(topic.TopicID);
				var forum = _forumService.Get(topic.ForumID);
				_forumService.UpdateCounts(forum);
				_forumService.UpdateLast(forum);
			}
			else
				throw new InvalidOperationException("User must be Admin to hard delete topic.");
		}
示例#29
0
		public void UnpinTopic(Topic topic, User user)
		{
			if (user.IsInRole(PermanentRoles.Moderator))
			{
				_moderationLogService.LogTopic(user, ModerationType.TopicUnpin, topic, null);
				_topicRepository.UnpinTopic(topic.TopicID);
			}
			else
				throw new InvalidOperationException("User must be Moderator to unpin topic.");
		}
示例#30
0
		public void NotifyNewPost(Topic topic, int postID)
		{
			var context = GlobalHost.ConnectionManager.GetHubContext<Topics>();
			context.Clients.Group(topic.TopicID.ToString()).fetchNewPost(postID);
		}
示例#31
0
        public void NotifyNewPost(Topic topic, int postID)
        {
            var context = GlobalHost.ConnectionManager.GetHubContext <Topics>();

            context.Clients.Group(topic.TopicID.ToString()).fetchNewPost(postID);
        }
示例#32
0
		public List<Post> GetPosts(Topic topic, bool includeDeleted)
		{
			return _postRepository.Get(topic.TopicID, includeDeleted);
		}