<commit_before><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Jobs\Notifications;

use App\Exceptions\InvalidNotificationException;
use App\Models\Comment;
use App\Models\Follow;
use App\Models\Notification;
use App\Models\User;
use App\Models\UserNotificationOption;

class CommentNew extends BroadcastNotificationBase
{
    const NOTIFICATION_OPTION_NAME = Notification::COMMENT_NEW;

    protected $comment;

    public static function getMailLink(Notification $notification): string
    {
        // TODO: actual item commented on.
        return route('comments.show', $notification->details['comment_id']);
    }

    public function __construct(Comment $comment, User $source)
    {
        parent::__construct($source);

        $this->comment = $comment;

        if ($this->comment->commentable === null) {
            throw new InvalidNotificationException("{$this->name}: comment #{$this->comment->getKey()} missing commentable");
        }
    }

    public function getDetails(): array
    {
        $details = [
            'comment_id' => $this->comment->getKey(),
            'title' => $this->comment->commentable->commentableTitle(),
            'content' => truncate($this->comment->message, static::CONTENT_TRUNCATE),
            'cover_url' => $this->comment->commentable->notificationCover(),
        ];

        if ($this->comment->parent !== null) {
            $details['reply_to'] = [
                'user_id' => $this->comment->parent->user_id,
            ];
        }

        return $details;
    }

    public function getListeningUserIds(): array
    {
        $userIds = Follow::whereNotifiable($this->comment->commentable)
            ->where(['subtype' => 'comment'])
            ->pluck('user_id');

        if ($this->comment->parent !== null) {
            // also notify parent if option is enabled.
            $user = $this->comment->parent->user;
            $notificationOption = $user->notificationOptions()->where('name', Notification::COMMENT_NEW)->first();

            if ($notificationOption->details[UserNotificationOption::COMMENT_REPLY] ?? true) {
                $userIds->push($user->getKey());
            }
        }

        return $userIds->all();
    }

    public function getNotifiable()
    {
        return $this->comment->commentable;
    }
}<commit_msg>skip if parent user is null<commit_after><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Jobs\Notifications;

use App\Exceptions\InvalidNotificationException;
use App\Models\Comment;
use App\Models\Follow;
use App\Models\Notification;
use App\Models\User;
use App\Models\UserNotificationOption;

class CommentNew extends BroadcastNotificationBase
{
    const NOTIFICATION_OPTION_NAME = Notification::COMMENT_NEW;

    protected $comment;

    public static function getMailLink(Notification $notification): string
    {
        // TODO: actual item commented on.
        return route('comments.show', $notification->details['comment_id']);
    }

    public function __construct(Comment $comment, User $source)
    {
        parent::__construct($source);

        $this->comment = $comment;

        if ($this->comment->commentable === null) {
            throw new InvalidNotificationException("{$this->name}: comment #{$this->comment->getKey()} missing commentable");
        }
    }

    public function getDetails(): array
    {
        $details = [
            'comment_id' => $this->comment->getKey(),
            'title' => $this->comment->commentable->commentableTitle(),
            'content' => truncate($this->comment->message, static::CONTENT_TRUNCATE),
            'cover_url' => $this->comment->commentable->notificationCover(),
        ];

        if ($this->comment->parent !== null) {
            $details['reply_to'] = [
                'user_id' => $this->comment->parent->user_id,
            ];
        }

        return $details;
    }

    public function getListeningUserIds(): array
    {
        $userIds = Follow::whereNotifiable($this->comment->commentable)
            ->where(['subtype' => 'comment'])
            ->pluck('user_id');

        if ($this->comment->parent !== null) {
            // also notify parent if option is enabled.
            $user = $this->comment->parent->user;
            if ($user !== null) {
                $notificationOption = $user->notificationOptions()->where('name', Notification::COMMENT_NEW)->first();

                if ($notificationOption->details[UserNotificationOption::COMMENT_REPLY] ?? true) {
                    $userIds->push($user->getKey());
                }
            }
        }

        return $userIds->all();
    }

    public function getNotifiable()
    {
        return $this->comment->commentable;
    }
}
{'fraction_non_alphanumeric': 0.13943268078306031, 'fraction_numerical': 0.0007990411506192569, 'mean_word_length': 2.6125541125541125, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 99, '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': '2475837', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1312, 'n_words': 290}