Skip to content

Node.js based forum software built for the modern web

delete chats on user delete

barisusaklid5bccfb292a6
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) {