private async Task <Plato.Follows.Models.Follow> FollowCreated(Plato.Follows.Models.Follow follow) { if (follow == null) { return(null); } // Is this a tag 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; // Persist changes var updatedTopic = await _entityStore.UpdateAsync(existingTopic); if (updatedTopic != null) { // Award reputation for following topic await _reputationAwarder.AwardAsync(Reputations.NewFollow, follow.CreatedUserId, "Followed a topic"); } return(follow); }
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); }
private async Task <Plato.Follows.Models.Follow> FollowDeleted(Plato.Follows.Models.Follow follow) { if (follow == null) { return(null); } // Is this the correct follow type? if (!follow.Name.Equals(FollowTypes.Issue.Name, StringComparison.OrdinalIgnoreCase)) { return(follow); } // Ensure the entity we are following still exists var existingEntity = await _entityStore.GetByIdAsync(follow.ThingId); if (existingEntity == null) { return(follow); } // Update total follows existingEntity.TotalFollows = existingEntity.TotalFollows - 1; // Ensure we don't go negative if (existingEntity.TotalFollows < 0) { existingEntity.TotalFollows = 0; } // Persist changes var updatedEntity = await _entityStore.UpdateAsync(existingEntity); if (updatedEntity != null) { // Revoke reputation for following await _reputationAwarder.RevokeAsync(Reputations.NewFollow, follow.CreatedUserId, "Unfollowed an issue"); } return(follow); }