From d5bccfb292a67d41d1b9e01550085b16e1907484 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 16 Dec 2015 09:30:55 +0200 Subject: [PATCH] delete chats on user delete --- src/user/delete.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/user/delete.js b/src/user/delete.js index 2fc444da42..5b822fcd7f 100644 --- a/src/user/delete.js +++ b/src/user/delete.js @@ -55,6 +55,9 @@ module.exports = function(User) { function (next) { deleteVotes(uid, next); }, + function (next) { + deleteChats(uid, next); + }, function (next) { async.parallel([ function(next) { @@ -97,6 +100,7 @@ module.exports = function(User) { 'uid:' + uid + ':favourites', 'uid:' + uid + ':followed_tids', 'user:' + uid + ':settings', 'uid:' + uid + ':topics', 'uid:' + uid + ':posts', 'uid:' + uid + ':chats', 'uid:' + uid + ':chats:unread', + 'uid:' + uid + ':chat:rooms', 'uid:' + uid + ':chat:rooms:unread', 'uid:' + uid + ':upvote', 'uid:' + uid + ':downvote', 'uid:' + uid + ':ignored:cids', 'uid:' + uid + ':flag:pids' ]; @@ -145,6 +149,29 @@ module.exports = function(User) { }); } + function deleteChats(uid, callback) { + async.waterfall([ + function (next) { + db.getSortedSetRange('uid:' + uid + ':chat:rooms', 0, -1, next); + }, + function (roomIds, next) { + var userKeys = roomIds.map(function(roomId) { + return 'uid:' + uid + ':chat:room:' + roomId + ':mids'; + }); + var roomKeys = roomIds.map(function(roomId) { + return 'chat:room:' + roomId + ':uids'; + }); + + async.parallel([ + async.apply(db.sortedSetsRemove, roomKeys, uid), + async.apply(db.deleteAll, userKeys) + ], next); + } + ], function(err) { + callback(err); + }); + } + function deleteUserIps(uid, callback) { async.waterfall([ function (next) {