mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #13135, tids are not numeric for ap topics
this fixes other issues like posts not disappearing when purged and many others
This commit is contained in:
@@ -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');
|
||||
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]]');
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user