mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	closes #1679
This commit is contained in:
		| @@ -51,7 +51,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/ | ||||
| 		var bookmark = localStorage.getItem('topic:' + tid + ':bookmark'); | ||||
| 		var postIndex = getPostIndex(); | ||||
| 		if (postIndex) { | ||||
| 			Topic.scrollToPost(postIndex, true); | ||||
| 			Topic.scrollToPost(postIndex - 1, true); | ||||
| 		} else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && postCount > 1) { | ||||
| 			app.alert({ | ||||
| 				alert_id: 'bookmark', | ||||
| @@ -96,7 +96,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/ | ||||
|  | ||||
| 	function getPostIndex() { | ||||
| 		var parts = window.location.pathname.split('/'); | ||||
| 		return parts[4] ? (parseInt(parts[4], 10) - 1) : ''; | ||||
| 		return parts[4] ? parseInt(parts[4], 10) : 0; | ||||
| 	} | ||||
|  | ||||
| 	function showBottomPostBar() { | ||||
| @@ -194,7 +194,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/ | ||||
| 	}; | ||||
|  | ||||
| 	Topic.scrollToPost = function(postIndex, highlight, duration, offset) { | ||||
| 		if (!postIndex) { | ||||
| 		if (!utils.isNumber(postIndex)) { | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -151,7 +151,7 @@ define('composer', ['taskbar', 'composer/controls', 'composer/uploads', 'compose | ||||
| 				title: threadData.title, | ||||
| 				body: threadData.body, | ||||
| 				modified: false, | ||||
| 				isMain: !threadData.index, | ||||
| 				isMain: threadData.isMain, | ||||
| 				topic_thumb: threadData.topic_thumb, | ||||
| 				tags: threadData.tags | ||||
| 			}); | ||||
|   | ||||
| @@ -88,7 +88,7 @@ middleware.checkPostIndex = function(req, res, next) { | ||||
| 		postCount = parseInt(postCount, 10) + 1; | ||||
| 		if (postIndex > postCount) { | ||||
| 			return res.locals.isAPI ? res.json(302, '/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount) : res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount); | ||||
| 		} else if (postIndex <= 1) { | ||||
| 		} else if (postIndex < 1) { | ||||
| 			return res.locals.isAPI ? res.json(302, '/topic/' + req.params.topic_id + '/' + req.params.slug) : res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug); | ||||
| 		} | ||||
| 		next(); | ||||
|   | ||||
							
								
								
									
										12
									
								
								src/posts.js
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/posts.js
									
									
									
									
									
								
							| @@ -275,7 +275,7 @@ var async = require('async'), | ||||
| 				post.user = results.user; | ||||
| 				post.topic = results.topicCategory.topic; | ||||
| 				post.category = results.topicCategory.category; | ||||
| 				post.index = parseInt(results.index, 10) + 1; | ||||
| 				post.index = results.index; | ||||
|  | ||||
| 				if (stripTags) { | ||||
| 					var s = S(results.content); | ||||
| @@ -444,10 +444,13 @@ var async = require('async'), | ||||
| 			}, | ||||
| 			function(result, next) { | ||||
| 				index = result; | ||||
| 				if (index === 1) { | ||||
| 					return callback(null, 1); | ||||
| 				} | ||||
| 				user.getSettings(uid, next); | ||||
| 			}, | ||||
| 			function(settings, next) { | ||||
| 				next(null, Math.ceil((index + 1) / settings.postsPerPage)); | ||||
| 				next(null, Math.ceil((index - 1) / settings.postsPerPage)); | ||||
| 			} | ||||
| 		], callback); | ||||
| 	}; | ||||
| @@ -459,7 +462,10 @@ var async = require('async'), | ||||
| 			} | ||||
|  | ||||
| 			db.sortedSetRank('tid:' + tid + ':posts', pid, function(err, index) { | ||||
| 				callback(err, parseInt(index, 10) + 1); | ||||
| 				if (!utils.isNumber(index)) { | ||||
| 					return callback(err, 1); | ||||
| 				} | ||||
| 				callback(err, parseInt(index, 10) + 2); | ||||
| 			}); | ||||
| 		}); | ||||
| 	}; | ||||
|   | ||||
| @@ -61,8 +61,8 @@ SocketModules.composer.push = function(socket, pid, callback) { | ||||
| 			tags: function(next) { | ||||
| 				topics.getTopicTags(postData.tid, next); | ||||
| 			}, | ||||
| 			index: function(next) { | ||||
| 				posts.getPidIndex(pid, next); | ||||
| 			isMain: function(next) { | ||||
| 				postTools.isMain(pid, next); | ||||
| 			} | ||||
| 		}, function(err, results) { | ||||
| 			if(err) { | ||||
| @@ -75,7 +75,7 @@ SocketModules.composer.push = function(socket, pid, callback) { | ||||
| 				title: results.topic.title, | ||||
| 				topic_thumb: results.topic.thumb, | ||||
| 				tags: results.tags, | ||||
| 				index: results.index | ||||
| 				isMain: results.isMain | ||||
| 			}); | ||||
| 		}); | ||||
| 	}); | ||||
|   | ||||
| @@ -114,14 +114,9 @@ function sendNotificationToPostOwner(data, uid, notification) { | ||||
| 					return; | ||||
| 				} | ||||
|  | ||||
| 				var path = nconf.get('relative_path') + '/topic/' + results.slug; | ||||
| 				if (parseInt(results.index, 10)) { | ||||
| 					path += '/' + (parseInt(results.index, 10) + 1); | ||||
| 				} | ||||
|  | ||||
| 				notifications.create({ | ||||
| 					text: '[[' + notification + ', ' + results.username + ']]', | ||||
| 					path: path, | ||||
| 					path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index, | ||||
| 					uniqueId: 'post:' + data.pid, | ||||
| 					from: uid | ||||
| 				}, function(nid) { | ||||
| @@ -306,7 +301,7 @@ SocketPosts.flag = function(socket, pid, callback) { | ||||
| 			posts.getPidIndex(pid, next); | ||||
| 		}, | ||||
| 		function(postIndex, next) { | ||||
| 			path += '/' + (parseInt(postIndex, 10) + 1); | ||||
| 			path += '/' + postIndex; | ||||
| 			groups.get('administrators', {}, next); | ||||
| 		}, | ||||
| 		function(adminGroup, next) { | ||||
|   | ||||
| @@ -367,7 +367,7 @@ var async = require('async'), | ||||
| 				} | ||||
|  | ||||
| 				results.postData.timestamp = utils.toISOString(results.postData.timestamp); | ||||
| 				results.postData.index = parseInt(results.postIndex, 10) + 1; | ||||
| 				results.postData.index = results.postIndex; | ||||
|  | ||||
| 				callback(null, results.postData); | ||||
| 			}); | ||||
|   | ||||
| @@ -239,7 +239,7 @@ module.exports = function(Topics) { | ||||
| 				posts.getPidIndex(postData.pid, next); | ||||
| 			}, | ||||
| 			function(index, next) { | ||||
| 				postData.index = index; | ||||
| 				postData.index = index - 1; | ||||
| 				postData.favourited = false; | ||||
| 				postData.votes = 0; | ||||
| 				postData.display_moderator_tools = true; | ||||
|   | ||||
| @@ -38,13 +38,9 @@ module.exports = function(Topics) { | ||||
| 						return next(err); | ||||
| 					} | ||||
|  | ||||
| 					var path = nconf.get('relative_path') + '/topic/' + results.topicData.slug; | ||||
| 					if (parseInt(results.postIndex, 10)) { | ||||
| 						path += '/' + (parseInt(results.postIndex, 10) + 1); | ||||
| 					} | ||||
| 					notifications.create({ | ||||
| 						text: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]', | ||||
| 						path: path, | ||||
| 						path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex, | ||||
| 						uniqueId: 'topic:' + tid, | ||||
| 						from: exceptUid | ||||
| 					}, function(nid) { | ||||
|   | ||||
| @@ -167,14 +167,9 @@ var async = require('async'), | ||||
| 					return; | ||||
| 				} | ||||
|  | ||||
| 				var message = '[[notifications:user_made_post, ' + results.username + ']]'; | ||||
| 				var path = nconf.get('relative_path') + '/topic/' + results.slug; | ||||
| 				if (parseInt(results.postIndex, 10)) { | ||||
| 					path += '/' + (parseInt(results.postIndex, 10) + 1); | ||||
| 				} | ||||
| 				notifications.create({ | ||||
| 					text: message, | ||||
| 					path: path, | ||||
| 					text: '[[notifications:user_made_post, ' + results.username + ']]', | ||||
| 					path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.postIndex, | ||||
| 					uniqueId: 'topic:' + tid, | ||||
| 					from: uid | ||||
| 				}, function(nid) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user