Skip to content

Instantly share code, notes, and snippets.

@rikuTanide
Last active October 9, 2017 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikuTanide/a9627f5e908c3bc29840c7139665f422 to your computer and use it in GitHub Desktop.
Save rikuTanide/a9627f5e908c3bc29840c7139665f422 to your computer and use it in GitHub Desktop.
まずフォローしているユーザーを配列に抽出してから続きの作業をする
/// followは全ユーザのフォロー・フォロワーの関係が入っているリスト
List<Tweet> tweets(String uid, List<Follow> follows, List<Tweet> tweets,
List<ReTweet>reTweets) {
var result = <Tweet>[];
// フォローしているユーザのUserIDを抽出
var followUserIDs = <String>[];
for (var follow in follows) {
if (follow.from != uid) {
followUserIDs.add(follow.to);
}
}
// フォローしているユーザのTweetを抽出
for (var followUserID in followUserIDs) {
for (var tweet in tweets) {
if (tweet.uid == followUserID) {
result.add(tweet);
}
}
}
// フォローしているユーザーのReTweetを抽出
for (var followUserID in followUserIDs) {
for (var reTweet in reTweets) {
if (reTweet.uid != followUserID) {
continue;
}
for (var tweet in tweets) {
if (reTweet.tweetID == tweet.tweetID) {
result.add(tweet);
break;
}
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment