mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-20 23:40:38 +01:00
refactor: rewrote SocketPosts.getRawPost in await style
Added new filter hook filter:post.getRawPost
This commit is contained in:
@@ -70,24 +70,22 @@ function postReply(socket, data, callback) {
|
|||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketPosts.getRawPost = function (socket, pid, callback) {
|
SocketPosts.getRawPost = async (socket, pid) => {
|
||||||
async.waterfall([
|
const canRead = await privileges.posts.can('topics:read', pid, socket.uid);
|
||||||
function (next) {
|
|
||||||
privileges.posts.can('topics:read', pid, socket.uid, next);
|
|
||||||
},
|
|
||||||
function (canRead, next) {
|
|
||||||
if (!canRead) {
|
if (!canRead) {
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
throw new Error('[[error:no-privileges]]');
|
||||||
}
|
}
|
||||||
posts.getPostFields(pid, ['content', 'deleted'], next);
|
|
||||||
},
|
let postData = await posts.getPostFields(pid, ['content', 'deleted']);
|
||||||
function (postData, next) {
|
|
||||||
if (postData.deleted) {
|
if (postData.deleted) {
|
||||||
return next(new Error('[[error:no-post]]'));
|
throw new Error('[[error:no-post]]');
|
||||||
}
|
}
|
||||||
next(null, postData.content);
|
|
||||||
},
|
postData = await plugins.fireHook('filter:post.getRawPost', Object.assign(postData, {
|
||||||
], callback);
|
pid: pid,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return postData.content;
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.getTimestampByIndex = function (socket, data, callback) {
|
SocketPosts.getTimestampByIndex = function (socket, data, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user