<commit_before><?php

namespace OpenDominion\Listeners;

use OpenDominion\Events\UserRegisteredEvent;
use OpenDominion\Helpers\NotificationHelper;

class SetUserDefaultSettings
{
    /** @var NotificationHelper */
    protected $notificationHelper;

    /**
     * SetUserDefaultSettings constructor.
     *
     * @param NotificationHelper $notificationHelper
     */
    public function __construct(NotificationHelper $notificationHelper)
    {
        $this->notificationHelper = $notificationHelper;
    }

    /**
     * Handle the event.
     *
     * @param UserRegisteredEvent $event
     * @return void
     */
    public function handle(UserRegisteredEvent $event): void
    {
        $user = $event->getUser();

        $settings = [];

        // Notifications
        $settings['notifications'] = [];

        foreach (collect([
            $this->notificationHelper->getGeneralTypes(),
            $this->notificationHelper->getHourlyDominionTypes(),
            $this->notificationHelper->getIrregularDominionTypes()
        ]) as $notifications) {
            foreach ($notifications as $notificationKey => $notification) {
                $settings['notifications'][$notificationKey] = collect($notification['defaults'])->filter(function ($value) {
                    return $value === true;
                });
            }
        }

        // Notification Settings
        $settings['notification_digest'] = 'hourly';

        $user->settings = $settings;
        $user->save();
    }
}
<commit_msg>Fix set default notification settings upon registration<commit_after><?php

namespace OpenDominion\Listeners;

use OpenDominion\Events\UserRegisteredEvent;
use OpenDominion\Helpers\NotificationHelper;

class SetUserDefaultSettings
{
    /** @var NotificationHelper */
    protected $notificationHelper;

    /**
     * SetUserDefaultSettings constructor.
     *
     * @param NotificationHelper $notificationHelper
     */
    public function __construct(NotificationHelper $notificationHelper)
    {
        $this->notificationHelper = $notificationHelper;
    }

    /**
     * Handle the event.
     *
     * @param UserRegisteredEvent $event
     * @return void
     */
    public function handle(UserRegisteredEvent $event): void
    {
        $user = $event->getUser();

        $settings = [];

        // Notifications
        $settings['notifications'] = $this->notificationHelper->getDefaultUserNotificationSettings();
        $settings['notification_digest'] = 'hourly';

        $user->settings = $settings;
        $user->save();
    }
}

{'fraction_non_alphanumeric': 0.1154294597745822, 'fraction_numerical': 0.0, 'mean_word_length': 2.6929698708751793, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '355728', 'n_tokens_mistral': 659, 'n_tokens_neox': 643, 'n_words': 121}