Skip to content

Commit

Permalink
Merge branch 'master' of github.com:terro/Chihiro
Browse files Browse the repository at this point in the history
  • Loading branch information
rxkh committed Jun 6, 2012
2 parents 746e175 + 7dff567 commit d28431a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions server/user.js
Expand Up @@ -339,6 +339,32 @@ function findByInterests(callback) {
});
}

// Find nearby users by interests
function recommendByInterests(uid, interests) {
redis.get('location:' + uid, function (err, location) {
if (location == null) {
callback([]);
return;
}
db.executeDbCommand({
geoNear: 'users',
near: eval(location),
spherical: true,
maxDistance: 1 / 6371, // 1km
distanceMultiplier: 6371000
}, function (err, obj) {
obj.documents[0].results.forEach(function (result) {
var obj = result.obj;
if (obj._id == uid) return;
if (!obj.interests) return;
if (!intersection(obj.interests, interests)) return;
if (obj._id in clients)
clients[obj._id].emit('recommend by interests', uid);
});
});
});
}

function updateLocation(data) {
var socket = this;
socket.get('uid', function (err, uid) {
Expand All @@ -361,6 +387,9 @@ function updateProfile(data, callback) {
// set in redis
data._id = uid;
setUserData(data);

if (data.interests)
recommendByInterests(uid, data.interests);

console.log('user ' + uid + ' updated its profile.');

Expand Down

0 comments on commit d28431a

Please sign in to comment.