Jelajahi Sumber

Remove duplicate mentions

sbkwgh 8 tahun lalu
induk
melakukan
fc16b8257a
1 mengubah file dengan 6 tambahan dan 2 penghapusan
  1. 6 2
      routes/post.js

+ 6 - 2
routes/post.js

@@ -170,8 +170,12 @@ router.post('/', async (req, res) => {
 		await thread.increment('postsCount')
 
 		if(req.body.mentions) {
-			for(var i = 0; i < req.body.mentions.length; i++) {
-				let mention = req.body.mentions[i]
+			let uniqueMentions = req.body.mentions.filter((mention, pos, self) => {
+				return self.indexOf(mention) === pos
+			})
+
+			for(var i = 0; i < uniqueMentions.length; i++) {
+				let mention = uniqueMentions[i]
 				let ioUsers = req.app.get('io-users')
 
 				let mentionNotification = await Notification.createPostNotification({