public override double Calculate(DateTime publishingTimestamp, IStory story) { Check.Argument.IsNotNull(story, "story"); // Give ownerScore if comment is postedby the same user // who actually posted the story // or // Give sameIpScore if comment is submitted form the same ip // or differntIpScore if from different ip ICollection <IComment> comments = _commentRepository.FindAfter(story.Id, story.LastProcessedAt ?? story.CreatedAt); double total = comments.Sum(c => story.IsPostedBy(c.ByUser) ? _ownerWeight : string.CompareOrdinal(c.FromIPAddress, story.FromIPAddress) == 0 ? _sameIpAddressWeight : _differentIPAddressWeight); return(total); }
private void StoryRemoved(IStory theStory, UserAction action) { Check.Argument.IsNotNull(theStory, "theStory"); DateTime expireDate = theStory.CreatedAt.AddHours(_settings.MaximumAgeOfStoryInHoursToPublish); foreach (IMarkAsSpam markAsSpam in theStory.MarkAsSpams) { if (markAsSpam.ByUser.IsPublicUser() && (markAsSpam.MarkedAt <= expireDate)) { markAsSpam.ByUser.DecreaseScoreBy(_userScoreTable.StoryMarkedAsSpam, action); } } foreach (IComment comment in theStory.Comments) { if (comment.ByUser.IsPublicUser() && (comment.CreatedAt <= expireDate)) { comment.ByUser.DecreaseScoreBy(_userScoreTable.StoryCommented, action); } } foreach (IVote vote in theStory.Votes) { if (!theStory.IsPostedBy(vote.ByUser)) { if (vote.ByUser.IsPublicUser() && (vote.PromotedAt <= expireDate)) { decimal score = theStory.IsPublished() ? _userScoreTable.PublishedStoryPromoted : _userScoreTable.UpcomingStoryPromoted; vote.ByUser.DecreaseScoreBy(score, action); } } } if (theStory.PostedBy.IsPublicUser()) { theStory.PostedBy.DecreaseScoreBy(_userScoreTable.StorySubmitted, action); } }