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) {
btn.attr('disabled', true);
socket.emit(command, {
tid: ajaxify.data.tid,
pids: postSelect.pids,
}, function (err) {
btn.removeAttr('disabled');

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

@ -89,7 +89,7 @@ module.exports = function (SocketPosts) {
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({
type: params.type,
@ -114,7 +114,7 @@ module.exports = function (SocketPosts) {
}
for (const pid of data.pids) {
/* 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);
websockets.in('topic_' + data.tid).emit('event:post_purged', postData);
const topicData = await topics.getTopicFields(data.tid, ['title', 'cid']);
websockets.in('topic_' + postData.tid).emit('event:post_purged', postData);
const topicData = await topics.getTopicFields(postData.tid, ['title', 'cid']);
await events.log({
type: 'post-purge',

@ -416,7 +416,7 @@ describe('Post\'s', function () {
});
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);
posts.getPostField(replyPid, 'deleted', function (err, deleted) {
assert.ifError(err);
@ -433,7 +433,7 @@ describe('Post\'s', function () {
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) {
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);
topics.getTopicField(data.topicData.tid, 'deleted', function (err, deleted) {
assert.ifError(err);

Loading…
Cancel
Save