protected function conditions(Search $search, array $matches, $negate)
 {
     $actor = $search->getActor();
     // might be better as `id IN (subquery)`?
     $method = $negate ? 'whereNotExists' : 'whereExists';
     $search->getQuery()->{$method}(function ($query) use($actor, $matches) {
         $query->select(app('flarum.db')->raw(1))->from('users_discussions')->where('discussions.id', new Expression('discussion_id'))->where('user_id', $actor->id)->where('subscription', $matches[1] === 'follow' ? 'follow' : 'ignore');
     });
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function conditions(Search $search, array $matches, $negate)
 {
     if (!$search instanceof DiscussionSearch) {
         throw new LogicException('This gambit can only be applied on a DiscussionSearch');
     }
     $actor = $search->getActor();
     if ($actor->exists) {
         $readIds = $this->discussions->getReadIds($actor);
         $search->getQuery()->where(function ($query) use($readIds, $negate, $actor) {
             if (!$negate) {
                 $query->whereNotIn('id', $readIds)->where('last_time', '>', $actor->read_time ?: 0);
             } else {
                 $query->whereIn('id', $readIds)->orWhere('last_time', '<=', $actor->read_time ?: 0);
             }
         });
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function apply(Search $search, $bit)
 {
     $users = $this->users->getIdsForUsername($bit, $search->getActor());
     $search->getQuery()->whereIn('id', $users);
     $search->setDefaultSort(['id' => $users]);
 }