Skip to content

Commit

Permalink
fixed gambit and added replace to composer.json
Browse files Browse the repository at this point in the history
  • Loading branch information
luceos committed Jun 19, 2019
1 parent 027a6d4 commit 2b40ba7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions composer.json
Expand Up @@ -37,6 +37,9 @@
"discuss": "https://discuss.flarum.org/d/4762"
}
},
"replace": {
"flagrow/byobu": "*"
},
"autoload": {
"psr-4": {
"FoF\\Byobu\\": "src/"
Expand Down
24 changes: 15 additions & 9 deletions src/Gambits/Discussion/ByobuGambit.php
Expand Up @@ -5,7 +5,9 @@
use Flarum\Discussion\Search\DiscussionSearch;
use Flarum\Search\AbstractRegexGambit;
use Flarum\Search\AbstractSearch;
use Flarum\User\User;
use Flarum\User\UserRepository;
use Illuminate\Database\Query\Builder;
use LogicException;

class ByobuGambit extends AbstractRegexGambit
Expand Down Expand Up @@ -46,19 +48,23 @@ protected function conditions(AbstractSearch $search, array $matches, $negate)

$usernames = explode(',', trim($matches[1], '"'));

$ids = [];

foreach ($usernames as $username) {
$ids[] = $this->users->getIdForUsername($username);
}

$actor = $search->getActor();

$ids[] = $actor->id;
$userIds = User::query()
->whereIn('username', $usernames)
->whereVisibleTo($actor)
->pluck('id')
->toArray();

$userIds[] = $actor->id;
$groupIds = $actor->groups()->pluck('id')->toArray();

$search->getQuery()
->orWhereHas('recipients', function ($query) use ($ids) {
$query->whereIn('user_id', $ids);
->join('recipients', 'discussions.id', '=', 'recipients.discussion_id')
->where(function (Builder $query) use ($userIds, $groupIds) {
$query
->whereIn('recipients.user_id', $userIds)
->orWhereIn('recipients.group_id', $groupIds);
});
}
}

0 comments on commit 2b40ba7

Please sign in to comment.