Esempio n. 1
0
        public async Task <object> SubscribeFollowers(List <string> followers)
        {
            var handle         = GetUserHandle();
            var throttleResult = await ThrottleStore.CheckThrottle(ThrottleAction.SubscribeFollowers, handle, IsAuthenticated);

            if (throttleResult.ThrottleRequest)
            {
                return(await SendErrorMessage("Rate Limit", throttleResult.Message));
            }

            var following = await FollowerStore.GetFollowers(handle);

            if (followers.IsNullOrEmpty())
            {
                return new
                       {
                           Followers = following,
                           Following = new List <string>()
                       }
            }
            ;

            var result = new List <string>();

            foreach (var follower in followers.Select(x => x.Trim()).Distinct())
            {
                if (!HiveValidation.ValidateUserHandle(follower))
                {
                    continue;
                }

                await FollowerStore.FollowHandle(handle, follower);

                await SendFollowUpdate(follower, handle, false);

                result.Add(follower);
            }

            return(new
            {
                Followers = following,
                Following = result
            });
        }
Esempio n. 2
0
        private string GetSenderName(string sender, string senderId)
        {
            if (IsAuthenticated)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(sender) || sender.Equals(senderId))
            {
                return(null);
            }

            var handle = sender.Trim().Truncate(15);

            if (!HiveValidation.ValidateUserHandle(handle))
            {
                return(null);
            }

            return(handle);
        }
Esempio n. 3
0
        public async Task <bool> UnfollowUser(string userToUnfollow)
        {
            if (!HiveValidation.ValidateUserHandle(userToUnfollow))
            {
                return(await SendErrorMessage("Validation Error", "Invalid name format"));
            }

            var handle         = GetUserHandle();
            var throttleResult = await ThrottleStore.CheckThrottle(ThrottleAction.UnfollowUser, handle, IsAuthenticated);

            if (throttleResult.ThrottleRequest)
            {
                return(await SendErrorMessage("Rate Limit", throttleResult.Message));
            }

            await FollowerStore.UnfollowHandle(handle, userToUnfollow);

            await SendFollowUpdate(userToUnfollow, handle, true);

            return(true);
        }