mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	Merge branch 'master' of https://github.com/NodeBB/NodeBB
This commit is contained in:
		| @@ -9,6 +9,7 @@ const _ = require('lodash'); | |||||||
|  |  | ||||||
| const db = require('./database'); | const db = require('./database'); | ||||||
| const User = require('./user'); | const User = require('./user'); | ||||||
|  | const categories = require('./categories'); | ||||||
| const posts = require('./posts'); | const posts = require('./posts'); | ||||||
| const groups = require('./groups'); | const groups = require('./groups'); | ||||||
| const meta = require('./meta'); | const meta = require('./meta'); | ||||||
| @@ -84,7 +85,24 @@ Notifications.getMultiple = async function (nids) { | |||||||
| 	const notifications = await db.getObjects(keys); | 	const notifications = await db.getObjects(keys); | ||||||
|  |  | ||||||
| 	const userKeys = notifications.map(n => n && n.from); | 	const userKeys = notifications.map(n => n && n.from); | ||||||
| 	const usersData = await User.getUsersFields(userKeys, ['username', 'userslug', 'picture']); | 	let [usersData, categoriesData] = await Promise.all([ | ||||||
|  | 		User.getUsersFields(userKeys, ['username', 'userslug', 'picture']), | ||||||
|  | 		categories.getCategoriesFields(userKeys, ['cid', 'name', 'slug', 'picture']), | ||||||
|  | 	]); | ||||||
|  | 	// Merge valid categoriesData into usersData | ||||||
|  | 	usersData = usersData.map((userData, idx) => { | ||||||
|  | 		const categoryData = categoriesData[idx]; | ||||||
|  | 		if (!userData.uid && categoryData.cid) { | ||||||
|  | 			return { | ||||||
|  | 				username: categoryData.slug, | ||||||
|  | 				displayname: categoryData.name, | ||||||
|  | 				userslug: categoryData.slug, | ||||||
|  | 				picture: categoryData.picture, | ||||||
|  | 			}; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		return userData; | ||||||
|  | 	}); | ||||||
|  |  | ||||||
| 	notifications.forEach((notification, index) => { | 	notifications.forEach((notification, index) => { | ||||||
| 		if (notification) { | 		if (notification) { | ||||||
|   | |||||||
| @@ -94,7 +94,10 @@ SocketHelpers.sendNotificationToPostOwner = async function (pid, fromuid, comman | |||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	fromuid = utils.isNumber(fromuid) ? parseInt(fromuid, 10) : fromuid; | 	fromuid = utils.isNumber(fromuid) ? parseInt(fromuid, 10) : fromuid; | ||||||
| 	const postData = await posts.getPostFields(pid, ['tid', 'uid', 'content']); | 	const [postData, fromCategory] = await Promise.all([ | ||||||
|  | 		posts.getPostFields(pid, ['tid', 'uid', 'content']), | ||||||
|  | 		!utils.isNumber(fromuid) && categories.exists(fromuid), | ||||||
|  | 	]); | ||||||
| 	const [canRead, isIgnoring] = await Promise.all([ | 	const [canRead, isIgnoring] = await Promise.all([ | ||||||
| 		privileges.posts.can('topics:read', pid, postData.uid), | 		privileges.posts.can('topics:read', pid, postData.uid), | ||||||
| 		topics.isIgnoring([postData.tid], postData.uid), | 		topics.isIgnoring([postData.tid], postData.uid), | ||||||
| @@ -103,19 +106,17 @@ SocketHelpers.sendNotificationToPostOwner = async function (pid, fromuid, comman | |||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	const [userData, topicTitle, postObj] = await Promise.all([ | 	const [userData, topicTitle, postObj] = await Promise.all([ | ||||||
| 		user.getUserFields(fromuid, ['username']), | 		fromCategory ? categories.getCategoryFields(fromuid, ['name']) : user.getUserFields(fromuid, ['username']), | ||||||
| 		topics.getTopicField(postData.tid, 'title'), | 		topics.getTopicField(postData.tid, 'title'), | ||||||
| 		posts.parsePost(postData), | 		posts.parsePost(postData), | ||||||
| 	]); | 	]); | ||||||
|  |  | ||||||
| 	const { displayname } = userData; |  | ||||||
|  |  | ||||||
| 	const title = utils.decodeHTMLEntities(topicTitle); | 	const title = utils.decodeHTMLEntities(topicTitle); | ||||||
| 	const titleEscaped = title.replace(/%/g, '%').replace(/,/g, ','); | 	const titleEscaped = title.replace(/%/g, '%').replace(/,/g, ','); | ||||||
|  |  | ||||||
| 	const notifObj = await notifications.create({ | 	const notifObj = await notifications.create({ | ||||||
| 		type: command, | 		type: command, | ||||||
| 		bodyShort: `[[${notification}, ${displayname}, ${titleEscaped}]]`, | 		bodyShort: `[[${notification}, ${userData.displayname || userData.name}, ${titleEscaped}]]`, | ||||||
| 		bodyLong: postObj.content, | 		bodyLong: postObj.content, | ||||||
| 		pid: pid, | 		pid: pid, | ||||||
| 		tid: postData.tid, | 		tid: postData.tid, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user