예제 #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);
        }
예제 #2
0
        private async Task <Follows.Models.Follow> FollowCreated(Follows.Models.Follow follow)
        {
            if (follow == null)
            {
                return(null);
            }

            // Is this a 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;

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

            if (updatedLabel != null)
            {
                // Award reputation for following label
                await _reputationAwarder.AwardAsync(Reputations.NewFollow, follow.CreatedUserId, $"Followed label \"{label.Name}\"");
            }

            return(follow);
        }
예제 #3
0
        private async Task <Follows.Models.Follow> FollowCreated(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;

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

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

            return(follow);
        }
예제 #4
0
        private async Task <Follows.Models.Follow> FollowCreated(Follows.Models.Follow follow)
        {
            if (follow == null)
            {
                return(null);
            }

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

            // Award reputation for following channel
            await _reputationAwarder.AwardAsync(Reputations.NewFollow, follow.CreatedUserId, "Followed a discuss category");

            return(follow);
        }
예제 #5
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);
        }