<commit_before><?php namespace Flarum\Extend;

use Illuminate\Foundation\Application;
use Flarum\Core\Models\Notification;
use Flarum\Core\Models\User;

class NotificationType implements ExtenderInterface
{
    protected $class;

    protected $enabled = [];

    public function __construct($class)
    {
        $this->class = $class;
    }

    public function enableByDefault($method)
    {
        $this->enabled[] = $method;

        return $this;
    }

    public function extend(Application $app)
    {
        $notifier = $app['flarum.notifier'];
        $class = $this->class;

        $notifier->registerType($class);

        Notification::registerType($class);

        foreach ($notifier->getMethods() as $method => $sender) {
            if ($sender::compatibleWith($class)) {
                User::registerPreference(User::notificationPreferenceKey($class::getType(), $method), 'boolval', isset($this->enabled[$method]));
            }
        }
    }
}<commit_msg>Fix notification preferences not being enabled by default<commit_after><?php namespace Flarum\Extend;

use Illuminate\Foundation\Application;
use Flarum\Core\Models\Notification;
use Flarum\Core\Models\User;

class NotificationType implements ExtenderInterface
{
    protected $class;

    protected $enabled = [];

    public function __construct($class)
    {
        $this->class = $class;
    }

    public function enableByDefault($method)
    {
        $this->enabled[] = $method;

        return $this;
    }

    public function extend(Application $app)
    {
        $notifier = $app['flarum.notifier'];
        $class = $this->class;

        $notifier->registerType($class);

        Notification::registerType($class);

        foreach ($notifier->getMethods() as $method => $sender) {
            if ($sender::compatibleWith($class)) {
                User::registerPreference(User::notificationPreferenceKey($class::getType(), $method), 'boolval', in_array($method, $this->enabled));
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.1357533565390353, 'fraction_numerical': 0.0, 'mean_word_length': 2.9528487229862477, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7126779', 'n_tokens_mistral': 565, 'n_tokens_neox': 542, 'n_words': 108}