-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6870e57
commit 418cdff
Showing
2 changed files
with
7 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,41 +8,24 @@ | |
* The NewsPicker service is a sort of basic artificial intelligence. Its | ||
* purpose is to select a bunch of links relevant for a given user. | ||
* | ||
* @phpstan-type Options array{ | ||
* 'number_links': int, | ||
* } | ||
* | ||
* @author Marien Fressinaud <[email protected]> | ||
* @license http://www.gnu.org/licenses/agpl-3.0.en.html AGPL | ||
*/ | ||
class NewsPicker | ||
{ | ||
private const DEFAULT_OPTIONS = [ | ||
'number_links' => 9, | ||
]; | ||
|
||
private models\User $user; | ||
|
||
/** @var Options */ | ||
private array $options; | ||
|
||
/** | ||
* @param array{ | ||
* 'number_links'?: int, | ||
* } $options | ||
*/ | ||
public function __construct(models\User $user, array $options = []) | ||
public function __construct(models\User $user) | ||
{ | ||
$this->user = $user; | ||
$this->options = array_merge(self::DEFAULT_OPTIONS, $options); | ||
} | ||
|
||
/** | ||
* Pick and return a set of links relevant for news. | ||
* | ||
* @return models\Link[] | ||
*/ | ||
public function pick(): array | ||
public function pick(int $max = 25): array | ||
{ | ||
$excluded_hashes = models\Link::listHashesExcludedFromNews($this->user->id); | ||
$links_from_followed = models\Link::listFromFollowedCollections($this->user->id); | ||
|
@@ -58,7 +41,7 @@ public function pick(): array | |
|
||
$links[$hash] = $link; | ||
|
||
if (count($links) >= $this->options['number_links']) { | ||
if (count($links) >= $max) { | ||
break; | ||
} | ||
} | ||
|