hook fixes

new hook, action:user.online,
fix action:user.set hooks so they pass in uid
check err before firing hooks
v1.18.x
barisusakli 10 years ago
parent aaa1fae558
commit a1c8902b4e

@ -152,23 +152,37 @@ var async = require('async'),
if (err || now - parseInt(score, 10) < 300000) { if (err || now - parseInt(score, 10) < 300000) {
return callback(err); return callback(err);
} }
db.sortedSetAdd('users:online', now, uid, callback); db.sortedSetAdd('users:online', now, uid, function(err) {
if (err) {
return callback(err);
}
plugins.fireHook('action:user.online', {uid: uid, timestamp: now});
});
}); });
}; };
User.setUserField = function(uid, field, value, callback) { User.setUserField = function(uid, field, value, callback) {
plugins.fireHook('action:user.set', {field: field, value: value, type: 'set'}); db.setObjectField('user:' + uid, field, value, function(err) {
db.setObjectField('user:' + uid, field, value, callback); if (err) {
return callback(err)
}
plugins.fireHook('action:user.set', {uid: uid, field: field, value: value, type: 'set'});
callback();
});
}; };
User.setUserFields = function(uid, data, callback) { User.setUserFields = function(uid, data, callback) {
for (var field in data) { db.setObject('user:' + uid, data, function(err) {
if (data.hasOwnProperty(field)) { if (err) {
plugins.fireHook('action:user.set', {field: field, value: data[field], type: 'set'}); return callback(err);
} }
} for (var field in data) {
if (data.hasOwnProperty(field)) {
db.setObject('user:' + uid, data, callback); plugins.fireHook('action:user.set', {uid: uid, field: field, value: data[field], type: 'set'});
}
}
callback();
});
}; };
User.incrementUserFieldBy = function(uid, field, value, callback) { User.incrementUserFieldBy = function(uid, field, value, callback) {
@ -177,7 +191,7 @@ var async = require('async'),
if (err) { if (err) {
return callback(err); return callback(err);
} }
plugins.fireHook('action:user.set', {field: field, value: value, type: 'increment'}); plugins.fireHook('action:user.set', {uid: uid, field: field, value: value, type: 'increment'});
callback(null, value); callback(null, value);
}); });
@ -189,7 +203,7 @@ var async = require('async'),
if (err) { if (err) {
return callback(err); return callback(err);
} }
plugins.fireHook('action:user.set', {field: field, value: value, type: 'decrement'}); plugins.fireHook('action:user.set', {uid: uid, field: field, value: value, type: 'decrement'});
callback(null, value); callback(null, value);
}); });

Loading…
Cancel
Save