[PLUGIN][ActivityPub][Inbox] Add event for notifications triggered by AP Inbox
This commit is contained in:
parent
e86dbad6d6
commit
496701ce73
|
@ -178,8 +178,11 @@ class Inbox extends Controller
|
|||
if (!empty($ap_act->_object_mention_ids)) {
|
||||
$already_known_ids = $ap_act->_object_mention_ids;
|
||||
}
|
||||
|
||||
DB::flush();
|
||||
Event::handle('NewNotification', [$actor, $ap_act->getActivity(), $already_known_ids, _m('{nickname} mentioned you.', ['{nickname}' => $actor->getNickname()])]);
|
||||
if (Event::handle('ActivityPubNewNotification', [$actor, $ap_act->getActivity(), $already_known_ids, _m('{nickname} mentioned you.', ['{nickname}' => $actor->getNickname()])]) === Event::next) {
|
||||
Event::handle('NewNotification', [$actor, $ap_act->getActivity(), $already_known_ids, _m('{nickname} mentioned you.', ['{nickname}' => $actor->getNickname()])]);
|
||||
}
|
||||
|
||||
dd($ap_act, $act = $ap_act->getActivity(), $act->getActor(), $act->getObject());
|
||||
|
||||
|
|
|
@ -313,15 +313,9 @@ class Favourite extends NoteHandlerPlugin
|
|||
}
|
||||
|
||||
if ($type_activity->get('type') === 'Like') {
|
||||
if (!\is_null($activity = self::favourNote($note_id, $actor->getId(), source: 'ActivityPub'))) {
|
||||
DB::flush();
|
||||
Event::handle('NewNotification', [$actor, $activity, [], _m('{nickname} favoured note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]);
|
||||
}
|
||||
$activity = self::favourNote($note_id, $actor->getId(), source: 'ActivityPub');
|
||||
} else {
|
||||
if (!\is_null($activity = self::unfavourNote($note_id, $actor->getId(), source: 'ActivityPub'))) {
|
||||
DB::flush();
|
||||
Event::handle('NewNotification', [$actor, $activity, [], _m('{nickname} unfavoured note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]);
|
||||
}
|
||||
$activity = self::unfavourNote($note_id, $actor->getId(), source: 'ActivityPub');
|
||||
}
|
||||
if (!\is_null($activity)) {
|
||||
// Store ActivityPub Activity
|
||||
|
@ -336,6 +330,24 @@ class Favourite extends NoteHandlerPlugin
|
|||
return Event::stop;
|
||||
}
|
||||
|
||||
public function onActivityPubNewNotification(Actor $sender, Activity $activity, array $ids_already_known = [], ?string $reason = null): bool
|
||||
{
|
||||
switch ($activity->getVerb()) {
|
||||
case 'favourite':
|
||||
Event::handle('NewNotification', [$sender, $activity, [], _m('{nickname} favoured note {note_id}.', ['{nickname}' => $sender->getNickname(), '{note_id}' => $activity->getObjectId()])]);
|
||||
return Event::stop;
|
||||
case 'undo':
|
||||
if ($activity->getObjectType() === 'activity') {
|
||||
$undone_favourite = $activity->getObject();
|
||||
if ($undone_favourite->getVerb() === 'favourite') {
|
||||
Event::handle('NewNotification', [$sender, $activity, [], _m('{nickname} unfavoured note {note_id}.', ['{nickname}' => $sender->getNickname(), '{note_id}' => $activity->getObjectId()])]);
|
||||
return Event::stop;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an Activity Streams 2.0 Like or Undo Like into the appropriate Favourite and Undo Favourite entities
|
||||
*
|
||||
|
|
|
@ -390,15 +390,9 @@ class RepeatNote extends NoteHandlerPlugin
|
|||
}
|
||||
|
||||
if ($type_activity->get('type') === 'Announce') {
|
||||
if (!\is_null($activity = self::repeatNote($note ?? Note::getById($note_id), $actor->getId(), source: 'ActivityPub'))) {
|
||||
DB::flush();
|
||||
Event::handle('NewNotification', [$actor, $activity, [], _m('{nickname} repeated note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]);
|
||||
}
|
||||
$activity = self::repeatNote($note ?? Note::getById($note_id), $actor->getId(), source: 'ActivityPub');
|
||||
} else {
|
||||
if (!\is_null($activity = self::unrepeatNote($note_id, $actor->getId(), source: 'ActivityPub'))) {
|
||||
DB::flush();
|
||||
Event::handle('NewNotification', [$actor, $activity, [], _m('{nickname} unrepeated note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $note_id])]);
|
||||
}
|
||||
$activity = self::unrepeatNote($note_id, $actor->getId(), source: 'ActivityPub');
|
||||
}
|
||||
if (!\is_null($activity)) {
|
||||
// Store ActivityPub Activity
|
||||
|
@ -413,6 +407,24 @@ class RepeatNote extends NoteHandlerPlugin
|
|||
return Event::stop;
|
||||
}
|
||||
|
||||
public function onActivityPubNewNotification(Actor $sender, Activity $activity, array $ids_already_known = [], ?string $reason = null): bool
|
||||
{
|
||||
switch ($activity->getVerb()) {
|
||||
case 'repeat':
|
||||
Event::handle('NewNotification', [$sender, $activity, [], _m('{nickname} repeated note {note_id}.', ['{nickname}' => $sender->getNickname(), '{note_id}' => $activity->getObjectId()])]);
|
||||
return Event::stop;
|
||||
case 'undo':
|
||||
if ($activity->getObjectType() === 'activity') {
|
||||
$undone_repeat = $activity->getObject();
|
||||
if ($undone_repeat->getVerb() === 'repeat') {
|
||||
Event::handle('NewNotification', [$sender, $activity, [], _m('{nickname} unrepeated note {note_id}.', ['{nickname}' => $sender->getNickname(), '{note_id}' => $undone_repeat->getObjectId()])]);
|
||||
return Event::stop;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an Activity Streams 2.0 Announce or Undo Announce into the appropriate Repeat and Undo Repeat entities
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user