Skip to content

Commit

Permalink
fix: prevent starting a PD with users blocking them (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau authored Jul 31, 2022
1 parent 2e99cdb commit 23dcf93
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
8 changes: 2 additions & 6 deletions js/src/forum/extend/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Button from 'flarum/common/components/Button';
import ItemList from 'flarum/common/utils/ItemList';
import UserPage from 'flarum/forum/components/UserPage';
import LinkButton from 'flarum/common/components/LinkButton';
import canStartPrivateDiscussion from '../helpers/canStartPrivateDiscussion';

export default () => {
attributes();
Expand All @@ -17,12 +18,7 @@ export default () => {

function message() {
extend(UserControls, 'userControls', function (items, user) {
if (
app.session.user &&
app.session.user.id() !== user.id() &&
app.forum.attribute('canStartPrivateDiscussion') &&
(user.blocksPd() === false || (app.forum.attribute('canStartPrivateDiscussionWithBlockers') && user.cannotBeDirectMessaged()))
) {
if (canStartPrivateDiscussion(user)) {
items.add(
'private-discussion',
Button.component(
Expand Down
10 changes: 10 additions & 0 deletions js/src/forum/helpers/canStartPrivateDiscussion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import app from 'flarum/forum/app';

export default function canStartPrivateDiscussion(recipient) {
return (
app.session.user &&
app.session.user.id() !== recipient.id() &&
app.forum.attribute('canStartPrivateDiscussion') &&
(!recipient.blocksPd() || (app.forum.attribute('canStartPrivateDiscussionWithBlockers') && recipient.cannotBeDirectMessaged()))
);
}
3 changes: 2 additions & 1 deletion js/src/forum/pages/PrivateDiscussionsUserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ItemList from 'flarum/common/utils/ItemList';
import listItems from 'flarum/common/helpers/listItems';
import PrivateDiscussionList from './discussions/PrivateDiscussionList';
import PrivateComposing from './PrivateComposing';
import canStartPrivateDiscussion from '../helpers/canStartPrivateDiscussion';

export default class PrivateDiscussionsUserPage extends UserPage {
oninit(vnode) {
Expand Down Expand Up @@ -57,7 +58,7 @@ export default class PrivateDiscussionsUserPage extends UserPage {

const items = new ItemList();

if (app.session.user && app.forum.attribute('canStartPrivateDiscussion')) {
if (canStartPrivateDiscussion(this.user)) {
items.add('start_private', composing.component());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Discussion/Screener.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function hasBlockingUsers(): bool
{
return $this->users
->first(function (User $user) {
return $user->getPreference('blocksPd', false);
return boolval($user->blocks_byobu_pd);
}) !== null;
}

Expand Down

0 comments on commit 23dcf93

Please sign in to comment.