mirror of
https://github.com/flarum/core.git
synced 2025-07-31 05:30:38 +02:00
Allow discussions to be hidden and restored
This commit is contained in:
@@ -13,6 +13,7 @@ import SubtreeRetainer from 'flarum/utils/SubtreeRetainer';
|
||||
import DiscussionControls from 'flarum/utils/DiscussionControls';
|
||||
import slidable from 'flarum/utils/slidable';
|
||||
import extractText from 'flarum/utils/extractText';
|
||||
import classList from 'flarum/utils/classList';
|
||||
|
||||
/**
|
||||
* The `DiscussionListItem` component shows a single discussion in the
|
||||
@@ -43,6 +44,16 @@ export default class DiscussionListItem extends Component {
|
||||
);
|
||||
}
|
||||
|
||||
attrs() {
|
||||
return {
|
||||
className: classList([
|
||||
'DiscussionListItem',
|
||||
this.active() ? 'active' : '',
|
||||
this.props.discussion.isHidden() ? 'DiscussionListItem--hidden' : ''
|
||||
])
|
||||
};
|
||||
}
|
||||
|
||||
view() {
|
||||
const retain = this.subtree.retain();
|
||||
|
||||
@@ -56,9 +67,10 @@ export default class DiscussionListItem extends Component {
|
||||
const jumpTo = Math.min(discussion.lastPostNumber(), (discussion.readNumber() || 0) + 1);
|
||||
const relevantPosts = this.props.params.q ? discussion.relevantPosts() : [];
|
||||
const controls = DiscussionControls.controls(discussion, this).toArray();
|
||||
const attrs = this.attrs();
|
||||
|
||||
return (
|
||||
<div className={'DiscussionListItem ' + (this.active() ? 'active' : '')}>
|
||||
<div {...attrs}>
|
||||
|
||||
{controls.length ? Dropdown.component({
|
||||
icon: 'ellipsis-v',
|
||||
|
@@ -105,10 +105,25 @@ export default {
|
||||
destructiveControls(discussion) {
|
||||
const items = new ItemList();
|
||||
|
||||
if (discussion.canDelete()) {
|
||||
if (!discussion.isHidden()) {
|
||||
if (discussion.canHide()) {
|
||||
items.add('hide', Button.component({
|
||||
icon: 'trash-o',
|
||||
children: app.trans('core.delete'),
|
||||
onclick: this.hideAction.bind(discussion)
|
||||
}));
|
||||
}
|
||||
} else if (discussion.canDelete()) {
|
||||
items.add('restore', Button.component({
|
||||
icon: 'reply',
|
||||
children: app.trans('core.restore'),
|
||||
onclick: this.restoreAction.bind(discussion),
|
||||
disabled: discussion.commentsCount() === 0
|
||||
}));
|
||||
|
||||
items.add('delete', Button.component({
|
||||
icon: 'times',
|
||||
children: app.trans('core.delete'),
|
||||
children: app.trans('core.delete_forever'),
|
||||
onclick: this.deleteAction.bind(discussion)
|
||||
}));
|
||||
}
|
||||
@@ -173,13 +188,35 @@ export default {
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/**
|
||||
* Hide a discussion.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
hideAction() {
|
||||
this.pushAttributes({ hideTime: new Date(), hideUser: app.session.user });
|
||||
|
||||
return this.save({ isHidden: true });
|
||||
},
|
||||
|
||||
/**
|
||||
* Restore a discussion.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
restoreAction() {
|
||||
this.pushAttributes({ hideTime: null, hideUser: null });
|
||||
|
||||
return this.save({ isHidden: false });
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete the discussion after confirming with the user.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
deleteAction() {
|
||||
if (confirm(extractText(app.trans('core.confirm_delete_discussion')))) {
|
||||
this.delete();
|
||||
|
||||
// If there is a discussion list in the cache, remove this discussion.
|
||||
if (app.cache.discussionList) {
|
||||
app.cache.discussionList.removeDiscussion(this);
|
||||
@@ -190,11 +227,15 @@ export default {
|
||||
if (app.viewingDiscussion(this)) {
|
||||
app.history.back();
|
||||
}
|
||||
|
||||
return this.delete();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Rename the discussion.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
renameAction() {
|
||||
const currentTitle = this.title();
|
||||
@@ -204,7 +245,7 @@ export default {
|
||||
// save has completed, update the post stream as there will be a new post
|
||||
// indicating that the discussion was renamed.
|
||||
if (title && title !== currentTitle) {
|
||||
this.save({title}).then(() => {
|
||||
return this.save({title}).then(() => {
|
||||
if (app.viewingDiscussion(this)) {
|
||||
app.current.stream.update();
|
||||
}
|
||||
|
@@ -114,25 +114,34 @@ export default {
|
||||
|
||||
/**
|
||||
* Hide a post.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
hideAction() {
|
||||
this.save({ isHidden: true });
|
||||
this.pushAttributes({ hideTime: new Date(), hideUser: app.session.user });
|
||||
|
||||
return this.save({ isHidden: true }).then(() => m.redraw());
|
||||
},
|
||||
|
||||
/**
|
||||
* Restore a post.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
restoreAction() {
|
||||
this.save({ isHidden: false });
|
||||
this.pushAttributes({ hideTime: null, hideUser: null });
|
||||
|
||||
return this.save({ isHidden: false }).then(() => m.redraw());
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a post.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
deleteAction() {
|
||||
this.delete();
|
||||
this.discussion().removePost(this.id());
|
||||
|
||||
return this.delete();
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user