public ViewResult Topics(int page = 1) { var user = this.CurrentUser(); if (user == null) return View(); PagerContext pagerContext; var topics = _subService.GetTopics(user, page, out pagerContext); var titles = _forumService.GetAllForumTitles(); var container = new PagedTopicContainer { PagerContext = pagerContext, Topics = topics, ForumTitles = titles }; _lastReadService.GetTopicReadStatus(user, container); return View(container); }
public ViewResult Result(string query, SearchType searchType = SearchType.Rank, int page = 1) { ViewBag.SearchTypes = new SelectList(Enum.GetValues(typeof(SearchType))); ViewBag.Query = query; ViewBag.SearchType = searchType; var includeDeleted = false; var user = this.CurrentUser(); if (user != null && user.IsInRole(PermanentRoles.Moderator)) includeDeleted = true; var titles = _forumService.GetAllForumTitles(); PagerContext pagerContext; var topics = _searchService.GetTopics(query, searchType, user, includeDeleted, page, out pagerContext); var container = new PagedTopicContainer { ForumTitles = titles, PagerContext = pagerContext, Topics = topics }; _lastReadService.GetTopicReadStatus(user, container); return View("Index", container); }
public void GetTopicReadStatus(User user, PagedTopicContainer container) { Dictionary<int, DateTime> lastForumReads = null; Dictionary<int, DateTime> lastTopicReads = null; if (user != null) { lastForumReads = _lastReadRepository.GetLastReadTimesForForums(user.UserID); lastTopicReads = _lastReadRepository.GetLastReadTimesForTopics(user.UserID, container.Topics.Select(t => t.TopicID)); } foreach (var topic in container.Topics) { var status = new ReadStatus(); if (topic.IsClosed) status |= ReadStatus.Closed; else status |= ReadStatus.Open; if (topic.IsPinned) status |= ReadStatus.Pinned; else status |= ReadStatus.NotPinned; if (lastForumReads == null) status |= ReadStatus.NoNewPosts; else { var lastRead = DateTime.MinValue; if (lastForumReads.ContainsKey(topic.ForumID)) lastRead = lastForumReads[topic.ForumID]; if (lastTopicReads.ContainsKey(topic.TopicID) && lastTopicReads[topic.TopicID] > lastRead) lastRead = lastTopicReads[topic.TopicID]; if (topic.LastPostTime > lastRead) status |= ReadStatus.NewPosts; else status |= ReadStatus.NoNewPosts; } container.ReadStatusLookup.Add(topic.TopicID, status); } }
public ViewResult Index() { var container = new PagedTopicContainer {PagerContext = new PagerContext { PageCount = 0, PageIndex = 1 }, Topics = new List<Topic>() }; ViewBag.SearchTypes = new SelectList(Enum.GetValues(typeof (SearchType))); return View(container); }
public void TopicReadStatusWithUserClosedNoNewNotPinned() { var service = GetService(); var container = new PagedTopicContainer(); container.Topics = new List<Topic> { new Topic(1) { ForumID = 2, IsClosed = true, LastPostTime = new DateTime(2000, 1, 1, 5, 0, 0) } }; var user = new User(123, DateTime.MinValue); _lastReadRepo.Setup(l => l.GetLastReadTimesForForums(user.UserID)).Returns(new Dictionary<int, DateTime> { { 2, new DateTime(2000, 1, 1, 7, 0, 0) } }); _lastReadRepo.Setup(l => l.GetLastReadTimesForTopics(user.UserID, new[] { 1 })).Returns(new Dictionary<int, DateTime>()); service.GetTopicReadStatus(user, container); Assert.AreEqual(ReadStatus.NoNewPosts | ReadStatus.Closed | ReadStatus.NotPinned, container.ReadStatusLookup[1]); }
public void TopicReadStatusForNoUser() { var service = GetService(); var container = new PagedTopicContainer(); container.Topics = new List<Topic> {new Topic(1), new Topic(2) {IsClosed = true}, new Topic(3) {IsPinned = true}}; service.GetTopicReadStatus(null, container); Assert.AreEqual(3, container.ReadStatusLookup.Count); Assert.AreEqual(ReadStatus.NoNewPosts | ReadStatus.Open | ReadStatus.NotPinned, container.ReadStatusLookup[1]); Assert.AreEqual(ReadStatus.NoNewPosts | ReadStatus.Closed | ReadStatus.NotPinned, container.ReadStatusLookup[2]); Assert.AreEqual(ReadStatus.NoNewPosts | ReadStatus.Open | ReadStatus.Pinned, container.ReadStatusLookup[3]); }
public ViewResult Recent(int page = 1) { var includeDeleted = false; var user = this.CurrentUser(); if (user != null && user.IsInRole(PermanentRoles.Moderator)) includeDeleted = true; var titles = _forumService.GetAllForumTitles(); PagerContext pagerContext; var topics = _forumService.GetRecentTopics(user, includeDeleted, page, out pagerContext); var container = new PagedTopicContainer { ForumTitles = titles, PagerContext = pagerContext, Topics = topics }; _lastReadService.GetTopicReadStatus(user, container); return View(container); }
public ViewResult Posts(int id, int page = 1) { var postUser = _userService.GetUser(id); if (postUser == null) return this.NotFound("NotFound", null); var includeDeleted = false; var user = this.CurrentUser(); if (user != null && user.IsInRole(PermanentRoles.Moderator)) includeDeleted = true; var titles = _forumService.GetAllForumTitles(); PagerContext pagerContext; var topics = _topicService.GetTopics(user, postUser, includeDeleted, page, out pagerContext); var container = new PagedTopicContainer { ForumTitles = titles, PagerContext = pagerContext, Topics = topics }; _lastReadService.GetTopicReadStatus(user, container); ViewBag.PostUserName = postUser.Name; return View(container); }
public static MvcHtmlString TopicReadIndicator(this HtmlHelper helper, Topic topic, PagedTopicContainer container, string path, string cssClass) { var alt = Resources.NoNewPosts; var image = "NoNewIndicator.png"; if (container.ReadStatusLookup.ContainsKey(topic.TopicID)) { var status = container.ReadStatusLookup[topic.TopicID]; switch (status) { case ReadStatus.Open | ReadStatus.NewPosts | ReadStatus.Pinned: image = "NewPinnedIndicator.png"; alt = Resources.NewPostsPinned; break; case ReadStatus.Open | ReadStatus.NewPosts | ReadStatus.NotPinned: image = "NewIndicator.png"; alt = Resources.NewPosts; break; case ReadStatus.Open | ReadStatus.NoNewPosts | ReadStatus.Pinned: image = "PinnedIndicator.png"; alt = Resources.Pinned; break; case ReadStatus.Open | ReadStatus.NoNewPosts | ReadStatus.NotPinned: image = "NoNewIndicator.png"; alt = Resources.NoNewPosts; break; case ReadStatus.Closed | ReadStatus.NewPosts | ReadStatus.Pinned: image = "NewClosedPinnedIndicator.png"; alt = Resources.NewPostsClosedPinned; break; case ReadStatus.Closed | ReadStatus.NewPosts | ReadStatus.NotPinned: image = "NewClosedIndicator.png"; alt = Resources.NewPostsClosed; break; case ReadStatus.Closed | ReadStatus.NoNewPosts | ReadStatus.Pinned: image = "ClosedPinnedIndicator.png"; alt = Resources.ClosedPinned; break; case ReadStatus.Closed | ReadStatus.NoNewPosts | ReadStatus.NotPinned: image = "ClosedIndicator.png"; alt = Resources.Closed; break; default: break; } } var build = new StringBuilder(); build.Append("<img src=\""); build.Append(path); build.Append(image); build.Append("\" alt=\""); build.Append(alt); build.Append("\""); if (!String.IsNullOrEmpty(cssClass)) { build.Append(" class=\""); build.Append(cssClass); build.Append("\""); } build.Append(" />"); return MvcHtmlString.Create(build.ToString()); }
public static MvcHtmlString TopicReadIndicator(this HtmlHelper helper, Topic topic, PagedTopicContainer container, string path) { return TopicReadIndicator(helper, topic, container, path, null); }
public static bool IsNewPosts(this HtmlHelper helper, Topic topic, PagedTopicContainer container) { if (!container.ReadStatusLookup.ContainsKey(topic.TopicID)) return false; if (container.ReadStatusLookup[topic.TopicID] == (ReadStatus.NewPosts | container.ReadStatusLookup[topic.TopicID])) return true; return false; }