Skip to content

Commit

Permalink
refactor: remove posts.tools.purge
Browse files Browse the repository at this point in the history
moved the check to socketPosts.purge
  • Loading branch information
barisusakli committed Oct 6, 2020
1 parent dde5b6b commit ed092bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
9 changes: 0 additions & 9 deletions src/posts/tools.js
Expand Up @@ -41,13 +41,4 @@ module.exports = function (Posts) {
}
return post;
}

Posts.tools.purge = async function (uid, pid) {
const canPurge = await privileges.posts.canPurge(pid, uid);
if (!canPurge) {
throw new Error('[[error:no-privileges]]');
}
require('./cache').del(pid);
await Posts.purge(pid, uid);
};
};
7 changes: 6 additions & 1 deletion src/socket.io/posts/tools.js
Expand Up @@ -131,7 +131,12 @@ module.exports = function (SocketPosts) {
const postData = await posts.getPostFields(data.pid, ['toPid', 'tid']);
postData.pid = data.pid;

await posts.tools.purge(socket.uid, data.pid);
const canPurge = await privileges.posts.canPurge(data.pid, socket.uid);
if (!canPurge) {
throw new Error('[[error:no-privileges]]');
}
require('../../posts/cache').del(data.pid);
await posts.purge(data.pid, socket.uid);

websockets.in('topic_' + postData.tid).emit('event:post_purged', postData);
const topicData = await topics.getTopicFields(postData.tid, ['title', 'cid']);
Expand Down

0 comments on commit ed092bf

Please sign in to comment.