示例#1
0
        // GET: comments for a given submission
        public ActionResult Comments(int?id, string subversetoshow, int?startingcommentid, string sort)
        {
            var subverse = _db.Subverses.Find(subversetoshow);

            if (subverse == null)
            {
                return(View("~/Views/Errors/Error_404.cshtml"));
            }

            ViewBag.SelectedSubverse   = subverse.name;
            ViewBag.SubverseAnonymized = subverse.anonymized_mode;

            if (startingcommentid != null)
            {
                ViewBag.StartingCommentId = startingcommentid;
            }

            if (sort != null)
            {
                ViewBag.SortingMode = sort;
            }

            if (id == null)
            {
                return(View("~/Views/Errors/Error.cshtml"));
            }

            var message = _db.Messages.Find(id);

            if (message == null)
            {
                return(View("~/Views/Errors/Error_404.cshtml"));
            }

            // make sure that the combination of selected subverse and message subverse are linked
            if (!message.Subverse.Equals(subversetoshow, StringComparison.OrdinalIgnoreCase))
            {
                return(View("~/Views/Errors/Error_404.cshtml"));
            }

            // experimental
            // register a new session for this subverse
            try
            {
                var currentSubverse = (string)RouteData.Values["subversetoshow"];
                SessionTracker.Add(currentSubverse, Session.SessionID);
            }
            catch (Exception)
            {
                //
            }

            // check if this is a new view and register it
            string clientIpAddress = String.Empty;

            if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                clientIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            }
            else if (Request.UserHostAddress.Length != 0)
            {
                clientIpAddress = Request.UserHostAddress;
            }

            if (clientIpAddress == String.Empty)
            {
                return(View("~/Views/Home/Comments.cshtml", message));
            }

            // generate salted hash of client IP address
            string ipHash = IpHash.CreateHash(clientIpAddress);
            // check if this hash is present for this submission id in viewstatistics table
            var existingView = _db.Viewstatistics.Find(message.Id, ipHash);

            // this IP has already viwed this thread, skip registering a new view
            if (existingView != null)
            {
                return(View("~/Views/Home/Comments.cshtml", message));
            }

            // this is a new view, register it for this submission
            var view = new Viewstatistic {
                submissionId = message.Id, viewerId = ipHash
            };

            _db.Viewstatistics.Add(view);
            message.Views++;
            _db.SaveChanges();

            return(View("~/Views/Home/Comments.cshtml", message));
        }
示例#2
0
        // GET: comments for a given submission
        public ActionResult Comments(int?id, string subversetoshow, int?startingcommentid, string sort, int?commentToHighLight)
        {
            var subverse = SubverseCache.Retrieve(subversetoshow);

            //var subverse = _db.Subverses.Find(subversetoshow);

            if (subverse == null)
            {
                return(View("~/Views/Errors/Error_404.cshtml"));
            }

            //HACK: Disable subverse
            if (subverse.admin_disabled.HasValue && subverse.admin_disabled.Value)
            {
                ViewBag.Subverse = subverse.name;
                return(View("~/Views/Errors/SubverseDisabled.cshtml"));
            }

            ViewBag.SelectedSubverse   = subverse.name;
            ViewBag.SubverseAnonymized = subverse.anonymized_mode;

            //Temp cache user votes for this thread
            ViewBag.VoteCache         = UserVotesBySubmission(id.Value);
            ViewBag.SavedCommentCache = UserSavedCommentsBySubmission(id.Value);

            if (startingcommentid != null)
            {
                ViewBag.StartingCommentId = startingcommentid;
            }

            if (commentToHighLight != null)
            {
                ViewBag.CommentToHighLight = commentToHighLight;
            }

            if (sort != null)
            {
                ViewBag.SortingMode = sort;
            }

            if (id == null)
            {
                return(View("~/Views/Errors/Error.cshtml"));
            }

            var submission = _db.Messages.Find(id);

            if (submission == null)
            {
                return(View("~/Views/Errors/Error_404.cshtml"));
            }

            // make sure that the combination of selected subverse and message subverse are linked
            if (!submission.Subverse.Equals(subversetoshow, StringComparison.OrdinalIgnoreCase))
            {
                return(View("~/Views/Errors/Error_404.cshtml"));
            }

            // experimental: register a new session for this subverse
            string clientIpAddress = String.Empty;

            if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                clientIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            }
            else if (Request.UserHostAddress.Length != 0)
            {
                clientIpAddress = Request.UserHostAddress;
            }

            if (clientIpAddress == String.Empty)
            {
                return(View("~/Views/Home/Comments.cshtml", submission));
            }

            // generate salted hash of client IP address
            string ipHash = IpHash.CreateHash(clientIpAddress);

            var currentSubverse = (string)RouteData.Values["subversetoshow"];

            // register a new session for this subverse
            SessionTracker.Add(currentSubverse, ipHash);

            // register a new view for this thread
            // check if this hash is present for this submission id in viewstatistics table
            var existingView = _db.Viewstatistics.Find(submission.Id, ipHash);

            // this IP has already viwed this thread, skip registering a new view
            if (existingView != null)
            {
                return(View("~/Views/Home/Comments.cshtml", submission));
            }

            // this is a new view, register it for this submission
            var view = new Viewstatistic {
                submissionId = submission.Id, viewerId = ipHash
            };

            _db.Viewstatistics.Add(view);

            submission.Views++;

            _db.SaveChanges();

            return(View("~/Views/Home/Comments.cshtml", submission));
        }
