blob: 5446098adb1c5051c3708ce56ac7f08be02b1135 (
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
namespace Digitigrade\Notification;
use Digitigrade\Model\Actor;
use Digitigrade\Model\Notification;
use Digitigrade\Model\UserAccount;
use Digitigrade\PokeVerb;
class PokeNotif implements Notifyable {
private Actor $subject;
private PokeVerb $verb;
private Actor $object;
private bool $urgent;
public function __construct(Actor $subject, PokeVerb $verb, Actor $object, bool $urgent) {
$this->subject = $subject;
$this->verb = $verb;
$this->object = $object;
$this->urgent = $urgent;
}
public function toJsonReference(): mixed {
return [$this->subject->id, $this->verb->value, $this->object->id, $this->urgent];
}
public static function fromJsonReference(mixed $reference): ?self {
return new self(
Actor::find($reference[0]),
PokeVerb::from($reference[1]),
Actor::find($reference[2]),
$reference[3]
);
}
public function getNotificationTitle(): string {
$kind = $this->urgent ? 'urgent' : 'normal';
$verb = $this->verb->value;
return __f("notifications.poke.$kind", $this->subject->displayName, __("notifications.poke.verb.$verb"));
}
public function getNotificationTitleLink(): ?string {
return $this->subject->getLocalUiHref();
}
public function getNotificationBody(): ?string {
return null;
}
public function getNotificationImageUrl(): ?string {
return $this->subject->avatar ?? '/static/default-avatar.png';
}
public function getNotificationImageLink(): ?string {
return $this->subject->getLocalUiHref();
}
public function processNotifications() {
if (!$this->object->isLocal)
return;
Notification::fromNotifyable($this, UserAccount::findByLinkedActor($this->object))->send();
}
}
|