public async Task UpdateFriendShipIds() { using (await IdsAsyncLock.LockAsync()) { if (GetIds) { return; } long idsCursor = 0; try { while (true) { var param = new Dictionary <string, object> { { "user_id", Tokens.UserId }, { "count", 5000 } }; if (idsCursor != 0) { param.Add("cursor", idsCursor); } var userFollowingIds = await Tokens.Friends.IdsAsync(param); foreach (var id in userFollowingIds) { FollowingIds.Add(id); } if (userFollowingIds.NextCursor == 0) { break; } idsCursor = userFollowingIds.NextCursor; } } catch { return; } try { while (true) { var param = new Dictionary <string, object> { { "user_id", Tokens.UserId }, { "count", 5000 } }; if (idsCursor != 0) { param.Add("cursor", idsCursor); } var userFollowerIds = await Tokens.Followers.IdsAsync(param); foreach (var id in userFollowerIds) { FollowersIds.Add(id); } if (userFollowerIds.NextCursor == 0) { break; } idsCursor = userFollowerIds.NextCursor; } } catch { return; } CrushIds = FollowingIds.Except(FollowersIds).ToList(); CrushedOnIds = FollowersIds.Except(FollowingIds).ToList(); GetIds = true; } }
public async Task UpdateCrushedOn(bool useCursor = false) { if (UpdatingCrushedOn) { return; } if (Tokens == null) { return; } if (useCursor && _crushedOnCursor == 0) { return; } UpdatingCrushedOn = true; if (!useCursor || _crushedOnCursor == 0) { CrushedOn.Clear(); } if (!GetIds) { await UpdateFriendShipIds(); } if (!GetIds) { UpdatingCrushedOn = true; return; } using (await IdsAsyncLock.LockAsync()) { var ids = new List <long>(); for (var idsCount = 0; _crushedOnCursor < CrushedOnIds.Count && idsCount <= 99; _crushedOnCursor++, idsCount++) { ids.Add(CrushedOnIds[(int)_crushedOnCursor]); } try { var crushedOn = await Tokens.Users.LookupAsync(user_id => ids.AsEnumerable()); if (!useCursor || _crushedOnCursor == 0) { CrushedOn.Clear(); } foreach (var user in crushedOn) { CrushedOn.Add(user); } } catch { if (!useCursor || _crushedOnCursor == 0) { CrushedOn.Clear(); } UpdatingCrushedOn = false; return; } } if (_crushedOnCursor == CrushedOnIds.Count) { _crushedOnCursor = 0; } UpdatingCrushedOn = false; }