mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +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); | ||||
| } | ||||
|  | ||||
| SocketPosts.getRawPost = function (socket, pid, callback) { | ||||
| 	async.waterfall([ | ||||
| 		function (next) { | ||||
| 			privileges.posts.can('topics:read', pid, socket.uid, next); | ||||
| 		}, | ||||
| 		function (canRead, next) { | ||||
| SocketPosts.getRawPost = async (socket, pid) => { | ||||
| 	const canRead = await privileges.posts.can('topics:read', pid, socket.uid); | ||||
| 	if (!canRead) { | ||||
| 				return next(new Error('[[error:no-privileges]]')); | ||||
| 		throw new Error('[[error:no-privileges]]'); | ||||
| 	} | ||||
| 			posts.getPostFields(pid, ['content', 'deleted'], next); | ||||
| 		}, | ||||
| 		function (postData, next) { | ||||
|  | ||||
| 	let postData = await posts.getPostFields(pid, ['content', 'deleted']); | ||||
| 	if (postData.deleted) { | ||||
| 				return next(new Error('[[error:no-post]]')); | ||||
| 		throw new Error('[[error:no-post]]'); | ||||
| 	} | ||||
| 			next(null, postData.content); | ||||
| 		}, | ||||
| 	], callback); | ||||
|  | ||||
| 	postData = await plugins.fireHook('filter:post.getRawPost', Object.assign(postData, { | ||||
| 		pid: pid, | ||||
| 	})); | ||||
|  | ||||
| 	return postData.content; | ||||
| }; | ||||
|  | ||||
| SocketPosts.getTimestampByIndex = function (socket, data, callback) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user