fix: removed ajaxify refresh on crosspost commit, dynamically update post stats in template, logic fix

This commit is contained in:
Julian Lam
2025-12-16 14:21:51 -05:00
parent 947676efac
commit b981082dd7
6 changed files with 28 additions and 2 deletions

View File

@@ -5,5 +5,6 @@
"profile-page-for": "Profile page for user %1",
"user-watched-tags": "User watched tags",
"delete-upload-button": "Delete upload button",
"group-page-link-for": "Group page link for %1"
"group-page-link-for": "Group page link for %1",
"show-crossposts": "Show Cross-posts"
}

View File

@@ -81,6 +81,7 @@
"users": "Users",
"topics": "Topics",
"posts": "Posts",
"crossposts": "Cross-posts",
"x-posts": "<span class=\"formatted-number\">%1</span> posts",
"x-topics": "<span class=\"formatted-number\">%1</span> topics",
"x-reputation": "<span class=\"formatted-number\">%1</span> reputation",

View File

@@ -69,6 +69,7 @@ define('forum/topic', [
setupQuickReply();
handleBookmark(tid);
handleThumbs();
addCrosspostsHandler();
$(window).on('scroll', utils.debounce(updateTopicTitle, 250));
@@ -406,6 +407,23 @@ define('forum/topic', [
});
}
function addCrosspostsHandler() {
const anchorEl = document.getElementById('show-crossposts');
if (anchorEl) {
anchorEl.addEventListener('click', async () => {
const { crossposts } = ajaxify.data;
const html = await app.parseAndTranslate('modals/crossposts', { crossposts });
bootbox.dialog({
size: 'sm',
onEscape: true,
backdrop: true,
title: '[[global:crossposts]]',
message: html,
});
});
}
}
function setupQuickReply() {
if (config.enableQuickReply || (config.theme && config.theme.enableQuickReply)) {
quickreply.init();

View File

@@ -214,6 +214,11 @@ Topics.move = async (req, res) => {
helpers.formatApiResponse(200, res);
};
Topics.getCrossposts = async (req, res) => {
const crossposts = await topics.crossposts.get(req.params.tid);
helpers.formatApiResponse(200, res, { crossposts });
};
Topics.crosspost = async (req, res) => {
const { cid } = req.body;
const crossposts = await topics.crossposts.add(req.params.tid, cid, req.uid);

View File

@@ -54,6 +54,7 @@ module.exports = function () {
setupApiRoute(router, 'put', '/:tid/move', [...middlewares, middleware.assert.topic], controllers.write.topics.move);
setupApiRoute(router, 'get', '/:tid/crossposts', [...middlewares, middleware.assert.topic], controllers.write.topics.getCrossposts);
setupApiRoute(router, 'post', '/:tid/crossposts', [...middlewares, middleware.assert.topic], controllers.write.topics.crosspost);
setupApiRoute(router, 'delete', '/:tid/crossposts', [...middlewares, middleware.assert.topic], controllers.write.topics.uncrosspost);

View File

@@ -17,7 +17,7 @@ Crossposts.get = async function (tid) {
return cids;
}, new Set());
let categoriesData = await categories.getCategoriesFields(
cids, ['cid', 'name', 'icon', 'bgColor', 'color', 'slug']
Array.from(cids), ['cid', 'name', 'icon', 'bgColor', 'color', 'slug']
);
categoriesData = categoriesData.reduce((map, category) => {
map.set(parseInt(category.cid, 10), category);