public function query() {

    // Get the group.
    $group = \Drupal::routeMatch()->getParameter('group');

    // Visibility logic when visiting a post stream on group page:
    // - All the posts to the group by you and other users in the community.
    $this->query->addTable('post__field_visibility');
    $this->query->addTable('post__field_recipient_group');

    // Or posted to the group by the community.
    $recipient_condition = db_and();
    $recipient_condition->condition('post__field_visibility.field_visibility_value', '0', '=');
    $recipient_condition->condition('post__field_recipient_group.field_recipient_group_target_id', $group->id(), '=');

    $this->query->addWhere('visibility', $recipient_condition);
  }