fix: typo, client-side handling of crossposts as pertains to uncategorized topics

This commit is contained in:
Julian Lam
2026-01-07 11:50:00 -05:00
parent 273bc68c46
commit 7465762d87
2 changed files with 30 additions and 31 deletions

View File

@@ -20,27 +20,44 @@ define('forum/topic/crosspost', [
}; };
function showModal() { function showModal() {
app.parseAndTranslate('modals/crosspost-topic', { const selectedCategory = (() => {
selectedCategory: ajaxify.data.crossposts.length ? const multiple = {
{ icon: 'fa-plus',
icon: 'fa-plus', name: '[[unread:multiple-categories-selected]]',
name: '[[unread:multiple-categories-selected]]', bgColor: '#ddd',
bgColor: '#ddd', };
} : if (ajaxify.data.cid > 0) {
ajaxify.data.category, return ajaxify.data.crossposts.length ? multiple : ajaxify.data.category;
}, function (html) { }
switch (ajaxify.data.crossposts.length) {
case 0:
return undefined;
case 1:
return ajaxify.data.crossposts[0].category;
default:
return multiple;
}
})();
app.parseAndTranslate('modals/crosspost-topic', { selectedCategory }, function (html) {
modal = html; modal = html;
$('body').append(modal); $('body').append(modal);
const dropdownEl = modal.find('[component="category-selector"]'); const dropdownEl = modal.find('[component="category-selector"]');
dropdownEl.addClass('dropup'); dropdownEl.addClass('dropup');
const selectedCids = [...ajaxify.data.crossposts.map(c => c.cid)];
if (ajaxify.data.cid > 0) {
selectedCids.unshift(ajaxify.data.cid);
}
categoryFilter.init($('[component="category/dropdown"]'), { categoryFilter.init($('[component="category/dropdown"]'), {
onHidden: onCategoriesSelected, onHidden: onCategoriesSelected,
hideAll: true, hideAll: true,
hideUncategorized: true, hideUncategorized: true,
localOnly: true, localOnly: true,
selectedCids: Array.from(new Set([ajaxify.data.cid, ...ajaxify.data.crossposts.map(c => c.cid)])), selectedCids: Array.from(new Set(selectedCids)),
}); });
modal.find('#crosspost_thread_commit').on('click', onCommitClicked); modal.find('#crosspost_thread_commit').on('click', onCommitClicked);
@@ -49,7 +66,7 @@ define('forum/topic/crosspost', [
} }
function onCategoriesSelected(data) { function onCategoriesSelected(data) {
selectedCids = data.selectedCids.filter(utils.isNumber); selectedCids = data.selectedCids.filter(cid => utils.isNumber(cid) && cid > 0);
if (data.changed) { if (data.changed) {
modal.find('#crosspost_thread_commit').prop('disabled', false); modal.find('#crosspost_thread_commit').prop('disabled', false);
} }
@@ -58,31 +75,13 @@ define('forum/topic/crosspost', [
function onCommitClicked() { function onCommitClicked() {
const commitEl = modal.find('#crosspost_thread_commit'); const commitEl = modal.find('#crosspost_thread_commit');
if (!commitEl.prop('disabled') && selectedCids && selectedCids.length) { if (!commitEl.prop('disabled')) {
commitEl.prop('disabled', true); commitEl.prop('disabled', true);
const data = { const data = {
tid: Crosspost.tid, tid: Crosspost.tid,
cids: selectedCids, cids: selectedCids,
}; };
// TODO
// if (config.undoTimeout > 0) {
// return alerts.alert({
// alert_id: 'tids_move_' + (Crosspost.tid ? Crosspost.tid.join('-') : 'all'),
// title: '[[topic:thread-tools.move]]',
// message: message,
// type: 'success',
// timeout: config.undoTimeout,
// timeoutfn: function () {
// moveTopics(data);
// },
// clickfn: function (alert, params) {
// delete params.timeoutfn;
// alerts.success('[[topic:topic-move-undone]]');
// },
// });
// }
crosspost(data); crosspost(data);
} }
} }

View File

@@ -231,7 +231,7 @@ Topics.crosspost = async (req, res) => {
Topics.uncrosspost = async (req, res) => { Topics.uncrosspost = async (req, res) => {
const { cid } = req.body; const { cid } = req.body;
const crossposts = await topics.crossposts.remove(req.params.tid, cid, req.uid); const crossposts = await topics.crossposts.remove(req.params.tid, cid, req.uid);
await activitypub.out.undo.announce('uid', req.uid, req.parms.tid); await activitypub.out.undo.announce('uid', req.uid, req.params.tid);
helpers.formatApiResponse(200, res, { crossposts }); helpers.formatApiResponse(200, res, { crossposts });
}; };