Node.js based forum software built for the modern web
fix: #13135, tids are not numeric for ap topics
Barış Soner Uşaklıd687f0810cb8
diff --git a/public/src/client/topic.js b/public/src/client/topic.jsindex c11ece6f94..be32f5cd2c 100644--- a/public/src/client/topic.js+++ b/public/src/client/topic.js@@ -24,7 +24,7 @@ define('forum/topic', [bootbox, clipboard) {const Topic = {};- let tid = 0;+ let tid = '0';let currentUrl = '';$(window).on('action:ajaxify.start', function (ev, data) {@@ -38,8 +38,8 @@ define('forum/topic', [});Topic.init = async function () {- const tidChanged = !tid || parseInt(tid, 10) !== parseInt(ajaxify.data.tid, 10);- tid = ajaxify.data.tid;+ const tidChanged = !tid || String(tid) !== String(ajaxify.data.tid);+ tid = String(ajaxify.data.tid);currentUrl = ajaxify.currentPage;hooks.fire('action:topic.loading');diff --git a/public/src/client/topic/events.js b/public/src/client/topic/events.jsindex 4fdfcdbf4d..5b45deeb54 100644--- a/public/src/client/topic/events.js+++ b/public/src/client/topic/events.js@@ -80,7 +80,7 @@ define('forum/topic/events', [function updateBookmarkCount(data) {$('[data-pid="' + data.post.pid + '"] .bookmarkCount').filter(function (index, el) {- return parseInt($(el).closest('[data-pid]').attr('data-pid'), 10) === parseInt(data.post.pid, 10);+ return $(el).closest('[data-pid]').attr('data-pid') === String(data.post.pid);}).html(data.post.bookmarks).attr('data-bookmarks', data.post.bookmarks);}@@ -88,14 +88,14 @@ define('forum/topic/events', [if (ajaxify.data.category &&ajaxify.data.category.slug &&- parseInt(data.tid, 10) === parseInt(ajaxify.data.tid, 10)+ String(data.tid) === String(ajaxify.data.tid)) {ajaxify.go('category/' + ajaxify.data.category.slug, null, true);}}function onTopicMoved(data) {- if (data && data.slug && parseInt(data.tid, 10) === parseInt(ajaxify.data.tid, 10)) {+ if (data && data.slug && String(data.tid) === String(ajaxify.data.tid)) {ajaxify.go('topic/' + data.slug, null, true);}}@@ -184,7 +184,7 @@ define('forum/topic/events', [}function onPostPurged(postData) {- if (!postData || parseInt(postData.tid, 10) !== parseInt(ajaxify.data.tid, 10)) {+ if (!postData || String(postData.tid) !== String(ajaxify.data.tid)) {return;}components.get('post', 'pid', postData.pid).fadeOut(500, function () {@@ -234,7 +234,7 @@ define('forum/topic/events', [function togglePostBookmark(data) {const el = $('[data-pid="' + data.post.pid + '"] [component="post/bookmark"]').filter(function (index, el) {- return parseInt($(el).closest('[data-pid]').attr('data-pid'), 10) === parseInt(data.post.pid, 10);+ return $(el).closest('[data-pid]').attr('data-pid') === String(data.post.pid);});if (!el.length) {return;@@ -258,7 +258,7 @@ define('forum/topic/events', [function onNewNotification(data) {const tid = ajaxify.data.tid;- if (data && data.tid && parseInt(data.tid, 10) === parseInt(tid, 10)) {+ if (data && data.tid && String(data.tid) === String(tid)) {socket.emit('topics.markTopicNotificationsRead', [tid]);}}diff --git a/public/src/client/topic/move-post.js b/public/src/client/topic/move-post.jsindex 3c154b9374..62863f16bf 100644--- a/public/src/client/topic/move-post.js+++ b/public/src/client/topic/move-post.js@@ -74,7 +74,7 @@ define('forum/topic/move-post', [const tidInput = moveModal.find('#topicId');let targetTid = null;if (ajaxify.data.template.topic && ajaxify.data.tid &&- parseInt(ajaxify.data.tid, 10) !== fromTid+ String(ajaxify.data.tid) !== String(fromTid)) {targetTid = ajaxify.data.tid;}@@ -98,8 +98,8 @@ define('forum/topic/move-post', [}const targetTid = getTargetTid();if (postSelect.pids.length) {- if (targetTid && parseInt(targetTid, 10) !== parseInt(fromTid, 10)) {- api.get('/topics/' + targetTid, {}).then(function (data) {+ if (targetTid && String(targetTid) !== String(fromTid)) {+ api.get(`/topics/${targetTid}`, {}).then(function (data) {if (!data || !data.tid) {return alerts.error('[[error:no-topic]]');}@@ -123,7 +123,7 @@ define('forum/topic/move-post', [}const targetTid = getTargetTid();if (postSelect.pids.length && targetTid &&- parseInt(targetTid, 10) !== parseInt(fromTid, 10)+ String(targetTid) !== String(fromTid)) {moveCommit.removeAttr('disabled');} else {@@ -150,7 +150,7 @@ define('forum/topic/move-post', [});});if (data.pids.length && ajaxify.data.template.topic &&- parseInt(data.tid, 10) === parseInt(ajaxify.data.tid, 10)) {+ String(data.tid) === String(ajaxify.data.tid)) {ajaxify.go(`/post/${data.pids[0]}`);}closeMoveModal();diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.jsindex b88dc73608..3f9840ebcf 100644--- a/public/src/client/topic/posts.js+++ b/public/src/client/topic/posts.js@@ -22,7 +22,7 @@ define('forum/topic/posts', [!data ||!data.posts ||!data.posts.length ||- parseInt(data.posts[0].tid, 10) !== parseInt(ajaxify.data.tid, 10)+ String(data.posts[0].tid) !== String(ajaxify.data.tid)) {return;}diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.jsindex a66b293a73..38db844cdd 100644--- a/public/src/client/topic/threadTools.js+++ b/public/src/client/topic/threadTools.js@@ -294,7 +294,7 @@ define('forum/topic/threadTools', [ThreadTools.setLockedState = function (data) {const threadEl = components.get('topic');- if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {+ if (String(data.tid) !== threadEl.attr('data-tid')) {return;}@@ -322,7 +322,7 @@ define('forum/topic/threadTools', [ThreadTools.setDeleteState = function (data) {const threadEl = components.get('topic');- if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {+ if (String(data.tid) !== threadEl.attr('data-tid')) {return;}@@ -356,7 +356,7 @@ define('forum/topic/threadTools', [ThreadTools.setPinnedState = function (data) {const threadEl = components.get('topic');- if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {+ if (String(data.tid) !== threadEl.attr('data-tid')) {return;}diff --git a/src/posts/queue.js b/src/posts/queue.jsindex 91fab2e6e9..cc3b1078c8 100644--- a/src/posts/queue.js+++ b/src/posts/queue.js@@ -61,9 +61,9 @@ module.exports = function (Posts) {const tid = String(filter.tid);postData = postData.filter(item => item.data.tid && String(item.data.tid) === tid);} else if (Array.isArray(filter.tid)) {- const tids = filter.tid.map(tid => parseInt(tid, 10));+ const tids = filter.tid.map(String);postData = postData.filter(- item => item.data.tid && tids.includes(parseInt(item.data.tid, 10))+ item => item.data.tid && tids.includes(String(item.data.tid)));}diff --git a/src/posts/user.js b/src/posts/user.jsindex b92aca8a9a..d096b0fa50 100644--- a/src/posts/user.js+++ b/src/posts/user.js@@ -200,9 +200,9 @@ module.exports = function (Posts) {}async function updateTopicPosters(postData, toUid) {- const postsByTopic = _.groupBy(postData, p => parseInt(p.tid, 10));+ const postsByTopic = _.groupBy(postData, p => String(p.tid));await async.eachOf(postsByTopic, async (posts, tid) => {- const postsByUser = _.groupBy(posts, p => parseInt(p.uid, 10));+ const postsByUser = _.groupBy(posts, p => String(p.uid));await db.sortedSetIncrBy(`tid:${tid}:posters`, posts.length, toUid);await async.eachOf(postsByUser, async (posts, uid) => {await db.sortedSetIncrBy(`tid:${tid}:posters`, -posts.length, uid);diff --git a/src/topics/fork.js b/src/topics/fork.jsindex 07111eecd1..d86322a9df 100644--- a/src/topics/fork.js+++ b/src/topics/fork.js@@ -91,7 +91,7 @@ module.exports = function (Topics) {};Topics.movePostToTopic = async function (callerUid, pid, tid, forceScheduled = false) {- tid = parseInt(tid, 10);+ tid = String(tid);const topicData = await Topics.getTopicFields(tid, ['tid', 'scheduled']);if (!topicData.tid) {throw new Error('[[error:no-topic]]');@@ -109,7 +109,7 @@ module.exports = function (Topics) {throw new Error('[[error:cant-move-from-scheduled-to-existing]]');}- if (postData.tid === tid) {+ if (String(postData.tid) === String(tid)) {throw new Error('[[error:cant-move-to-same-topic]]');}diff --git a/src/topics/merge.js b/src/topics/merge.jsindex 1a06adefbb..7812a3d4e4 100644--- a/src/topics/merge.js+++ b/src/topics/merge.js@@ -21,7 +21,7 @@ module.exports = function (Topics) {}const otherTids = tids.sort((a, b) => a - b)- .filter(tid => tid && parseInt(tid, 10) !== parseInt(mergeIntoTid, 10));+ .filter(tid => tid && String(tid) !== String(mergeIntoTid));for (const tid of otherTids) {/* eslint-disable no-await-in-loop */