mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-18 21:42:55 +01:00
fix: typo, client-side handling of crossposts as pertains to uncategorized topics
This commit is contained in:
@@ -20,27 +20,44 @@ define('forum/topic/crosspost', [
|
||||
};
|
||||
|
||||
function showModal() {
|
||||
app.parseAndTranslate('modals/crosspost-topic', {
|
||||
selectedCategory: ajaxify.data.crossposts.length ?
|
||||
{
|
||||
icon: 'fa-plus',
|
||||
name: '[[unread:multiple-categories-selected]]',
|
||||
bgColor: '#ddd',
|
||||
} :
|
||||
ajaxify.data.category,
|
||||
}, function (html) {
|
||||
const selectedCategory = (() => {
|
||||
const multiple = {
|
||||
icon: 'fa-plus',
|
||||
name: '[[unread:multiple-categories-selected]]',
|
||||
bgColor: '#ddd',
|
||||
};
|
||||
if (ajaxify.data.cid > 0) {
|
||||
return ajaxify.data.crossposts.length ? multiple : ajaxify.data.category;
|
||||
}
|
||||
|
||||
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;
|
||||
$('body').append(modal);
|
||||
|
||||
const dropdownEl = modal.find('[component="category-selector"]');
|
||||
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"]'), {
|
||||
onHidden: onCategoriesSelected,
|
||||
hideAll: true,
|
||||
hideUncategorized: 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);
|
||||
@@ -49,7 +66,7 @@ define('forum/topic/crosspost', [
|
||||
}
|
||||
|
||||
function onCategoriesSelected(data) {
|
||||
selectedCids = data.selectedCids.filter(utils.isNumber);
|
||||
selectedCids = data.selectedCids.filter(cid => utils.isNumber(cid) && cid > 0);
|
||||
if (data.changed) {
|
||||
modal.find('#crosspost_thread_commit').prop('disabled', false);
|
||||
}
|
||||
@@ -58,31 +75,13 @@ define('forum/topic/crosspost', [
|
||||
function onCommitClicked() {
|
||||
const commitEl = modal.find('#crosspost_thread_commit');
|
||||
|
||||
if (!commitEl.prop('disabled') && selectedCids && selectedCids.length) {
|
||||
if (!commitEl.prop('disabled')) {
|
||||
commitEl.prop('disabled', true);
|
||||
const data = {
|
||||
tid: Crosspost.tid,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ Topics.crosspost = async (req, res) => {
|
||||
Topics.uncrosspost = async (req, res) => {
|
||||
const { cid } = req.body;
|
||||
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 });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user