v1.18.x
barisusakli 11 years ago
parent 0e241456e4
commit 89bb11a58c

@ -37,7 +37,7 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
for(var x = 0; x<chats.length; ++x) {
userObj = chats[x];
$('<li />')
$('<li class="' + (userObj.unread ? 'unread' : '') + '"/>')
.attr('data-uid', userObj.uid)
.html('<a href="javascript:app.openChat(\'' +
userObj.username +

@ -70,7 +70,7 @@ module.exports = function(db, module) {
}
set.sort(function(a, b) {return b.score - a.score;});
callback(null, set);
})
});
};
module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {
@ -162,6 +162,19 @@ module.exports = function(db, module) {
});
};
module.isSortedSetMembers = function(key, values, callback) {
module.getListRange(key, 0, -1, function(err, list) {
list = list.map(function(item) {
return item.value;
});
values = values.map(function(value) {
return list.indexOf(value.toString()) !== -1;
});
callback(err, values);
});
};
module.sortedSetsScore = function(keys, value, callback) {
var sets = {};
async.each(keys, function(key, next) {

@ -132,6 +132,22 @@ module.exports = function(db, module) {
});
};
module.isSortedSetMembers = function(key, values, callback) {
values = values.map(helpers.valueToString);
db.collection('objects').find({_key: key, value: {$in: values}}).toArray(function(err, results) {
results = results.map(function(item) {
return item.value;
});
values = values.map(function(value) {
return results.indexOf(value) !== -1;
});
console.log(err, values);
callback(err, results);
});
};
module.sortedSetsScore = function(keys, value, callback) {
value = helpers.valueToString(value);
db.collection('objects').find({_key:{$in:keys}, value: value}).toArray(function(err, result) {

@ -68,6 +68,22 @@ module.exports = function(redisClient, module) {
});
};
module.isSortedSetMembers = function(key, values, callback) {
var multi = redisClient.multi();
for (var i=0; i<values.length; ++i) {
multi.zscore(key, values[i]);
}
multi.exec(function(err, results) {
if (err) {
return callback(err);
}
results = results.map(function(score) {
return !!score;
});
callback(null, results);
});
};
module.sortedSetsScore = function(keys, value, callback) {
multi('zscore', keys, value, callback);
};

@ -145,12 +145,20 @@ var db = require('./database'),
return callback(err);
}
user.getMultipleUserFields(uids, ['username', 'picture', 'uid'], function(err, users) {
async.parallel({
unreadUids: async.apply(db.isSortedSetMembers, 'uid:' + uid + ':chats:unread', uids),
users: async.apply(user.getMultipleUserFields, uids, ['username', 'picture', 'uid'])
}, function(err, results) {
if (err) {
return callback(err);
}
var users = results.users;
users = users.filter(function(user) {
for (var i=0; i<users.length; ++i) {
users[i].unread = results.unreadUids[i];
}
users = users.filter(function(user, index) {
return !!user.uid;
});

Loading…
Cancel
Save