Node.js based forum software built for the modern web
fix: ability to change crosspost prior to accepting as queued crosspost
Julian Lam3d7a4068f63e
diff --git a/public/language/en-GB/post-queue.json b/public/language/en-GB/post-queue.jsonindex 7212aad374..fe2a924274 100644--- a/public/language/en-GB/post-queue.json+++ b/public/language/en-GB/post-queue.json@@ -10,6 +10,7 @@"user": "User","when": "When","category": "Category",+ "crosspost-to": "Crosspost to","tags": "Tags","title": "Title","content": "Content",diff --git a/public/src/client/post-queue.js b/public/src/client/post-queue.jsindex 86b5bed119..95b4460b9e 100644--- a/public/src/client/post-queue.js+++ b/public/src/client/post-queue.js@@ -167,6 +167,36 @@ define('forum/post-queue', [});}+ function handleCrosspostCidChange(postEl) {+ const id = postEl.getAttribute('data-id');+ const crosspostSection = postEl.querySelector('[data-crosspost]');++ categorySelector.modal({+ localOnly: true,+ onSubmit: function (selectedCategory) {+ Promise.all([+ api.get(`/categories/${selectedCategory.cid}`, {}),+ api.put(`/posts/queue/${id}`, {+ crosspostCid: selectedCategory.cid,+ }),+ ]).then(function (result) {+ const category = result[0];+ app.parseAndTranslate('post-queue', 'posts', {+ posts: [{+ type: 'crosspost',+ crosspostCategory: category,+ crosspostCid: category.cid,+ }],+ }, function (html) {+ if (crosspostSection) {+ crosspostSection.innerHTML = html.find('[data-crosspost]').html();+ }+ });+ }).catch(alerts.error);+ },+ });+ }+function handleCategoryChange(categoryEl) {const $this = $(categoryEl);const id = $this.parents('[data-id]').attr('data-id');@@ -251,8 +281,13 @@ define('forum/post-queue', [const uid = subselector.closest('[data-uid]').getAttribute('data-uid');switch (action) {case 'editCategory': {- const categoryEl = e.target.closest('[data-id]').querySelector('.topic-category');- handleCategoryChange(categoryEl);+ const postEl = e.target.closest('[data-id]');+ if (e.target.closest('[data-crosspost]')) {+ handleCrosspostCidChange(postEl);+ } else {+ const categoryEl = postEl.querySelector('.topic-category');+ handleCategoryChange(categoryEl);+ }break;}diff --git a/src/api/posts.js b/src/api/posts.jsindex 4b19d62a8c..5890c9243b 100644--- a/src/api/posts.js+++ b/src/api/posts.js@@ -608,7 +608,10 @@ postsAPI.removeQueuedPost = async (caller, data) => {};postsAPI.editQueuedPost = async (caller, data) => {- if (!data || !data.id || (!data.content && !data.title && !data.cid && !data.tags && !data.thumbs)) {+ if (+ !data || !data.id || (!data.content && !data.title && !data.cid &&+ !data.tags && !data.thumbs && !data.crosspostCid)+ ) {throw new Error('[[error:invalid-data]]');}await posts.editQueuedContent(caller.uid, data);diff --git a/src/posts/queue.js b/src/posts/queue.jsindex 1c3408da27..585a9d09d7 100644--- a/src/posts/queue.js+++ b/src/posts/queue.js@@ -98,6 +98,7 @@ module.exports = function (Posts) {'username', 'userslug', 'picture', 'icon:bgColor', 'joindate', 'postcount', 'reputation',]);postData.user = userData;+ postData.crosspostCategory = await categories.getCategoryData(postData.data.crosspostCid);} else {postData.topic = { cid: parseInt(postData.data.crosspostCid, 10) };}@@ -112,7 +113,7 @@ module.exports = function (Posts) {);}- postData.category = await categories.getCategoryData(postData.data.crosspostCid || postData.topic.cid);+ postData.category = await categories.getCategoryData(postData.topic.cid);const result = await plugins.hooks.fire('filter:parse.post', { postData: postData.data });postData.data.content = result.postData.content;}@@ -462,6 +463,9 @@ module.exports = function (Posts) {if (editData.thumbs !== undefined) {data.data.thumbs = editData.thumbs;}+ if (editData.crosspostCid !== undefined) {+ data.data.crosspostCid = editData.crosspostCid;+ }await db.setObjectField(`post:queue:${editData.id}`, 'data', JSON.stringify(data.data));cache.del('post-queue');};diff --git a/src/views/post-queue.tpl b/src/views/post-queue.tplindex 060ffd730d..950fec1e2f 100644--- a/src/views/post-queue.tpl+++ b/src/views/post-queue.tpl@@ -183,6 +183,26 @@</div></li>+ {{{ if (./type == "crosspost") }}}+ <li class="card-body border-bottom" data-crosspost>+ <div class="d-flex align-items-center justify-content-between mb-1">+ <div class="text-xs fw-semibold">+ [[post-queue:crosspost-to]]+ </div>+ <button data-action="editCategory" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>+ </div>++ <div class="topic-category">+ <a href="{config.relative_path}/category/{posts.crosspostCategory.slug}">+ <div class="category-item d-inline-block">+ {buildCategoryIcon(./crosspostCategory, "24px", "rounded-circle")}+ <span class="text-sm">{posts.crosspostCategory.name}</span>+ </div>+ </a>+ </div>+ </li>+ {{{ end }}}+{{{ if (posts.type == "topic") }}}<li class="card-body border-bottom"><div class="d-flex align-items-center justify-content-between mb-1">