mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 00:10:25 +01:00
#1281 post purge
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
"reply": "Reply",
|
"reply": "Reply",
|
||||||
"edit": "Edit",
|
"edit": "Edit",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
|
"purge": "Purge",
|
||||||
"restore": "Restore",
|
"restore": "Restore",
|
||||||
"move": "Move",
|
"move": "Move",
|
||||||
"fork": "Fork",
|
"fork": "Fork",
|
||||||
@@ -68,8 +69,7 @@
|
|||||||
|
|
||||||
"post_delete_confirm": "Are you sure you want to delete this post?",
|
"post_delete_confirm": "Are you sure you want to delete this post?",
|
||||||
"post_restore_confirm": "Are you sure you want to restore this post?",
|
"post_restore_confirm": "Are you sure you want to restore this post?",
|
||||||
"post_delete_error": "Could not delete this post!",
|
"post_purge_confirm": "Are you you want to purge this post?",
|
||||||
"post_restore_error": "Could not restore this post!",
|
|
||||||
|
|
||||||
"load_categories": "Loading Categories",
|
"load_categories": "Loading Categories",
|
||||||
"disabled_categories_note": "Disabled Categories are greyed out",
|
"disabled_categories_note": "Disabled Categories are greyed out",
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
|
|||||||
'event:topic_moved': onTopicMoved,
|
'event:topic_moved': onTopicMoved,
|
||||||
|
|
||||||
'event:post_edited': onPostEdited,
|
'event:post_edited': onPostEdited,
|
||||||
|
'event:post_purged': onPostPurged,
|
||||||
|
|
||||||
'event:post_deleted': togglePostDeleteState,
|
'event:post_deleted': togglePostDeleteState,
|
||||||
'event:post_restored': togglePostDeleteState,
|
'event:post_restored': togglePostDeleteState,
|
||||||
@@ -108,10 +109,19 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onPostPurged(pid) {
|
||||||
|
$('#post-container li[data-pid="' + pid + '"]').fadeOut(500, function() {
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function togglePostDeleteState(data) {
|
function togglePostDeleteState(data) {
|
||||||
var postEl = $('#post-container li[data-pid="' + data.pid + '"]');
|
var postEl = $('#post-container li[data-pid="' + data.pid + '"]');
|
||||||
|
|
||||||
if (postEl.length) {
|
if (!postEl.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
postEl.toggleClass('deleted');
|
postEl.toggleClass('deleted');
|
||||||
var isDeleted = postEl.hasClass('deleted');
|
var isDeleted = postEl.hasClass('deleted');
|
||||||
postTools.toggle(data.pid, isDeleted);
|
postTools.toggle(data.pid, isDeleted);
|
||||||
@@ -128,12 +138,13 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
|
|||||||
|
|
||||||
postTools.updatePostCount();
|
postTools.updatePostCount();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function togglePostFavourite(data) {
|
function togglePostFavourite(data) {
|
||||||
|
|
||||||
var favBtn = $('li[data-pid="' + data.post.pid + '"] .favourite');
|
var favBtn = $('li[data-pid="' + data.post.pid + '"] .favourite');
|
||||||
if (favBtn.length) {
|
if (!favBtn.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
favBtn.addClass('btn-warning')
|
favBtn.addClass('btn-warning')
|
||||||
.attr('data-favourited', data.isFavourited);
|
.attr('data-favourited', data.isFavourited);
|
||||||
|
|
||||||
@@ -144,7 +155,6 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
|
|||||||
icon.attr('class', data.isFavourited ? className.replace('-o', '') : className + '-o');
|
icon.attr('class', data.isFavourited ? className.replace('-o', '') : className + '-o');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function togglePostVote(data) {
|
function togglePostVote(data) {
|
||||||
var post = $('li[data-pid="' + data.post.pid + '"]');
|
var post = $('li[data-pid="' + data.post.pid + '"]');
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
|
|||||||
var postEl = $('#post-container li[data-pid="' + pid + '"]');
|
var postEl = $('#post-container li[data-pid="' + pid + '"]');
|
||||||
|
|
||||||
postEl.find('.quote, .favourite, .post_reply, .chat').toggleClass('none', isDeleted);
|
postEl.find('.quote, .favourite, .post_reply, .chat').toggleClass('none', isDeleted);
|
||||||
|
postEl.find('.purge').toggleClass('none', !isDeleted);
|
||||||
|
|
||||||
translator.translate(isDeleted ? ' [[topic:restore]]' : ' [[topic:delete]]', function(translated) {
|
translator.translate(isDeleted ? ' [[topic:restore]]' : ' [[topic:delete]]', function(translated) {
|
||||||
|
postEl.find('.delete').find('i').toggleClass('fa-trash-o', !isDeleted).toggleClass('fa-comment', isDeleted);
|
||||||
postEl.find('.delete').find('span').html(translated);
|
postEl.find('.delete').find('span').html(translated);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -88,6 +90,10 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
|
|||||||
deletePost($(this), tid);
|
deletePost($(this), tid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
postContainer.on('click', '.purge', function(e) {
|
||||||
|
purgePost($(this), tid);
|
||||||
|
})
|
||||||
|
|
||||||
postContainer.on('click', '.move', function(e) {
|
postContainer.on('click', '.move', function(e) {
|
||||||
openMovePostModal($(this));
|
openMovePostModal($(this));
|
||||||
});
|
});
|
||||||
@@ -186,21 +192,31 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
|
|||||||
|
|
||||||
function deletePost(button, tid) {
|
function deletePost(button, tid) {
|
||||||
var pid = getPid(button),
|
var pid = getPid(button),
|
||||||
postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')),
|
postEl = $('#post-container li[data-pid="' + pid + '"]'),
|
||||||
action = !postEl.hasClass('deleted') ? 'delete' : 'restore';
|
action = !postEl.hasClass('deleted') ? 'delete' : 'restore';
|
||||||
|
|
||||||
|
postAction(action, pid, tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
function purgePost(button, tid) {
|
||||||
|
postAction('purge', getPid(button), tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
function postAction(action, pid, tid) {
|
||||||
translator.translate('[[topic:post_' + action + '_confirm]]', function(msg) {
|
translator.translate('[[topic:post_' + action + '_confirm]]', function(msg) {
|
||||||
bootbox.confirm(msg, function(confirm) {
|
bootbox.confirm(msg, function(confirm) {
|
||||||
if (confirm) {
|
if (!confirm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
socket.emit('posts.' + action, {
|
socket.emit('posts.' + action, {
|
||||||
pid: pid,
|
pid: pid,
|
||||||
tid: tid
|
tid: tid
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
app.alertError('[[topic:post_' + action + '_error]]');
|
app.alertError(err.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,16 @@ var winston = require('winston'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PostTools.purge = function(uid, pid, callback) {
|
||||||
|
privileges.posts.canEdit(pid, uid, function(err, canEdit) {
|
||||||
|
if (err || !canEdit) {
|
||||||
|
return callback(err || new Error('[[error:no-privileges]]'));
|
||||||
|
}
|
||||||
|
|
||||||
|
posts.delete(pid, callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function updateTopicTimestamp(tid, callback) {
|
function updateTopicTimestamp(tid, callback) {
|
||||||
topics.getLatestUndeletedPid(tid, function(err, pid) {
|
topics.getLatestUndeletedPid(tid, function(err, pid) {
|
||||||
if(err || !pid) {
|
if(err || !pid) {
|
||||||
|
|||||||
@@ -1,9 +1,127 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async'),
|
||||||
|
db = require('../database'),
|
||||||
|
|
||||||
|
plugins = require('../plugins');
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(Posts) {
|
module.exports = function(Posts) {
|
||||||
|
|
||||||
Posts.delete = function(pid, callback) {
|
Posts.delete = function(pid, callback) {
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
deletePostFromTopicAndUser(pid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
deletePostFromCategoryRecentPosts(pid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
deletePostFromUsersFavourites(pid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
deletePostFromUsersVotes(pid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('posts:pid', pid, next);
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.fireHook('action:post.delete', pid);
|
||||||
|
db.delete('post:' + pid, callback);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function deletePostFromTopicAndUser(pid, callback) {
|
||||||
|
Posts.getPostFields(pid, ['tid', 'uid', 'deleted'], function(err, postData) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('tid:' + postData.tid + ':posts', pid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('tid:' + postData.tid + ':posts:votes', pid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('uid:' + postData.uid + ':posts', pid, next);
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parseInt(postData.deleted, 10) === 0) {
|
||||||
|
db.decrObjectField('global', 'postCount', callback);
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletePostFromCategoryRecentPosts(pid, callback) {
|
||||||
|
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.each(cids, function(cid, next) {
|
||||||
|
db.sortedSetRemove('categories:recent_posts:cid:' + cid, pid, next);
|
||||||
|
}, callback);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletePostFromUsersFavourites(pid, callback) {
|
||||||
|
db.getSetMembers('pid:' + pid + ':users_favourited', function(err, uids) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.each(uids, function(uid, next) {
|
||||||
|
db.sortedSetRemove('uid:' + uid + ':favourites', pid, next);
|
||||||
|
}, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.delete('pid:' + pid + ':users_favourited', callback);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletePostFromUsersVotes(pid, callback) {
|
||||||
|
async.parallel({
|
||||||
|
upvoters: function(next) {
|
||||||
|
db.getSetMembers('pid:' + pid + ':upvote', next);
|
||||||
|
},
|
||||||
|
downvoters: function(next) {
|
||||||
|
db.getSetMembers('pid:' + pid + ':downvote', next);
|
||||||
|
}
|
||||||
|
}, function(err, results) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
async.each(results.upvoters, function(uid, next) {
|
||||||
|
db.sortedSetRemove('uid:' + uid + ':upvote', pid, next);
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
async.each(results.downvoters, function(uid, next) {
|
||||||
|
db.sortedSetRemove('uid:' + uid + ':downvote', pid, next);
|
||||||
|
}, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -210,6 +210,23 @@ function deleteOrRestore(command, socket, data, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SocketPosts.purge = function(socket, data, callback) {
|
||||||
|
if(!data) {
|
||||||
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
|
}
|
||||||
|
postTools.purge(socket.uid, data.pid, function(err) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.parent.exports.emitTopicPostStats();
|
||||||
|
|
||||||
|
websockets.server.sockets.in('topic_' + data.tid).emit('event:post_purged', data.pid);
|
||||||
|
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
SocketPosts.getPrivileges = function(socket, pid, callback) {
|
SocketPosts.getPrivileges = function(socket, pid, callback) {
|
||||||
privileges.posts.get(pid, socket.uid, function(err, privileges) {
|
privileges.posts.get(pid, socket.uid, function(err, privileges) {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ var async = require('async'),
|
|||||||
(function(Topics) {
|
(function(Topics) {
|
||||||
|
|
||||||
require('./topics/create')(Topics);
|
require('./topics/create')(Topics);
|
||||||
|
require('./topics/delete')(Topics);
|
||||||
require('./topics/unread')(Topics);
|
require('./topics/unread')(Topics);
|
||||||
require('./topics/recent')(Topics);
|
require('./topics/recent')(Topics);
|
||||||
require('./topics/fork')(Topics);
|
require('./topics/fork')(Topics);
|
||||||
|
|||||||
77
src/topics/delete.js
Normal file
77
src/topics/delete.js
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async'),
|
||||||
|
db = require('../database'),
|
||||||
|
|
||||||
|
plugins = require('../plugins');
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function(Topics) {
|
||||||
|
Topics.delete = function(tid, callback) {
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
db.delete('tid:' + tid + ':followers', next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.delete('tid:' + tid + ':read_by_uid', next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('topics:tid', tid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('topics:recent', tid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('topics:posts', tid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('topics:views', tid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
deleteTopicFromCategoryAndUser(tid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
Topics.deleteTopicTags(tid, next);
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
plugins.fireHook('action:topic.delete', tid);
|
||||||
|
db.delete('topic:' + tid, callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function deleteTopicFromCategoryAndUser(tid, callback) {
|
||||||
|
Topics.getTopicFields(tid, ['cid', 'uid', 'deleted'], function(err, topicData) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('categories:' + topicData.cid + ':tid', tid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('uid:' + topicData.uid + ':topics', tid, next);
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.decrObjectField('category:' + topicData.cid, 'topic_count', function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parseInt(topicData.deleted, 10) === 0) {
|
||||||
|
db.decrObjectField('global', 'topicCount', callback);
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
db = require('./../database'),
|
db = require('../database'),
|
||||||
posts = require('./../posts'),
|
posts = require('../posts'),
|
||||||
user = require('./../user'),
|
user = require('../user'),
|
||||||
topics = require('./../topics'),
|
topics = require('../topics'),
|
||||||
categories = require('./../categories'),
|
groups = require('../groups');
|
||||||
plugins = require('./../plugins'),
|
|
||||||
groups = require('./../groups');
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(User) {
|
module.exports = function(User) {
|
||||||
@@ -30,123 +28,11 @@ module.exports = function(User) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function deletePosts(uid, callback) {
|
function deletePosts(uid, callback) {
|
||||||
deleteSortedSetElements('uid:' + uid + ':posts', deletePost, callback);
|
deleteSortedSetElements('uid:' + uid + ':posts', posts.delete, callback);
|
||||||
}
|
|
||||||
|
|
||||||
function deletePost(pid, callback) {
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
deletePostFromTopic(pid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
deletePostFromCategoryRecentPosts(pid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
deletePostFromUsersFavourites(pid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
deletePostFromUsersVotes(pid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
db.sortedSetRemove('posts:pid', pid, next);
|
|
||||||
}
|
|
||||||
], function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins.fireHook('action:post.delete', pid);
|
|
||||||
db.delete('post:' + pid, callback);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deletePostFromTopic(pid, callback) {
|
|
||||||
posts.getPostFields(pid, ['tid', 'deleted'], function(err, postData) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
db.sortedSetRemove('tid:' + postData.tid + ':posts', pid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
db.sortedSetRemove('tid:' + postData.tid + ':posts:votes', pid, next);
|
|
||||||
}
|
|
||||||
], function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parseInt(postData.deleted, 10) === 0) {
|
|
||||||
db.decrObjectField('global', 'postCount', callback);
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deletePostFromCategoryRecentPosts(pid, callback) {
|
|
||||||
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.each(cids, function(cid, next) {
|
|
||||||
db.sortedSetRemove('categories:recent_posts:cid:' + cid, pid, next);
|
|
||||||
}, callback);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deletePostFromUsersFavourites(pid, callback) {
|
|
||||||
db.getSetMembers('pid:' + pid + ':users_favourited', function(err, uids) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.each(uids, function(uid, next) {
|
|
||||||
db.sortedSetRemove('uid:' + uid + ':favourites', pid, next);
|
|
||||||
}, function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
db.delete('pid:' + pid + ':users_favourited', callback);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deletePostFromUsersVotes(pid, callback) {
|
|
||||||
async.parallel({
|
|
||||||
upvoters: function(next) {
|
|
||||||
db.getSetMembers('pid:' + pid + ':upvote', next);
|
|
||||||
},
|
|
||||||
downvoters: function(next) {
|
|
||||||
db.getSetMembers('pid:' + pid + ':downvote', next);
|
|
||||||
}
|
|
||||||
}, function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
async.each(results.upvoters, function(uid, next) {
|
|
||||||
db.sortedSetRemove('uid:' + uid + ':upvote', pid, next);
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
async.each(results.downvoters, function(uid, next) {
|
|
||||||
db.sortedSetRemove('uid:' + uid + ':downvote', pid, next);
|
|
||||||
}, next);
|
|
||||||
}
|
|
||||||
], callback);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteTopics(uid, callback) {
|
function deleteTopics(uid, callback) {
|
||||||
deleteSortedSetElements('uid:' + uid + ':topics', deleteTopic, callback);
|
deleteSortedSetElements('uid:' + uid + ':topics', topics.delete, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteSortedSetElements(set, deleteMethod, callback) {
|
function deleteSortedSetElements(set, deleteMethod, callback) {
|
||||||
@@ -159,67 +45,6 @@ module.exports = function(User) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteTopic(tid, callback) {
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
db.delete('tid:' + tid + ':followers', next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
db.delete('tid:' + tid + ':read_by_uid', next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
db.sortedSetRemove('topics:tid', tid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
db.sortedSetRemove('topics:recent', tid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
db.sortedSetRemove('topics:posts', tid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
db.sortedSetRemove('topics:views', tid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
deleteTopicFromCategory(tid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
topics.deleteTopicTags(tid, next);
|
|
||||||
}
|
|
||||||
], function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
plugins.fireHook('action:topic.delete', tid);
|
|
||||||
db.delete('topic:' + tid, callback);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteTopicFromCategory(tid, callback) {
|
|
||||||
topics.getTopicFields(tid, ['cid', 'deleted'], function(err, topicData) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
db.sortedSetRemove('categories:' + topicData.cid + ':tid', tid, function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
db.decrObjectField('category:' + topicData.cid, 'topic_count', function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parseInt(topicData.deleted, 10) === 0) {
|
|
||||||
db.decrObjectField('global', 'topicCount', callback);
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteAccount(uid, callback) {
|
function deleteAccount(uid, callback) {
|
||||||
user.getUserFields(uid, ['username', 'userslug', 'email'], function(err, userData) {
|
user.getUserFields(uid, ['username', 'userslug', 'email'], function(err, userData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user