Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
山ごとに小分けの関数にする
List<Tweet> tweets(String uid, List<Follow> follows, List<Tweet> tweets,
List<ReTweet>reTweets) {
var result = <Tweet>[];
// フォローしているユーザのUserIDを抽出
var followUserIDs = getFollowUserIDs(follows, uid);
// フォローしているユーザのTweetを抽出
result.addAll(getTweets(followUserIDs, tweets));
// フォローしているユーザーのReTweetを抽出
result.addAll(getReTweets(followUserIDs, reTweets, tweets));
return result;
}
List<Tweet> getReTweets(List<String> followUserIDs, List<ReTweet> reTweets,
List<Tweet> tweets) {
var list = <Tweet>[];
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) {
list.add(tweet);
}
}
}
}
return list;
}
List<Tweet> getTweets(followUserIDs, List<Tweet> tweets) {
var list = <Tweet>[];
for (var followUserID in followUserIDs) {
for (var tweet in tweets) {
if (tweet.uid == followUserID) {
list.add(tweet);
}
}
}
return tweets;
}
List<String> getFollowUserIDs(List<Follow> follows, String uid) {
var followUserIDs = <String>[];
for (var follow in follows) {
if (follow.from != uid) {
followUserIDs.add(follow.to);
}
}
return followUserIDs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.