From 2d5a7ce064a115f3b092acb2e3a0e532d7f687ad Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 28 May 2016 09:43:21 +0930 Subject: [PATCH] Make discussion "hidden" state more explicit Previously a discussion was classified on the front-end as "hidden" if it had zero posts. This was technically a correct statement as the discussion would not be visible to the public... but it also meant that a discussion with zero posts (like one awaiting approval) was impossible for the OP to delete/hide (i.e. indicate that they made a mistake and they don't want the discussion to be approved). --- js/admin/dist/app.js | 4 +-- js/forum/dist/app.js | 31 +++++++++++++----------- js/forum/src/utils/DiscussionControls.js | 27 ++++++++++++--------- js/lib/models/Discussion.js | 2 +- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/js/admin/dist/app.js b/js/admin/dist/app.js index 146989a74..554554964 100644 --- a/js/admin/dist/app.js +++ b/js/admin/dist/app.js @@ -21583,8 +21583,8 @@ System.register('flarum/models/Discussion', ['flarum/Model', 'flarum/utils/compu hideTime: Model.attribute('hideTime', Model.transformDate), hideUser: Model.hasOne('hideUser'), - isHidden: computed('hideTime', 'commentsCount', function (hideTime, commentsCount) { - return !!hideTime || commentsCount === 0; + isHidden: computed('hideTime', function (hideTime) { + return !!hideTime; }), canReply: Model.attribute('canReply'), diff --git a/js/forum/dist/app.js b/js/forum/dist/app.js index 9b3caf819..da2e30235 100644 --- a/js/forum/dist/app.js +++ b/js/forum/dist/app.js @@ -29107,8 +29107,8 @@ System.register('flarum/models/Discussion', ['flarum/Model', 'flarum/utils/compu hideTime: Model.attribute('hideTime', Model.transformDate), hideUser: Model.hasOne('hideUser'), - isHidden: computed('hideTime', 'commentsCount', function (hideTime, commentsCount) { - return !!hideTime || commentsCount === 0; + isHidden: computed('hideTime', function (hideTime) { + return !!hideTime; }), canReply: Model.attribute('canReply'), @@ -30179,19 +30179,22 @@ System.register('flarum/utils/DiscussionControls', ['flarum/components/Discussio onclick: this.hideAction.bind(discussion) })); } - } else if (discussion.canDelete()) { - items.add('restore', Button.component({ - icon: 'reply', - children: app.translator.trans('core.forum.discussion_controls.restore_button'), - onclick: this.restoreAction.bind(discussion), - disabled: discussion.commentsCount() === 0 - })); + } else { + if (discussion.canHide()) { + items.add('restore', Button.component({ + icon: 'reply', + children: app.translator.trans('core.forum.discussion_controls.restore_button'), + onclick: this.restoreAction.bind(discussion) + })); + } - items.add('delete', Button.component({ - icon: 'times', - children: app.translator.trans('core.forum.discussion_controls.delete_forever_button'), - onclick: this.deleteAction.bind(discussion) - })); + if (discussion.canDelete()) { + items.add('delete', Button.component({ + icon: 'times', + children: app.translator.trans('core.forum.discussion_controls.delete_forever_button'), + onclick: this.deleteAction.bind(discussion) + })); + } } return items; diff --git a/js/forum/src/utils/DiscussionControls.js b/js/forum/src/utils/DiscussionControls.js index 1595ef36f..951f800e8 100644 --- a/js/forum/src/utils/DiscussionControls.js +++ b/js/forum/src/utils/DiscussionControls.js @@ -113,19 +113,22 @@ export default { onclick: this.hideAction.bind(discussion) })); } - } else if (discussion.canDelete()) { - items.add('restore', Button.component({ - icon: 'reply', - children: app.translator.trans('core.forum.discussion_controls.restore_button'), - onclick: this.restoreAction.bind(discussion), - disabled: discussion.commentsCount() === 0 - })); + } else { + if (discussion.canHide()) { + items.add('restore', Button.component({ + icon: 'reply', + children: app.translator.trans('core.forum.discussion_controls.restore_button'), + onclick: this.restoreAction.bind(discussion) + })); + } - items.add('delete', Button.component({ - icon: 'times', - children: app.translator.trans('core.forum.discussion_controls.delete_forever_button'), - onclick: this.deleteAction.bind(discussion) - })); + if (discussion.canDelete()) { + items.add('delete', Button.component({ + icon: 'times', + children: app.translator.trans('core.forum.discussion_controls.delete_forever_button'), + onclick: this.deleteAction.bind(discussion) + })); + } } return items; diff --git a/js/lib/models/Discussion.js b/js/lib/models/Discussion.js index cbfad1ac3..404ae75ab 100644 --- a/js/lib/models/Discussion.js +++ b/js/lib/models/Discussion.js @@ -30,7 +30,7 @@ Object.assign(Discussion.prototype, { hideTime: Model.attribute('hideTime', Model.transformDate), hideUser: Model.hasOne('hideUser'), - isHidden: computed('hideTime', 'commentsCount', (hideTime, commentsCount) => !!hideTime || commentsCount === 0), + isHidden: computed('hideTime', hideTime => !!hideTime), canReply: Model.attribute('canReply'), canRename: Model.attribute('canRename'),