From 1b518f0eb21b51ac09bf7516bda1f45ea7d635a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 1 Mar 2026 12:55:00 -0500 Subject: [PATCH] refactor: more cid parseInt changes --- install/package.json | 2 +- public/src/admin/manage/categories.js | 12 ++++++------ public/src/admin/manage/category.js | 2 +- public/src/admin/manage/group.js | 12 ++++++++---- public/src/client/groups/details.js | 13 +++++++++---- public/src/client/unread.js | 4 +--- public/src/modules/topicList.js | 8 ++++---- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/install/package.json b/install/package.json index 5547e7c64e..cde6256eb3 100644 --- a/install/package.json +++ b/install/package.json @@ -97,7 +97,7 @@ "multer": "2.0.2", "nconf": "0.13.0", "nodebb-plugin-2factor": "7.6.1", - "nodebb-plugin-composer-default": "10.3.22", + "nodebb-plugin-composer-default": "10.3.23", "nodebb-plugin-dbsearch": "6.4.0", "nodebb-plugin-emoji": "6.0.5", "nodebb-plugin-emoji-android": "4.1.1", diff --git a/public/src/admin/manage/categories.js b/public/src/admin/manage/categories.js index a8a6a2fb28..babdb83367 100644 --- a/public/src/admin/manage/categories.js +++ b/public/src/admin/manage/categories.js @@ -11,7 +11,7 @@ define('admin/manage/categories', [ ], function (translator, Benchpress, categorySelector, api, Sortable, bootbox, alerts) { Sortable = Sortable.default; const Categories = {}; - let newCategoryId = -1; + let newCategoryId = '-1'; let sortables; Categories.init = function () { @@ -261,15 +261,15 @@ define('admin/manage/categories', [ }; function itemDidAdd(e) { - newCategoryId = e.to.dataset.cid; + newCategoryId = String(e.to.dataset.cid); } function itemDragDidEnd(e) { - const isCategoryUpdate = parseInt(newCategoryId, 10) !== -1; + const isCategoryUpdate = String(newCategoryId) !== '-1'; // Update needed? if ((e.newIndex != null && parseInt(e.oldIndex, 10) !== parseInt(e.newIndex, 10)) || isCategoryUpdate) { - const cid = e.item.dataset.cid; + const cid = String(e.item.dataset.cid); const modified = {}; // on page 1 baseIndex is 0, on page n baseIndex is (n - 1) * ajaxify.data.categoriesPerPage // this makes sure order is correct when drag & drop is used on pages > 1 @@ -282,8 +282,8 @@ define('admin/manage/categories', [ modified[cid].parentCid = newCategoryId; // Show/hide expand buttons after drag completion - const oldParentCid = parseInt(e.from.getAttribute('data-cid'), 10); - const newParentCid = parseInt(e.to.getAttribute('data-cid'), 10); + const oldParentCid = String(e.from.getAttribute('data-cid') || ''); + const newParentCid = String(e.to.getAttribute('data-cid') || ''); if (oldParentCid !== newParentCid) { const toggle = document.querySelector(`.categories li[data-cid="${newParentCid}"] .toggle`); if (toggle) { diff --git a/public/src/admin/manage/category.js b/public/src/admin/manage/category.js index 7a6e85486e..d75318a4fd 100644 --- a/public/src/admin/manage/category.js +++ b/public/src/admin/manage/category.js @@ -160,7 +160,7 @@ define('admin/manage/category', [ label: '[[modules:bootbox.confirm]]', className: 'btn-primary', callback: function () { - if (!selectedCid || parseInt(selectedCid, 10) === parseInt(ajaxify.data.category.cid, 10)) { + if (!selectedCid || String(selectedCid) === String(ajaxify.data.category.cid)) { return; } diff --git a/public/src/admin/manage/group.js b/public/src/admin/manage/group.js index c856f0b487..fc68fc8f63 100644 --- a/public/src/admin/manage/group.js +++ b/public/src/admin/manage/group.js @@ -68,10 +68,14 @@ define('admin/manage/group', [ const cidSelector = categorySelector.init($('.member-post-cids-selector [component="category-selector"]'), { onSelect: function (selectedCategory) { - let cids = ($('#memberPostCids').val() || '').split(',').map(cid => parseInt(cid, 10)); - cids.push(selectedCategory.cid); - cids = cids.filter((cid, index, array) => array.indexOf(cid) === index); - $('#memberPostCids').val(cids.join(',')); + const cids = new Set(($('#memberPostCids').val() || '').split(',').filter(Boolean)); + if (cids.has(String(selectedCategory.cid))) { + cids.delete(String(selectedCategory.cid)); + } else { + cids.add(String(selectedCategory.cid)); + } + + $('#memberPostCids').val(Array.from(cids).join(',')); cidSelector.selectCategory(0); return false; }, diff --git a/public/src/client/groups/details.js b/public/src/client/groups/details.js index 9ed57cd6ed..39395258cb 100644 --- a/public/src/client/groups/details.js +++ b/public/src/client/groups/details.js @@ -233,11 +233,16 @@ define('forum/groups/details', [ const cidSelector = categorySelector.init($('.member-post-cids-selector [component="category-selector"]'), { onSelect: function (selectedCategory) { - let cids = ($('#memberPostCids').val() || '').split(',').map(cid => parseInt(cid, 10)); - cids.push(selectedCategory.cid); - cids = cids.filter((cid, index, array) => array.indexOf(cid) === index); - $('#memberPostCids').val(cids.join(',')); + const cids = new Set(($('#memberPostCids').val() || '').split(',').filter(Boolean)); + if (cids.has(String(selectedCategory.cid))) { + cids.delete(String(selectedCategory.cid)); + } else { + cids.add(String(selectedCategory.cid)); + } + + $('#memberPostCids').val(Array.from(cids).join(',')); cidSelector.selectCategory(0); + return false; }, }); }; diff --git a/public/src/client/unread.js b/public/src/client/unread.js index 6851ba1ec4..d0b6428dc8 100644 --- a/public/src/client/unread.js +++ b/public/src/client/unread.js @@ -65,9 +65,7 @@ define('forum/unread', [ // Generate list of default categories based on topic list let defaultCategories = ajaxify.data.topics.reduce((map, topic) => { const { category } = topic; - let { cid } = category; - cid = utils.isNumber(cid) ? parseInt(cid, 10) : cid; - map.set(cid, category); + map.set(String(category.cid), category); return map; }, new Map()); defaultCategories = Array.from(defaultCategories.values()); diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.js index 4af7eee9c5..1d026c1719 100644 --- a/public/src/modules/topicList.js +++ b/public/src/modules/topicList.js @@ -95,11 +95,11 @@ define('topicList', [ const categories = d.selectedCids && d.selectedCids.length && - d.selectedCids.indexOf(parseInt(data.cid, 10)) === -1; + !d.selectedCids.includes(parseInt(data.cid, 10)); const filterWatched = d.selectedFilter && d.selectedFilter.filter === 'watched'; const category = d.template.category && - parseInt(d.cid, 10) !== parseInt(data.cid, 10); + String(d.cid) !== String(data.cid); const preventAlert = !!(categories || filterWatched || category || scheduledTopics.includes(data.tid)); hooks.fire('filter:topicList.onNewTopic', { topic: data, preventAlert }).then((result) => { @@ -126,14 +126,14 @@ define('topicList', [ const isMain = parseInt(post.topic.mainPid, 10) === parseInt(post.pid, 10); const categories = d.selectedCids && d.selectedCids.length && - d.selectedCids.indexOf(parseInt(post.topic.cid, 10)) === -1; + !d.selectedCids.includes(parseInt(post.topic.cid, 10)); const filterNew = d.selectedFilter && d.selectedFilter.filter === 'new'; const filterWatched = d.selectedFilter && d.selectedFilter.filter === 'watched' && !post.topic.isFollowing; const category = d.template.category && - parseInt(d.cid, 10) !== parseInt(post.topic.cid, 10); + String(d.cid) !== String(post.topic.cid); const preventAlert = !!(isMain || categories || filterNew || filterWatched || category); hooks.fire('filter:topicList.onNewPost', { post, preventAlert }).then((result) => {