aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Notification/AdminEditedNoteNotif.php
blob: f3c18a17c83c0355c743d1e07a406ee9259ed661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Digitigrade\Notification;

use Digitigrade\Model\Note;
use Digitigrade\Model\UserAccount;

class AdminEditedNoteNotif implements Notifyable {
    private UserAccount $admin;
    private Note $note;

    public function __construct(UserAccount $admin, Note $note) {
        $this->admin = $admin;
        $this->note = $note;
    }

    public function toJsonReference(): mixed {
        return [$this->admin->id, $this->note->id];
    }

    public static function fromJsonReference(mixed $reference): self {
        return new self(UserAccount::find($reference[0]), Note::find($reference[1]));
    }

    public function getNotificationTitle(): string {
        return __f('notification.adminEditedNote', $this->admin->actor->displayName);
    }

    public function getNotificationTitleLink(): ?string {
        return $this->note->getLocalUiHref();
    }

    public function getNotificationBody(): ?string {
        return isset($this->note->summary) ? ('[' . $this->note->summary . ']') : $this->note->plainContent;
    }

    public function getNotificationImageUrl(): ?string {
        return $this->admin->actor->avatar ?? '/static/default-avatar.png';
    }

    public function getNotificationImageLink(): ?string {
        return $this->admin->actor->getLocalUiHref();
    }
}