From d41836e937a5685f6421c47b1c95820ed609623b Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 18 Jul 2017 02:16:07 +0000 Subject: [PATCH] index for aliases --- modules/users/api.js | 15 ++++++--------- modules/users/users.js | 11 ++++++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/users/api.js b/modules/users/api.js index b9368bc..361fcce 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -33,15 +33,12 @@ var api = function(dbot) { // Retrieve user aliases given a user ID 'getUserAliases': function(id, callback) { - var aliases = []; - this.db.search('user_aliases', { 'user': id }, function(result) { - aliases.push(result.alias); - }, function(err) { - if(!err) { - callback(null, aliases); - } else { - callback(true, null); - } + this.api.getUser(id, function(err, user) { + if(!err) { + callback(null, user.aliases); + } else { + callback(true, null); + } }); }, diff --git a/modules/users/users.js b/modules/users/users.js index c53a32b..407899b 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -16,7 +16,8 @@ var users = function(dbot) { 'id': id, 'server': server, 'primaryNick': nick, - 'currentNick': nick + 'currentNick': nick, + 'aliases': [] }, function(err, result) { if(!err) dbot.api.event.emit('new_user', [ result ]); callback(err, result); @@ -33,11 +34,14 @@ var users = function(dbot) { }, function(err, result) { if(!err) { dbot.api.event.emit('new_user_alias', [ result, alias ]); - callback(null, result); + user.aliases.push(alias); + this.db.save('users', user.id, user, function() { + callback(null, result); + }); } else { callback(true, null); } - }); + }.bind(this)); }.bind(this), // Remove an alias record @@ -134,6 +138,7 @@ var users = function(dbot) { } }.bind(this)); }.bind(this); + var checkUserTime = function(user, done) { if(!_.has(user, 'lastUsed') || (_.has(user, 'lastUsed') && moment(user.lastUsed).diff(moment(user.lastUsed).add(1, 'day'), 'days') > 0)) { user.lastUsed = moment().unix();