refactor: socket posts delete/restore/purge so tid is not necessary (#8607)

* refactor: socket posts delete/restore/purge so tid is not necessary

* refactor: stop trying to be fancy

* fix: tests to not pass in tid into posts.deletePosts

* fix: some more unnecessary tid passing
v1.18.x
Julian Lam 5 years ago committed by GitHub
parent dfeb65bb95
commit f743f92088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,7 +52,6 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function (compo
function deletePosts(btn, command) { function deletePosts(btn, command) {
btn.attr('disabled', true); btn.attr('disabled', true);
socket.emit(command, { socket.emit(command, {
tid: ajaxify.data.tid,
pids: postSelect.pids, pids: postSelect.pids,
}, function (err) { }, function (err) {
btn.removeAttr('disabled'); btn.removeAttr('disabled');

@ -166,7 +166,7 @@ define('forum/topic/postTools', [
var timestamp = parseInt(getData(btn, 'data-timestamp'), 10); var timestamp = parseInt(getData(btn, 'data-timestamp'), 10);
var postDeleteDuration = parseInt(ajaxify.data.postDeleteDuration, 10); var postDeleteDuration = parseInt(ajaxify.data.postDeleteDuration, 10);
if (checkDuration(postDeleteDuration, timestamp, 'post-delete-duration-expired')) { if (checkDuration(postDeleteDuration, timestamp, 'post-delete-duration-expired')) {
togglePostDelete($(this), tid); togglePostDelete($(this));
} }
}); });
@ -203,11 +203,11 @@ define('forum/topic/postTools', [
} }
postContainer.on('click', '[component="post/restore"]', function () { postContainer.on('click', '[component="post/restore"]', function () {
togglePostDelete($(this), tid); togglePostDelete($(this));
}); });
postContainer.on('click', '[component="post/purge"]', function () { postContainer.on('click', '[component="post/purge"]', function () {
purgePost($(this), tid); purgePost($(this));
}); });
postContainer.on('click', '[component="post/move"]', function () { postContainer.on('click', '[component="post/move"]', function () {
@ -371,19 +371,19 @@ define('forum/topic/postTools', [
return slug; return slug;
} }
function togglePostDelete(button, tid) { function togglePostDelete(button) {
var pid = getData(button, 'data-pid'); var pid = getData(button, 'data-pid');
var postEl = components.get('post', 'pid', pid); var postEl = components.get('post', 'pid', pid);
var action = !postEl.hasClass('deleted') ? 'delete' : 'restore'; var action = !postEl.hasClass('deleted') ? 'delete' : 'restore';
postAction(action, pid, tid); postAction(action, pid);
} }
function purgePost(button, tid) { function purgePost(button) {
postAction('purge', getData(button, 'data-pid'), tid); postAction('purge', getData(button, 'data-pid'));
} }
function postAction(action, pid, tid) { function postAction(action, pid) {
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) {
@ -392,7 +392,6 @@ define('forum/topic/postTools', [
socket.emit('posts.' + action, { socket.emit('posts.' + action, {
pid: pid, pid: pid,
tid: tid,
}, function (err) { }, function (err) {
if (err) { if (err) {
app.alertError(err.message); app.alertError(err.message);

@ -89,7 +89,7 @@ module.exports = function (SocketPosts) {
await deleteOrRestoreTopicOf(params.command, data.pid, socket); await deleteOrRestoreTopicOf(params.command, data.pid, socket);
} }
websockets.in('topic_' + data.tid).emit(params.event, postData); websockets.in('topic_' + postData.tid).emit(params.event, postData);
await events.log({ await events.log({
type: params.type, type: params.type,
@ -114,7 +114,7 @@ module.exports = function (SocketPosts) {
} }
for (const pid of data.pids) { for (const pid of data.pids) {
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
await SocketPosts[command](socket, { pid: pid, tid: data.tid }); await SocketPosts[command](socket, { pid: pid });
} }
} }
@ -134,8 +134,8 @@ module.exports = function (SocketPosts) {
await posts.tools.purge(socket.uid, data.pid); await posts.tools.purge(socket.uid, data.pid);
websockets.in('topic_' + data.tid).emit('event:post_purged', postData); websockets.in('topic_' + postData.tid).emit('event:post_purged', postData);
const topicData = await topics.getTopicFields(data.tid, ['title', 'cid']); const topicData = await topics.getTopicFields(postData.tid, ['title', 'cid']);
await events.log({ await events.log({
type: 'post-purge', type: 'post-purge',

@ -416,7 +416,7 @@ describe('Post\'s', function () {
}); });
it('should delete posts', function (done) { it('should delete posts', function (done) {
socketPosts.deletePosts({ uid: globalModUid }, { pids: [replyPid, mainPid], tid: tid }, function (err) { socketPosts.deletePosts({ uid: globalModUid }, { pids: [replyPid, mainPid] }, function (err) {
assert.ifError(err); assert.ifError(err);
posts.getPostField(replyPid, 'deleted', function (err, deleted) { posts.getPostField(replyPid, 'deleted', function (err, deleted) {
assert.ifError(err); assert.ifError(err);
@ -433,7 +433,7 @@ describe('Post\'s', function () {
it('should delete topic if last main post is deleted', function (done) { it('should delete topic if last main post is deleted', function (done) {
topics.post({ uid: voterUid, cid: cid, title: 'test topic', content: 'test topic' }, function (err, data) { topics.post({ uid: voterUid, cid: cid, title: 'test topic', content: 'test topic' }, function (err, data) {
assert.ifError(err); assert.ifError(err);
socketPosts.deletePosts({ uid: globalModUid }, { pids: [data.postData.pid], tid: data.topicData.tid }, function (err) { socketPosts.deletePosts({ uid: globalModUid }, { pids: [data.postData.pid] }, function (err) {
assert.ifError(err); assert.ifError(err);
topics.getTopicField(data.topicData.tid, 'deleted', function (err, deleted) { topics.getTopicField(data.topicData.tid, 'deleted', function (err, deleted) {
assert.ifError(err); assert.ifError(err);

Loading…
Cancel
Save