コード例 #1
0
        public static void HydrateUserData(IPrincipal user, IEnumerable <Domain.Models.Comment> comments)
        {
            if (user.Identity.IsAuthenticated && (comments != null && comments.Any()))
            {
                string userName = user.Identity.Name;
                if (!String.IsNullOrEmpty(userName))
                {
                    using (var repo = new Repository())
                    {
                        var votes        = repo.UserVoteStatus(userName, ContentType.Comment, comments.Select(x => x.ID).ToArray());
                        var q            = new QueryUserBlocks();
                        var blockedUsers = q.Execute().Where(x => x.Type == DomainType.User);

                        foreach (var comment in comments)
                        {
                            HydrateUserData(user, comment, false, votes, blockedUsers);
                            //comment.IsOwner = comment.UserName == userName;
                            //var voteValue = votes.FirstOrDefault(x => x.ID == comment.ID);
                            //comment.Vote = (voteValue == null ? 0 : voteValue.Value);
                            //comment.IsSaved = UserHelper.IsSaved(ContentType.Comment, comment.ID);
                            //Protect(comment);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: MesssagingUtility.cs プロジェクト: nevergofull/A
        public static bool IsSenderBlocked(string sender, string recipient)
        {
            var q      = new QueryUserBlocks(recipient);
            var blocks = q.Execute();

            if (blocks != null)
            {
                return(blocks.Any(x => x.Type == DomainType.User && x.Name.Equals(sender, StringComparison.OrdinalIgnoreCase)));
            }
            return(false);
        }
コード例 #3
0
        public static bool IsSenderBlocked(string sender, string recipient)
        {
            var q      = new QueryUserBlocks(recipient);
            var blocks = q.Execute();

            if (blocks != null)
            {
                return(blocks.Any(x => x.Type == DomainType.User && x.Name.ToLower() == sender.ToLower()));
            }
            return(false);
        }
コード例 #4
0
        public async Task <ViewResult> Blocked(Domain.Models.DomainType blockType, int?page)
        {
            switch (blockType)
            {
            case Domain.Models.DomainType.User:
                var q      = new QueryUserBlocks();
                var blocks = await q.ExecuteAsync();

                var userBlocks = blocks.Where(x => x.Type == Domain.Models.DomainType.User).OrderBy(x => x.Name);

                return(View("BlockedUsers", userBlocks));

                break;

            case Domain.Models.DomainType.Subverse:
            default:

                //Original Code below, leaving as is bc it works
                ViewBag.SelectedSubverse = "subverses";
                ViewBag.SubversesView    = "blocked";
                const int pageSize   = 25;
                int       pageNumber = (page ?? 0);

                if (pageNumber < 0)
                {
                    return(NotFoundErrorView());
                }
                string userName = User.Identity.Name;
                // get a list of user blocked subverses with details and order by subverse name, ascending
                IQueryable <SubverseDetailsViewModel> blockedSubverses = from c in _db.Subverses
                                                                         join a in _db.UserBlockedSubverses
                                                                         on c.Name equals a.Subverse
                                                                         where a.UserName.Equals(userName)
                                                                         orderby a.Subverse ascending
                                                                         select new SubverseDetailsViewModel
                {
                    Name          = c.Name,
                    Title         = c.Title,
                    Description   = c.Description,
                    Creation_date = c.CreationDate,
                    Subscribers   = c.SubscriberCount
                };

                var paginatedBlockedSubverses = new PaginatedList <SubverseDetailsViewModel>(blockedSubverses, page ?? 0, pageSize);

                return(View("BlockedSubverses", paginatedBlockedSubverses));

                break;
            }
        }
コード例 #5
0
ファイル: SetTests.cs プロジェクト: vrijdagweekend/voat
        public async Task Block_Lifecycle_Tests()
        {
            var userName = "******";
            var subName  = SUBVERSES.Unit;

            TestDataInitializer.CreateUser(userName);
            var user = TestHelper.SetPrincipal(userName);

            //Verify No Front / Blocked Sets
            var userBlockQuery   = new QueryUserBlocks(userName).SetUserContext(user);
            var userBlockResults = await userBlockQuery.ExecuteAsync();

            Assert.IsNotNull(userBlockResults, "Old McDonald had a farm ee i ee i o. And on that farm he shot some guys. Badda boom badda bing bang boom.");
            Assert.AreEqual(0, userBlockResults.Count(), "He is supposed to be Turkish. Some say his father was German. Nobody believed he was real.");

            var userSetQuery   = new QueryUserSets(userName).SetUserContext(user);
            var userSetResults = await userSetQuery.ExecuteAsync();

            Assert.IsNotNull(userSetResults, "One cannot be betrayed if one has no people.");
            Assert.AreEqual(0, userSetResults.Count(), "A man can convince anyone he's somebody else, but never himself.");

            var currentSubscriberCount = 0;

            using (var db = new VoatDataContext())
            {
                var count = db.Subverse.First(x => x.Name == subName).SubscriberCount;
                currentSubscriberCount = count.HasValue ? count.Value : 0;
            }

            //Sub a user to front
            var domainReference = new DomainReference(DomainType.Subverse, subName);
            var blockCmd        = new BlockCommand(domainReference.Type, domainReference.Name, true).SetUserContext(user);
            var blockResult     = await blockCmd.Execute();

            //Verify Front is created
            userBlockQuery   = new QueryUserBlocks(userName).SetUserContext(user);
            userBlockResults = await userBlockQuery.ExecuteAsync();

            Assert.IsNotNull(userBlockResults, "What about it, pretzel man? What's your story?");
            Assert.AreEqual(1, userBlockResults.Count(), "First day on the job, you know what I learned? How to spot a murderer.");
            Assert.IsTrue(userBlockResults.Any(x => x.Type == DomainType.Subverse && x.Name == subName), "It was Keyser Soze, Agent Kujan. I mean the Devil himself. How do you shoot the Devil in the back? What if you miss?");

            userSetQuery   = new QueryUserSets(userName).SetUserContext(user);
            userSetResults = await userSetQuery.ExecuteAsync();

            Assert.IsNotNull(userSetResults, "What the cops never figured out, and what I know now, was that these men would never break, never lie down, never bend over for anybody");
            Assert.AreEqual(1, userSetResults.Count(x => x.Type == SetType.Blocked), "Is it Friday already? ");
            var set = userSetResults.First(x => x.Type == SetType.Blocked);

            Assert.AreEqual(SetType.Blocked, set.Type, "I got a whole new problem when I post bail.");
            Assert.AreEqual(1, set.SubscriberCount, "I got a whole new problem when I post bail.");

            //Ensure Subverse Subscriber Count Updated
            using (var db = new VoatDataContext())
            {
                var tc    = db.Subverse.First(x => x.Name == subName).SubscriberCount;
                var count = tc.HasValue ? tc.Value : 0;
                Assert.AreEqual(currentSubscriberCount, count, "");
                currentSubscriberCount = count;
            }

            //verify FRONT set has sub
            using (var repo = new Voat.Data.Repository())
            {
                var setList = await repo.GetSetListDescription(SetType.Blocked.ToString(), userName);

                Assert.IsTrue(setList.Any(x => x.Name == subName));
            }

            //Unsubscribe
            blockCmd    = new BlockCommand(domainReference.Type, domainReference.Name, true).SetUserContext(user);
            blockResult = await blockCmd.Execute();

            VoatAssert.IsValid(blockResult);

            //Ensure Subverse Subscriber Count Updated
            using (var db = new VoatDataContext())
            {
                var count = db.Subverse.First(x => x.Name == subName).SubscriberCount;
                Assert.AreEqual(currentSubscriberCount, count.HasValue ? count.Value : 0, "");
            }

            //verify FRONT set has not sub
            using (var repo = new Voat.Data.Repository())
            {
                var setList = await repo.GetSetListDescription(SetType.Blocked.ToString(), userName);

                Assert.IsFalse(setList.Any(x => x.Name == subName));
            }
        }
コード例 #6
0
        protected async Task <CommentSegment> GetSegment(bool addChildren)
        {
            QueryCommentTree q = new QueryCommentTree(_submissionID);

            if (!String.IsNullOrEmpty(UserName))
            {
                //var p = new QueryUserData(UserName).Execute();
                //var preference = p.Preferences;
                var qvotes = new QueryUserCommentVotesForSubmission(_submissionID, CachePolicy.None).SetUserContext(User);
                _commentVotes = await qvotes.ExecuteAsync();

                var qblocks = new QueryUserBlocks().SetUserContext(User);
                _userBlocks = (await qblocks.ExecuteAsync()).Where(x => x.Type == DomainType.User);
                //_commentSaves = new QueryUserSavedCommentsForSubmission(_submissionID).Execute();
            }

            //TODO: Set with preferences

            int nestLevel = 3;

            //TODO: set IsCollapsed flag in output on every comment below this threshold

            fullTree = (await q.ExecuteAsync()).Values;
            switch (_sort)
            {
            case CommentSortAlgorithm.Intensity:
                fullTree = fullTree.OrderByDescending(x => Math.Max(1, (x.UpCount + x.DownCount)) ^ (Math.Min(x.UpCount, x.DownCount) / Math.Max(1, Math.Max(x.UpCount, x.DownCount))));
                break;

            case CommentSortAlgorithm.New:
                fullTree = fullTree.OrderByDescending(x => x.CreationDate);
                break;

            case CommentSortAlgorithm.Old:
                fullTree = fullTree.OrderBy(x => x.CreationDate);
                break;

            case CommentSortAlgorithm.Bottom:
                fullTree = fullTree.OrderBy(x => x.UpCount - x.DownCount).ThenByDescending(x => x.CreationDate);
                break;

            default:

                //top
                fullTree = fullTree.OrderByDescending(x => x.UpCount - x.DownCount).ThenByDescending(x => x.CreationDate);
                break;
            }

            var queryTree = fullTree.AsQueryable();

            queryTree = FilterSegment(queryTree);
            var queryableTree = TakeSegment(queryTree);

            //creating this to keep local vars in scope
            Func <usp_CommentTree_Result, NestedComment> mapToNestedCommentFunc = new Func <usp_CommentTree_Result, NestedComment>(commentTree =>
            {
                return(commentTree.Map(User, SubmitterName, _commentVotes, _userBlocks));
            });

            List <NestedComment> comments = new List <NestedComment>();

            foreach (var c in queryableTree)
            {
                var n = mapToNestedCommentFunc(c);
                if (!n.IsCollapsed)
                {
                    n.IsCollapsed = (n.Sum <= _collapseThreshold);
                }
                if (addChildren)
                {
                    AddComments(fullTree, n, _count, nestLevel, 1, _collapseThreshold, _sort, mapToNestedCommentFunc);
                }

                //having small issue with comments load links for deleted children, see if this clears up
                n.ChildCount          = fullTree.Count(x => x.ParentID == n.ID && !(x.IsDeleted && x.ChildCount == 0));
                n.Children.TotalCount = n.ChildCount;
                comments.Add(n);
            }

            var segment = new Domain.Models.CommentSegment();

            segment.Sort          = _sort;
            segment.StartingIndex = 0;
            segment.TotalCount    = queryTree.Count();
            if (comments.Any())
            {
                segment.Comments = comments;
                int segmentCount = segment.Comments.Count();
            }

            return(segment);
        }
コード例 #7
0
        public async Task <ActionResult> Blocked(Domain.Models.DomainType blockType, int?page)
        {
            switch (blockType)
            {
            case Domain.Models.DomainType.User:
                var q      = new QueryUserBlocks().SetUserContext(User);
                var blocks = await q.ExecuteAsync();

                var userBlocks = blocks.Where(x => x.Type == Domain.Models.DomainType.User).OrderBy(x => x.Name);

                var originalUserName = User.Identity.Name;
                ViewBag.NavigationViewModel = new NavigationViewModel()
                {
                    MenuType    = MenuType.UserProfile,
                    Name        = originalUserName,
                    BasePath    = "/user/" + originalUserName,
                    Description = originalUserName + "'s Blocked Users",
                };

                return(View("BlockedUsers", userBlocks));

                break;

            case Domain.Models.DomainType.Subverse:
            default:

                var domainReference = new Domain.Models.DomainReference(Domain.Models.DomainType.Set, Domain.Models.SetType.Blocked.ToString(), User.Identity.Name);
                return(RedirectToAction("Details", "Set", new { name = domainReference.FullName }));

                ////Original Code below, leaving as is bc it works
                //ViewBag.SelectedSubverse = "subverses";
                //ViewBag.SubversesView = "blocked";
                //const int pageSize = 25;
                //int pageNumber = (page ?? 0);

                //if (pageNumber < 0)
                //{
                //    return ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound));
                //}
                //string userName = User.Identity.Name;
                //// get a list of user blocked subverses with details and order by subverse name, ascending
                //IQueryable<SubverseDetailsViewModel> blockedSubverses = from c in _db.Subverses
                //                                                        join a in _db.UserBlockedSubverses
                //                                                        on c.Name equals a.Subverse
                //                                                        where a.UserName.Equals(userName)
                //                                                        orderby a.Subverse ascending
                //                                                        select new SubverseDetailsViewModel
                //                                                        {
                //                                                            Name = c.Name,
                //                                                            Title = c.Title,
                //                                                            Description = c.Description,
                //                                                            CreationDate = c.CreationDate,
                //                                                            Subscribers = c.SubscriberCount
                //                                                        };

                //var paginatedBlockedSubverses = new PaginatedList<SubverseDetailsViewModel>(blockedSubverses, page ?? 0, pageSize);

                //return View("BlockedSubverses", paginatedBlockedSubverses);

                break;
            }
        }