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