示例#1
0
        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));
        }
示例#2
0
        public IViewComponentResult Invoke(string subName, Guid?subId, bool showSearch, bool showCreateSub, bool showSubmit)
        {
            var model = new SidebarViewModel();

            model.ShowSearch    = showSearch;
            model.ShowCreateSub = showCreateSub;
            model.ShowSubmit    = showSubmit;

            var currentUser = _userContext.CurrentUser;

            if (subId.HasValue)
            {
                model.CurrentSub = _subWrapper.Wrap(_subDao.GetSubById(subId.Value), _userContext.CurrentUser);
            }
            else if (!string.IsNullOrEmpty(subName))
            {
                model.CurrentSub = _subWrapper.Wrap(_subDao.GetSubByName(subName), _userContext.CurrentUser);
            }

            if (model.CurrentSub != null)
            {
                if (_userContext.CurrentUser != null)
                {
                    model.Permissions = _moderationDao.GetUserPermissionsForSub(_userContext.CurrentUser, model.CurrentSub.Sub.Id);
                }

                if (!model.IsModerator)
                {
                    // we only show list of mods if the requesting user is not a mod of this sub
                    model.Moderators = _membershipDao.GetUsersByIds(_moderationDao.GetAllModsForSub(model.CurrentSub.Sub.Id).Select(x => x.UserId).ToList());
                }

                // get the number of active users currently viewing this sub.
                // for normal users, this number may be fuzzed (if low enough) for privacy reasons.
                if (_userContext.CurrentUser != null && _userContext.CurrentUser.IsAdmin)
                {
                    model.NumberOfActiveUsers = _subActivityDao.GetActiveNumberOfUsersForSub(model.CurrentSub.Sub.Id);
                }
                else
                {
                    bool wasFuzzed;
                    model.NumberOfActiveUsers         = _subActivityDao.GetActiveNumberOfUsersForSubFuzzed(model.CurrentSub.Sub.Id, out wasFuzzed);
                    model.IsNumberOfActiveUsersFuzzed = wasFuzzed;
                }
            }

            if (model.ShowCreateSub)
            {
                if (currentUser != null)
                {
                    var age = Common.CurrentTime() - currentUser.CreatedDate;
                    if (currentUser.IsAdmin || age.TotalDays >= _subSettings.Settings.MinUserAgeCreateSub)
                    {
                        model.CanCreateSub = true;
                    }
                }
            }

            return(View(model));
        }
示例#3
0
        public ActionResult Popular(string query, int?pageNumber, int?pageSize)
        {
            ViewBag.NavigationKey = "popular";

            ViewBag.Query = query;

            if (pageNumber == null || pageNumber < 1)
            {
                pageNumber = 1;
            }

            if (pageSize == null)
            {
                pageSize = 24;
            }

            if (pageSize > 100)
            {
                pageSize = 100;
            }

            if (pageSize < 1)
            {
                pageSize = 1;
            }

            var subs = _subDao.GetAllSubs(query,
                                          sortBy: SubsSortBy.Subscribers,
                                          nsfw: _userContext.CurrentNsfw,
                                          skip: ((pageNumber - 1) * pageSize),
                                          take: pageSize);

            return(View("List", new PagedList <SubWrapped>(_subwrapper.Wrap(subs, _userContext.CurrentUser), pageNumber.Value, pageSize.Value, subs.HasMore)));
        }