示例#3
0
        // GET: comments for a given submission
        public ActionResult Comments(int?id, string subversetoshow, int?startingcommentid, string sort, int?commentToHighLight)
        {
            #region Validation

            if (id == null)
            {
                return(View("~/Views/Errors/Error.cshtml"));
            }

            var submission = _db.Messages.Find(id.Value);

            if (submission == null)
            {
                return(View("~/Views/Errors/Error_404.cshtml"));
            }

            // make sure that the combination of selected subverse and submission subverse are linked
            if (!submission.Subverse.Equals(subversetoshow, StringComparison.OrdinalIgnoreCase))
            {
                return(View("~/Views/Errors/Error_404.cshtml"));
            }

            var subverse = DataCache.Subverse.Retrieve(subversetoshow);
            //var subverse = _db.Subverse.Find(subversetoshow);

            if (subverse == null)
            {
                return(View("~/Views/Errors/Error_404.cshtml"));
            }

            //HACK: Disable subverse
            if (subverse.admin_disabled.HasValue && subverse.admin_disabled.Value)
            {
                ViewBag.Subverse = subverse.name;
                return(View("~/Views/Errors/SubverseDisabled.cshtml"));
            }

            #endregion

            ViewBag.SelectedSubverse   = subverse.name;
            ViewBag.SubverseAnonymized = subverse.anonymized_mode;

            //Temp cache user votes for this thread
            ViewBag.VoteCache         = UserCommentVotesBySubmission(id.Value);
            ViewBag.SavedCommentCache = UserSavedCommentsBySubmission(id.Value);
            ViewBag.CCP = Karma.CommentKarma(User.Identity.Name);

            if (startingcommentid != null)
            {
                ViewBag.StartingCommentId = startingcommentid;
            }

            if (commentToHighLight != null)
            {
                ViewBag.CommentToHighLight = commentToHighLight;
            }

            var SortingMode = (sort == null ? "top" : sort).ToLower();
            ViewBag.SortingMode = SortingMode;



            // experimental: register a new session for this subverse
            string clientIpAddress = String.Empty;

            if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                clientIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            }
            else if (Request.UserHostAddress.Length != 0)
            {
                clientIpAddress = Request.UserHostAddress;
            }

            if (clientIpAddress != String.Empty)
            {
                // generate salted hash of client IP address
                string ipHash = IpHash.CreateHash(clientIpAddress);

                var currentSubverse = (string)RouteData.Values["subversetoshow"];

                // register a new session for this subverse
                SessionTracker.Add(currentSubverse, ipHash);

                // register a new view for this thread
                // check if this hash is present for this submission id in viewstatistics table
                var existingView = _db.Viewstatistics.Find(submission.Id, ipHash);

                // this IP has already viwed this thread, skip registering a new view
                if (existingView == null)
                {
                    // this is a new view, register it for this submission
                    var view = new Viewstatistic {
                        submissionId = submission.Id, viewerId = ipHash
                    };
                    _db.Viewstatistics.Add(view);

                    submission.Views++;

                    _db.SaveChanges();
                }
            }

            var commentTree = DataCache.CommentTree.Retrieve <usp_CommentTree_Result>(submission.Id, null, null);

            var model = new CommentBucketViewModel()
            {
                StartingIndex = 0,
                EndingIndex   = 5,
                Subverse      = subverse,
                Submission    = submission,
                CommentTree   = commentTree,
                //DisplayTree = displayTree,
                ParentID = null,
                Sort     = (CommentSort)Enum.Parse(typeof(CommentSort), SortingMode, true)
            };

            IQueryable <usp_CommentTree_Result> displayTree = commentTree.AsQueryable().Where(x => x.ParentId == null);
            model.TotalInDisplayBranch = displayTree.Count();

            if (model.Sort == CommentSort.Top)
            {
                displayTree = displayTree.OrderByDescending(x => x.Likes - x.Dislikes).Take(model.EndingIndex);
            }
            else
            {
                displayTree = displayTree.OrderByDescending(x => x.Date).Take(model.EndingIndex);
            }
            model.DisplayTree = displayTree;


            return(View("~/Views/Home/Comments.cshtml", model));
        }