Last active
August 29, 2015 14:17
-
-
Save syuilo/b0653de75c71e8028695 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require! { | |
async | |
'../models/user': User | |
'../models/user-following': UserFollowing | |
'../models/status': Status | |
'./user-response-filter' | |
'../config' | |
} | |
exports = (user-id, limit, since-id, max-id, callback) -> | |
UserFollowing.find { follower-id: user-id }, (followings) -> | |
| followings? => | |
function query-callback(err, statuses) | |
callback statuses | |
followings-ids = [] | |
followings-ids.push user-id # Get my statuses | |
followings.for-each (following) -> | |
followings-ids.push following.followee-id.to-string! | |
query = switch | |
| !since-id? and !max-id? => { user-id: { $in: followings-ids } } | |
| since-id? => { $and: [ user-id: { $in: followings-ids }, id : { $gt: since-id } ] } | |
| max-id? => { $and: [ user-id: { $in: followings-ids }, id : { $lt: max-id } ] } | |
Status | |
.find query | |
.sort \-created-at # Desc | |
.limit limit | |
.exec query-callback | |
| _ => callback null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment