Ejemplo n.º 1
0
        private async Task <Follows.Models.Follow> FollowDeleted(Follows.Models.Follow follow)
        {
            if (follow == null)
            {
                return(null);
            }

            // Is this a user follow?
            if (!follow.Name.Equals(FollowTypes.User.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(follow);
            }


            // Get the user we are following
            var user = await _platoUserStore.GetByIdAsync(follow.ThingId);

            if (user == null)
            {
                return(follow);
            }

            // Revoke follow reputation to the user following another user
            await _reputationAwarder.RevokeAsync(Reputations.NewFollow, follow.CreatedUserId, $"Unfollowed user \"{user.DisplayName}");

            // Revoke follower reputation for the user the current user is following
            await _reputationAwarder.RevokeAsync(Reputations.NewFollower, follow.ThingId, $"{follow.CreatedBy.DisplayName} stopped following me");

            return(follow);
        }
Ejemplo n.º 2
0
        async Task <TEntityReply> EntityReplyDeleted(TEntityReply reply)
        {
            if (reply == null)
            {
                throw new ArgumentNullException(nameof(reply));
            }

            if (reply.IsHidden)
            {
                return(reply);
            }

            if (reply.IsDeleted)
            {
                return(reply);
            }

            if (reply.IsSpam)
            {
                return(reply);
            }

            // Revoke awarded reputation
            if (reply.CreatedUserId > 0)
            {
                await _reputationAwarder.RevokeAsync(Reputations.NewComment, reply.CreatedUserId,
                                                     "Comment deleted or hidden");
            }

            // Return reply
            return(reply);
        }
Ejemplo n.º 3
0
        async Task <TEntity> EntityUpdating(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            // Get existing entity before any changes
            var existingEntity = await _entityRepository.SelectByIdAsync(entity.Id);

            // We need an existing entity
            if (existingEntity == null)
            {
                return(entity);
            }

            // Entity has been hidden
            if (entity.IsHidden())
            {
                // If the existing entity was not already hidden revoke reputation
                if (!existingEntity.IsHidden())
                {
                    if (entity.CreatedUserId > 0)
                    {
                        await _reputationAwarder.RevokeAsync(Reputations.NewArticle, entity.CreatedUserId,
                                                             "Article deleted or hidden");
                    }
                }
            }
            else
            {
                // If the existing entity was already hidden award reputation
                if (existingEntity.IsHidden())
                {
                    if (entity.CreatedUserId > 0)
                    {
                        await _reputationAwarder.AwardAsync(Reputations.NewArticle, entity.CreatedUserId,
                                                            "Article approved or made visible");
                    }
                }
            }

            // Return
            return(entity);
        }
Ejemplo n.º 4
0
        private async Task <Stars.Models.Star> StarDeleted(Stars.Models.Star star)
        {
            if (star == null)
            {
                return(null);
            }

            // Is this a article star?
            if (!star.Name.Equals(StarTypes.Article.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(star);
            }

            // Ensure the entity we are starring exists
            var entity = await _entityStore.GetByIdAsync(star.ThingId);

            if (entity == null)
            {
                return(star);
            }

            // Update total stars
            entity.TotalStars = entity.TotalStars - 1;

            // Ensure we don't go negative
            if (entity.TotalStars < 0)
            {
                entity.TotalStars = 0;
            }

            // Persist changes
            var updatedEntity = await _entityStore.UpdateAsync(entity);

            if (updatedEntity != null)
            {
                // Revoke reputation from user removing the entity star
                await _reputationAwarder.RevokeAsync(Reputations.StarArticle, star.CreatedUserId, "Unstarred an article");

                // Revoke reputation from entity author for user removing there entity star
                await _reputationAwarder.RevokeAsync(Reputations.StarredArticle, entity.CreatedUserId, "A user unstarred my article");
            }

            return(star);
        }
Ejemplo n.º 5
0
        async Task <TEntity> EntityDeleted(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (entity.IsHidden())
            {
                return(entity);
            }

            // Revoke awarded reputation
            if (entity.CreatedUserId > 0)
            {
                await _reputationAwarder.RevokeAsync(Reputations.NewArticle, entity.CreatedUserId,
                                                     "Article deleted or hidden");
            }

            return(entity);
        }
Ejemplo n.º 6
0
        private async Task <Plato.Follows.Models.Follow> FollowDeleted(Plato.Follows.Models.Follow follow)
        {
            if (follow == null)
            {
                return(null);
            }

            // Is this a discuss label follow?
            if (!follow.Name.Equals(FollowTypes.Category.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(follow);
            }

            // Revoke reputation for following tag
            await _reputationAwarder.RevokeAsync(Reputations.NewFollow, follow.CreatedUserId, "Unfollowed a discuss category");

            return(follow);
        }
Ejemplo n.º 7
0
        //async Task<TEntity> EntityUpdated(TEntity entity)
        //{

        //    // We always need a contributor to add
        //    if (entity.ModifiedUserId <= 0)
        //    {
        //        return entity;
        //    }

        //    // Get entity details to update
        //    var details = entity.GetOrCreate<DocDetails>();

        //    // Get user modifying entity
        //    var user = await _platoUserStore.GetByIdAsync(entity.ModifiedUserId);

        //    // We always need a contributor to add
        //    if (user == null)
        //    {
        //        return entity;
        //    }

        //    // No need to add the contributor more than once
        //    var exists = false;
        //    foreach (var contributor in details.Contributors)
        //    {
        //        if (contributor.Id == user.Id)
        //        {
        //            exists = true;
        //            contributor.Contributions.Add(new Contribution(DateTimeOffset.UtcNow));
        //        }
        //    }

        //    if (!exists)
        //    {
        //        // Add our contributor
        //        details.Contributors.Add(new EntityContributor(user)
        //        {
        //            Contributions = new List<Contribution>()
        //            {
        //                new Contribution(DateTimeOffset.UtcNow)
        //            }
        //        });
        //    }

        //    // Add updated data to entity
        //    entity.AddOrUpdate<DocDetails>(details);

        //    // Persist the updates
        //    return await _entityStore.UpdateAsync(entity);

        //}

        // ------------

        async Task <TEntity> BuildSortOrderAsync(TEntity entity)
        {
            // Get existing entity before any changes
            var existingEntity = await _entityRepository.SelectByIdAsync(entity.Id);

            // We need an existing entity
            if (existingEntity == null)
            {
                return(entity);
            }

            // Entity has been hidden
            if (entity.IsHidden())
            {
                // If the existing entity was not already hidden revoke reputation
                if (!existingEntity.IsHidden())
                {
                    if (entity.CreatedUserId > 0)
                    {
                        await _reputationAwarder.RevokeAsync(Reputations.NewTopic, entity.CreatedUserId, "Topic deleted or hidden");
                    }
                }
            }
            else
            {
                // If the existing entity was already hidden award reputation
                if (existingEntity.IsHidden())
                {
                    if (entity.CreatedUserId > 0)
                    {
                        await _reputationAwarder.AwardAsync(Reputations.NewTopic, entity.CreatedUserId, "Topic approved or made visible");
                    }
                }
            }

            // If the parent changes ensure we update the sort order
            if (entity.ParentId != existingEntity.ParentId)
            {
                entity.SortOrder = await GetNextAvailableSortOrder(entity);
            }

            return(entity);
        }
Ejemplo n.º 8
0
        private async Task <Follows.Models.Follow> FollowDeleted(Follows.Models.Follow follow)
        {
            if (follow == null)
            {
                return(null);
            }

            // Is this a discuss label follow?
            if (!follow.Name.Equals(FollowTypes.Label.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(follow);
            }

            // Get the label we are following
            var label = await _labelStore.GetByIdAsync(follow.ThingId);

            if (label == null)
            {
                return(follow);
            }

            // Update follow count
            label.TotalFollows = label.TotalFollows - 1;

            // Ensure we don't go negative
            if (label.TotalFollows < 0)
            {
                label.TotalFollows = 0;
            }

            // Persist changes
            var updatedLabel = await _labelStore.UpdateAsync(label);

            if (updatedLabel != null)
            {
                // Revoke reputation for following tag
                await _reputationAwarder.RevokeAsync(Reputations.NewFollow, follow.CreatedUserId, $"Unfollowed label \"{label.Name}\"");
            }

            return(follow);
        }
Ejemplo n.º 9
0
        private async Task <Plato.Follows.Models.Follow> FollowDeleted(Plato.Follows.Models.Follow follow)
        {
            if (follow == null)
            {
                return(null);
            }

            // Is this a topic follow?
            if (!follow.Name.Equals(FollowTypes.Topic.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(follow);
            }

            // Ensure the topic we are following still exists
            var existingTopic = await _entityStore.GetByIdAsync(follow.ThingId);

            if (existingTopic == null)
            {
                return(follow);
            }

            // Update total follows
            existingTopic.TotalFollows = existingTopic.TotalFollows - 1;

            // Ensure we don't go negative
            if (existingTopic.TotalFollows < 0)
            {
                existingTopic.TotalFollows = 0;
            }

            // Persist changes
            var updatedTopic = await _entityStore.UpdateAsync(existingTopic);

            if (updatedTopic != null)
            {
                // Revoke reputation for following tag
                await _reputationAwarder.RevokeAsync(Reputations.NewFollow, follow.CreatedUserId, "Unfollowed a topic");
            }

            return(follow);
        }
Ejemplo n.º 10
0
        private async Task <Follows.Models.Follow> FollowDeleted(Follows.Models.Follow follow)
        {
            if (follow == null)
            {
                return(null);
            }

            // Is this a tag follow?
            if (!follow.Name.Equals(FollowTypes.Tag.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(follow);
            }

            // Ensure the tag we are following still exists
            var tag = await _tagStore.GetByIdAsync(follow.ThingId);

            if (tag == null)
            {
                return(follow);
            }

            // Update total follows
            tag.TotalFollows = tag.TotalFollows - 1;

            // Ensure we don't go negative
            if (tag.TotalFollows < 0)
            {
                tag.TotalFollows = 0;
            }

            // Persist changes
            var updatedTag = await _tagStore.UpdateAsync(tag);

            if (updatedTag != null)
            {
                // Revoke reputation for following tag
                await _reputationAwarder.RevokeAsync(Reputations.NewFollow, follow.CreatedUserId, $"Unfollowed tag \"{tag.Name}\"");
            }

            return(follow);
        }