/// <summary> /// Checks if the specified users follows the specified channel /// </summary> /// <param name="channel">The channel to get follows against</param> /// <param name="users">The users to check if they follow</param> /// <returns>All users checked and whether they follow or not</returns> public async Task <Dictionary <UserModel, DateTimeOffset?> > CheckIfFollows(ChannelModel channel, IEnumerable <UserModel> users) { Validator.ValidateVariable(channel, "channel"); Validator.ValidateList(users, "users"); Dictionary <UserModel, DateTimeOffset?> results = new Dictionary <UserModel, DateTimeOffset?>(); for (int i = 0; i < users.Count(); i += 25) { IEnumerable <UserModel> userSubset = users.Skip(i).Take(25); string followQuery = string.Join(",", userSubset.Select(user => $"where=id:eq:{user.id}")); IEnumerable <FollowerUserModel> followUsers = await this.GetPagedAsync <FollowerUserModel>("channels/" + channel.id + "/follow?nonce=" + Guid.NewGuid().ToString() + "&fields=id,followed&" + followQuery); IEnumerable <uint> followUserIDs = followUsers.Select(u => u.id); foreach (UserModel user in userSubset) { DateTimeOffset? followDate = null; FollowerUserModel follow = followUsers.FirstOrDefault(u => u.id.Equals(user.id)); if (follow != null) { followDate = follow.followed.createdAt; } results.Add(user, followDate); } } return(results); }
/// <summary> /// Checks if the specified users follows the specified channel /// </summary> /// <param name="channel">The channel to get follows against</param> /// <param name="users">The users to check if they follow</param> /// <param name="processResults">The function to process results as they come in</param> /// <returns>All users checked and whether they follow or not</returns> public async Task CheckIfFollows(ChannelModel channel, IEnumerable <UserModel> users, Func <IEnumerable <KeyValuePair <uint, DateTimeOffset?> >, Task> processResults) { Validator.ValidateVariable(channel, "channel"); Validator.ValidateList(users, "users"); for (int i = 0; i < users.Count(); i += 25) { Dictionary <uint, DateTimeOffset?> results = new Dictionary <uint, DateTimeOffset?>(); IEnumerable <UserModel> userSubset = users.Skip(i).Take(25); IEnumerable <FollowerUserModel> followUsers = await this.GetPagedNumberAsync <FollowerUserModel>("channels/" + channel.id + "/follow?nonce=" + Guid.NewGuid().ToString() + "&fields=id,followed&where=id:in:" + string.Join(";", userSubset.Select(u => u.id))); IEnumerable <uint> followUserIDs = followUsers.Select(u => u.id); foreach (UserModel user in userSubset) { DateTimeOffset? followDate = null; FollowerUserModel follow = followUsers.FirstOrDefault(u => u.id.Equals(user.id)); if (follow != null) { followDate = follow.followed.createdAt; } results[user.id] = followDate; } await processResults(results); } }