Skip to content

Instantly share code, notes, and snippets.

@syuilo
Last active August 29, 2015 14:17
Show Gist options
  • Save syuilo/b0653de75c71e8028695 to your computer and use it in GitHub Desktop.
Save syuilo/b0653de75c71e8028695 to your computer and use it in GitHub Desktop.
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