-
-
Save aredridel/6101455 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Friend.findOne({ | |
userId: req.signedCookies.userid | |
}, function (err, signedInUser) { | |
function doCheck(err, currentUser) { | |
if (err) { | |
res.send(err); | |
} else { | |
console.log('doCheck'); | |
//for(var x = 0; x < users.length; x++) { | |
//var currentUser = users[x]; | |
function checkResult(lengthTerm, results) { | |
console.log('here2'); | |
return function () { | |
if (lengthTerm > 0) { | |
for (var i = 0; i < lengthTerm.length; i++) { | |
var currentLengthUser = lengthTerm[i]; | |
if (currentUser._id === currentLengthUser) { | |
for (var j = 0; j < results.length; j++) { | |
return results[j]; | |
} | |
} | |
} | |
} else { | |
currentUser.isMe = null; | |
currentUser.isFriend = null; | |
currentUser.isFriendRequest = false; | |
currentUser.isPendingRequest = null; | |
} | |
} | |
} | |
//} | |
function isMe(err, cb) { | |
console.log('isMe'); | |
if (err) { | |
res.send(err); | |
} else { | |
isMeResults = [ | |
users[x].isMe = true, | |
users[x].isFriend = null, | |
users[x].isFriendRequest = null, | |
users[x].isPendingRequest = null]; | |
return checkResult(signedInUser.userId, isMeResults); | |
cb(); | |
} | |
}; | |
function isFriend(err, cb) { | |
console.log('isFriend'); | |
if (err) { | |
res.send(err); | |
} else { | |
isFriendResults = [ | |
users[x].isMe = null, | |
users[x].isFriend = true, | |
users[x].isFriendRequest = null, | |
users[x].isPendingRequest = null]; | |
return checkResult(signedInUser.friends, isFriendResults); | |
cb(); | |
} | |
}; | |
function isPendingRequest(err, cb) { | |
console.log('isPendingRequest'); | |
if (err) { | |
res.send(err); | |
} else { | |
isPendingRequestResults = [ | |
users[x].isMe = null, | |
users[x].isFriend = null, | |
users[x].isFriendRequest = null, | |
users[x].isPendingRequest = true]; | |
return checkResult(signedInUser.request_received_from, isPendingRequestResults); | |
cb(); | |
} | |
}; | |
function isFriendRequest(err, cb) { | |
console.log('isFriendRequest'); | |
if (err) { | |
res.send(err); | |
} else { | |
isFriendRequestResults = [ | |
users[x].isMe = null, | |
users[x].isFriend = null, | |
users[x].isFriendRequest = null, | |
users[x].isPendingRequest = true]; | |
return checkResult(signedInUser.request_sent_to, isFriendRequestResults); | |
cb(); | |
} | |
}; | |
} | |
} | |
for (var x = 0; x < users.length; x++) { | |
var currentUser = users[x]; | |
doCheck(err, currentUser); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment