/**
  * Get the position within a discussion where a post with a certain number
  * is. If the post with that number does not exist, the index of the
  * closest post to it will be returned.
  *
  * @param integer $discussionId
  * @param integer $number
  * @param \Flarum\Core\Users\User|null $actor
  * @return integer
  */
 public function getIndexForNumber($discussionId, $number, User $actor = null)
 {
     $query = Discussion::find($discussionId)->postsVisibleTo($actor)->where('time', '<', function ($query) use($discussionId, $number) {
         $query->select('time')->from('posts')->where('discussion_id', $discussionId)->whereNotNull('number')->take(1)->orderByRaw('ABS(CAST(number AS SIGNED) - ' . (int) $number . ')');
     });
     return $query->count();
 }