Ejemplo n.º 1
0
        public async Task <IActionResult> Unfollow(string username)
        {
            _logger.LogInformation("Received profile unfollow request.");
            _logger.LogInformation("Profile username: {0}", username);

            User currentUser = _currentUserService.GetCurrentUser(HttpContext);

            _logger.LogInformation("Requesting user email: {0}", currentUser.Email);

            bool success = await _followService.UnfollowUser(username, currentUser.Email);

            if (!success)
            {
                _logger.LogError("Failed to unfollow '{0}' for '{1}'.", username, currentUser.Email);
                return(BadRequest());
            }

            // Publish event.
            _logger.LogInformation("Publishing unfollow notification.");
            FollowResponse followResponse = new FollowResponse()
            {
                UserUsername     = username,
                FollowerEmail    = currentUser.Email,
                FollowerUsername = currentUser.Username
            };
            await _notificationService.Publish(new UnfollowNotification(followResponse));

            _logger.LogInformation("Successfully unfollowed '{0}' for '{1}'.", username, currentUser.Email);

            return(NoContent());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// get subscribers of a channel
        /// </summary>
        /// <returns>list of subscribers</returns>
        public IEnumerable <UserInformation> GetFollowers()
        {
            if (channeldata == null)
            {
                Logger.Warning(this, "No channel connected to get subscribers");
                yield break;
            }

            int offset = 0;

            do
            {
                FollowResponse response = null;
                try
                {
                    response = channels.GetChannelFollowers(channeldata.ID, 100, offset);
                }
                catch (Exception e)
                {
                    Logger.Warning(this, $"Unable to get followers for channel '{channeldata.ID}'", e.Message);
                    throw;
                }

                if (response != null)
                {
                    foreach (UserInformation user in response.Follows.Select(s => new UserInformation
                    {
                        Service = TwitchConstants.ServiceKey,
                        Username = s.User.Name,
                        Avatar = s.User.Logo,
                    }))
                    {
                        yield return(user);
                    }
                }

                if (response?.Total < 100)
                {
                    break;
                }
                offset += 100;
            }while (true);
        }
Ejemplo n.º 3
0
 public UnfollowNotification(FollowResponse followResponse)
 {
     FollowResponse = followResponse;
 }