Skip to content

Node.js based forum software built for the modern web

fix: descriptionParsed

Barış Soner Uşaklı189ee51e7806
diff --git a/src/categories/create.js b/src/categories/create.js
index fa49468834..86e147176f 100644
--- a/src/categories/create.js
+++ b/src/categories/create.js
@@ -31,7 +31,6 @@ module.exports = function (Categories) {
name: data.name,
handle,
description: data.description ? data.description : '',
- descriptionParsed: data.descriptionParsed ? data.descriptionParsed : '',
icon: data.icon ? data.icon : '',
bgColor: data.bgColor || colours[0],
color: data.color || colours[1],
@@ -85,10 +84,6 @@ module.exports = function (Categories) {
category = result.category;
await db.setObject(`category:${category.cid}`, category);
- if (!category.descriptionParsed) {
- await Categories.parseDescription(category.cid, category.description);
- }
-
await db.sortedSetAddBulk([
['categories:cid', category.order, category.cid],
[`cid:${parentCid}:children`, category.order, category.cid],
diff --git a/src/categories/data.js b/src/categories/data.js
index 2b011fecb9..5a298c60c7 100644
--- a/src/categories/data.js
+++ b/src/categories/data.js
@@ -56,7 +56,7 @@ module.exports = function (Categories) {
fields: fields,
keys: keys,
});
- result.categories.forEach(category => modifyCategory(category, fields));
+ await modifyCategories(result.categories, result.fields);
return result.categories;
};
@@ -114,39 +114,45 @@ function defaultIntField(category, hasField, fieldName, defaultField) {
}
}
-function modifyCategory(category, fields) {
- if (!category) {
+async function modifyCategories(categories, fields) {
+ if (!categories || !categories.length) {
return;
}
-
const hasField = utils.createFieldChecker(fields);
- defaultIntField(category, hasField, 'minTags', 'minimumTagsPerTopic');
- defaultIntField(category, hasField, 'maxTags', 'maximumTagsPerTopic');
- defaultIntField(category, hasField, 'postQueue', 'postQueue');
+ await Promise.all(categories.map(async (category) => {
+ if (!category) return;
+ defaultIntField(category, hasField, 'minTags', 'minimumTagsPerTopic');
+ defaultIntField(category, hasField, 'maxTags', 'maximumTagsPerTopic');
+ defaultIntField(category, hasField, 'postQueue', 'postQueue');
- db.parseIntFields(category, intFields, fields);
+ db.parseIntFields(category, intFields, fields);
- if (hasField('icon')) {
- category.icon = category.icon || 'hidden';
- if (category.icon === 'fa-none') {
- category.icon = 'fa-nbb-none';
+ if (hasField('icon')) {
+ category.icon = category.icon || 'hidden';
+ if (category.icon === 'fa-none') {
+ category.icon = 'fa-nbb-none';
+ }
}
- }
- if (hasField('post_count')) {
- category.totalPostCount = category.post_count;
- }
+ if (hasField('post_count')) {
+ category.totalPostCount = category.post_count;
+ }
- if (hasField('topic_count')) {
- category.totalTopicCount = category.topic_count;
- }
+ if (hasField('topic_count')) {
+ category.totalTopicCount = category.topic_count;
+ }
- if (hasField('nickname')) {
- category.nickname = category.nickname || '';
- }
+ if (hasField('nickname')) {
+ category.nickname = category.nickname || '';
+ }
- if (hasField('name')) {
- category.name = category.nickname || category.name;
- }
+ if (hasField('name')) {
+ category.name = category.nickname || category.name;
+ }
+
+ if (hasField('description')) {
+ category.descriptionParsed = await plugins.hooks.fire('filter:parse.raw', category.description);
+ }
+ }));
}
diff --git a/src/categories/update.js b/src/categories/update.js
index 2c2053f9fa..77381191af 100644
--- a/src/categories/update.js
+++ b/src/categories/update.js
@@ -61,9 +61,6 @@ module.exports = function (Categories) {
}
await db.setObjectField(`${utils.isNumber(cid) ? 'category' : 'categoryRemote'}:${cid}`, key, value);
- if (key === 'description') {
- await Categories.parseDescription(cid, value);
- }
}
async function updateParent(cid, newParent) {
@@ -137,11 +134,6 @@ module.exports = function (Categories) {
]);
}
- Categories.parseDescription = async function (cid, description) {
- const parsedDescription = await plugins.hooks.fire('filter:parse.raw', description);
- await Categories.setCategoryField(cid, 'descriptionParsed', parsedDescription);
- };
-
async function updateName(cid, newName) {
const oldName = await Categories.getCategoryField(cid, 'name');
await db.sortedSetRemove('categories:name', `${oldName.slice(0, 200).toLowerCase()}:${cid}`);