From 5dddae4f00e5873adb62c61e11f8c4b65e8a40cd Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 26 May 2013 12:37:37 +0000 Subject: [PATCH] mergeChannelUsers internal API function in users + mergeusers seems to be working [#470] --- modules/users/commands.js | 17 +++++++++-------- modules/users/strings.json | 2 +- modules/users/users.js | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/modules/users/commands.js b/modules/users/commands.js index 8a89e97..1a96e53 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -83,7 +83,7 @@ var commands = function(dbot) { } }); } else { - event.reply(dbot.t('unknown_alias', { 'alias': newPrimary })); + event.reply(dbot.t('unknown_alias', { 'alias': newPrimarj })); } }.bind(this)); }, @@ -94,15 +94,16 @@ var commands = function(dbot) { this.api.resolveUser(event.server, primaryUser, function(user) { if(user) { - this.api.resolveUser(event.server, secondaryUser, function(secondaryUser) { + this.api.resolveUser(event.server, secondaryUser, function(oldUser) { if(secondaryUser) { - user.aliases.push(secondaryUser.primaryNick); - user.aliases.concat(secondaryUser.aliases); - this.db.del('users', secondaryUser.id, function(err) { + user.aliases.push(oldUser.primaryNick); + user.aliases.concat(oldUser.aliases); + this.internalAPI.mergeChannelUsers(event.server, oldUser, primaryUser); + this.db.del('users', oldUser.id, function(err) { if(!err) { this.db.save('users', user.id, user, function(err) { if(!err) { - this.updateChannels(event, secondaryUser, primaryUser); + this.internalAPI.mergeChannelUsers(event.server, secondaryUser, primaryUser); event.reply(dbot.t('merged_users', { 'old_user': secondaryUser, 'new_user': primaryUser @@ -116,11 +117,11 @@ var commands = function(dbot) { } }.bind(this)); } else { - event.reply(dbot.t('unprimary_error')); + event.reply(dbot.t('unprimary_error', { 'nick': secondaryUser })); } }.bind(this)); } else { - event.reply(dbot.t('unprimary_error')); + event.reply(dbot.t('unprimary_error', { 'nick': primaryUser })); } }.bind(this)); } diff --git a/modules/users/strings.json b/modules/users/strings.json index a8f60f1..fe9f79d 100644 --- a/modules/users/strings.json +++ b/modules/users/strings.json @@ -20,7 +20,7 @@ "nl": "{newParent} is nu de bovenliggende gebruiker, en {newAlias} is een alias." }, "unprimary_error": { - "en": "One of those users isn't currently recorded as a primary user.", + "en": "{nick} isn't recorded as a primary user.", "na'vi": "fo sute txin ke lu.", "nl": "Een van deze gebruikers is nog niet bekend als een primaire gebruiker." }, diff --git a/modules/users/users.js b/modules/users/users.js index b40f937..5612521 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -67,7 +67,26 @@ var users = function(dbot) { // QQ } }); - }.bind(this) + }.bind(this), + + 'mergeChannelUsers': function(server, oldUser, newUser) { + newUser.channels = _.union(oldUser.channels, newUser.channels); + _.each(newUser.channels, function(name) { + this.api.getChannel(server, name, function(channel) { + if(_.include(channel.users, oldUser.id)) { + channel.users = _.without(channel.users, oldUser.id); + } + if(!_.include(channel.users, newUser.id)) { + channel.users.push(newUser.id); + } + this.db.save('channel_users', channel.id, channel, function(err) { + if(err) { + // QQ + } + }); + }); + }, this); + } }; this.listener = function(event) {