public ActionResult Unmoderated(string subName) { if (string.IsNullOrEmpty(subName)) { throw new NotFoundException(); } var sub = _subDao.GetSubByName(subName); if (sub == null) { throw new NotFoundException(); } var postIds = _postDao.GetUnmoderatedPosts(new List <Guid> { sub.Id }, take: 30); var model = new SubPostsModel(); model.Sub = _subWrapper.Wrap(sub.Id, _userContext.CurrentUser); model.SortBy = PostsSortBy.New; model.Posts = new PagedList <PostWrapped>(_postWrapper.Wrap(postIds, _userContext.CurrentUser), 0, 30, postIds.HasMore); return(View(model)); }
public ActionResult Frontpage(PostsSortBy?sort, PostsTimeFilter?time, int?pageNumber, int?pageSize) { var subs = _contextService.GetSubscribedSubIds(); // if the user is not subscribe to any subs, show the default content. if (subs.Count == 0) { subs = _subDao.GetDefaultSubs(); } if (sort == null) { sort = PostsSortBy.Hot; } if (time == null) { time = PostsTimeFilter.All; } if (pageNumber == null || pageNumber < 1) { pageNumber = 1; } if (pageSize == null) { pageSize = 25; } if (pageSize > 100) { pageSize = 100; } if (pageSize < 1) { pageSize = 1; } var postIds = _postDao.GetPosts(subs, sortby: sort.Value, timeFilter: time.Value, // anonymous users don't see NSFW content. // logged in users only see NSFW if preferences say so. // If they want to see NSFW, they will see all content (SFW/NSFW). nsfw: _userContext.CurrentUser == null ? false : (_userContext.CurrentUser.ShowNsfw ? (bool?)null : false), skip: ((pageNumber - 1) * pageSize), take: pageSize); var model = new SubPostsModel(); model.SortBy = sort.Value; model.TimeFilter = time; if (subs.Any()) // maybe the user hasn't subscribed to any subs? { model.Posts = new PagedList <PostWrapped>(_postWrapper.Wrap(postIds, _userContext.CurrentUser), pageNumber.Value, pageSize.Value, postIds.HasMore); } return(View("Posts", model)); }
public ActionResult Posts(string subName, PostsSortBy?sort, PostsTimeFilter?time, int?pageNumber, int?pageSize) { if (string.IsNullOrEmpty(subName)) { return(Redirect(Url.Subs())); } var model = new SubPostsModel(); var subs = new List <Guid>(); Sub sub = null; if (subName.Equals("all", StringComparison.InvariantCultureIgnoreCase)) { // TODO: Filter only by subs that want to be including in "all". For now, we will do nothing, which will effectively return all posts. model.IsAll = true; } else { // the user wants to view a specific sub sub = _subDao.GetSubByName(subName); if (sub == null) { throw new NotFoundException(); } if (_userContext.CurrentUser != null) { _subActivityDao.MarkSubActive(_userContext.CurrentUser.Id, sub.Id); } subs.Add(sub.Id); } if (sort == null) { sort = PostsSortBy.Hot; // TODO: get default from sub } if (time == null) { time = PostsTimeFilter.All; } if (pageNumber == null || pageNumber < 1) { pageNumber = 1; } if (pageSize == null) { pageSize = 25; } if (pageSize > 100) { pageSize = 100; } if (pageSize < 1) { pageSize = 1; } var postIds = _postDao.GetPosts(subs, sortby: sort.Value, timeFilter: time.Value, onlyAll: model.IsAll, // anonymous users don't see NSFW content. // logged in users only see NSFW if preferences say so. // If they want to see NSFW, they will see all content (SFW/NSFW). nsfw: _userContext.CurrentUser == null ? false : (_userContext.CurrentUser.ShowNsfw ? (bool?)null : false), // we are showing posts for a specific sub, so we can show stickies stickyFirst: sub != null, skip: ((pageNumber - 1) * pageSize), take: pageSize); model.Sub = sub != null?_subWrapper.Wrap(sub.Id, _userContext.CurrentUser) : null; model.SortBy = sort.Value; model.TimeFilter = time; model.Posts = new PagedList <PostWrapped>(_postWrapper.Wrap(postIds, _userContext.CurrentUser), pageNumber.Value, pageSize.Value, postIds.HasMore); return(View(model)); }