[PLUGIN][ActivityPub][Notification] Fix some issues with targetting
This commit is contained in:
parent
e63c310d70
commit
56b8710b26
|
@ -143,9 +143,9 @@ class ActivityPub extends Plugin
|
|||
);
|
||||
|
||||
DB::flush();
|
||||
if ($ap_act->getToNotifyTargets() !== []) {
|
||||
if (Event::handle('ActivityPubNewNotification', [$actor, $ap_act->getActivity(), $ap_act->getAttentionTargets(), _m('{actor_id} triggered a notification via ActivityPub.', ['{actor_id}' => $actor->getId()])]) === Event::next) {
|
||||
Event::handle('NewNotification', [$actor, $ap_act->getActivity(), $ap_act->getAttentionTargets(), _m('{actor_id} triggered a notification via ActivityPub.', ['{nickname}' => $actor->getId()])]);
|
||||
if (($att_targets = $ap_act->getAttentionTargets()) !== []) {
|
||||
if (Event::handle('ActivityPubNewNotification', [$actor, ($act = $ap_act->getActivity()), $att_targets, _m('{actor_id} triggered a notification via ActivityPub.', ['{actor_id}' => $actor->getId()])]) === Event::next) {
|
||||
Event::handle('NewNotification', [$actor, $act, $att_targets, _m('{actor_id} triggered a notification via ActivityPub.', ['{nickname}' => $actor->getId()])]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -468,7 +468,7 @@ class ActivityPub extends Plugin
|
|||
try {
|
||||
if (FreeNetworkActorProtocol::canIAddr('activitypub', $addr = Discovery::normalize($target))) {
|
||||
$ap_actor = DB::wrapInTransaction(fn () => ActivitypubActor::getByAddr($addr));
|
||||
$actor = Actor::getById($ap_actor->getActorId());
|
||||
$actor = Actor::getById($ap_actor->getActorId());
|
||||
FreeNetworkActorProtocol::protocolSucceeded('activitypub', $actor->getId(), $addr);
|
||||
return Event::stop;
|
||||
} else {
|
||||
|
|
|
@ -115,6 +115,16 @@ class ActivitypubObject extends Entity
|
|||
return DB::findOneBy($this->getObjectType(), ['id' => $this->getObjectId()]);
|
||||
}
|
||||
|
||||
public function getAttentionTargetIds(): array
|
||||
{
|
||||
return $this->getObject()->getAttentionTargetIds();
|
||||
}
|
||||
|
||||
public function getAttentionTargets(): array
|
||||
{
|
||||
return $this->getObject()->getAttentionTargets();
|
||||
}
|
||||
|
||||
public static function schemaDef(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -78,7 +78,7 @@ class Favourite extends FeedController
|
|||
if ($form_add_to_favourite->isSubmitted()) {
|
||||
if (!\is_null($activity = \Plugin\Favourite\Favourite::favourNote(note_id: $id, actor_id: $actor_id))) {
|
||||
DB::flush();
|
||||
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $activity, [], _m('{actor_id} favoured note {note_id}.', ['{actor_id}' => $actor->getId(), '{note_id}' => $activity->getObjectId()])]);
|
||||
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $activity, $activity->getAttentionTargets(), _m('{actor_id} favoured note {note_id}.', ['{actor_id}' => $actor->getId(), '{note_id}' => $activity->getObjectId()])]);
|
||||
} else {
|
||||
throw new ClientException(_m('Note already favoured!'));
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ class Favourite extends FeedController
|
|||
if ($form_remove_favourite->isSubmitted()) {
|
||||
if (!\is_null($activity = \Plugin\Favourite\Favourite::unfavourNote(note_id: $id, actor_id: $actor_id))) {
|
||||
DB::flush();
|
||||
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $activity, [], _m('{actor_id} unfavoured note {note_id}.', ['{actor_id}' => $actor->getId(), '{note_id}' => $activity->getObjectId()])]);
|
||||
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $activity, $activity->getAttentionTargets(), _m('{actor_id} unfavoured note {note_id}.', ['{actor_id}' => $actor->getId(), '{note_id}' => $activity->getObjectId()])]);
|
||||
} else {
|
||||
throw new ClientException(_m('Note already unfavoured!'));
|
||||
}
|
||||
|
|
|
@ -110,11 +110,11 @@ class NoteFavourite extends Entity
|
|||
self::cacheKeys($note)['favourites-actors'],
|
||||
fn () => DB::dql(
|
||||
<<<'EOF'
|
||||
select a from actor a
|
||||
inner join note_favourite nf
|
||||
with a.id = nf.actor_id
|
||||
where nf.note_id = :note_id
|
||||
order by nf.created DESC
|
||||
SELECT a FROM actor AS a
|
||||
INNER JOIN note_favourite AS nf
|
||||
WITH a.id = nf.actor_id
|
||||
WHERE nf.note_id = :note_id
|
||||
ORDER BY nf.created DESC
|
||||
EOF,
|
||||
['note_id' => $note->getId()],
|
||||
),
|
||||
|
|
|
@ -75,7 +75,7 @@ class Repeat extends Controller
|
|||
if ($form_add_to_repeat->isSubmitted()) {
|
||||
$repeat_activity = \Plugin\RepeatNote\RepeatNote::repeatNote(note: $note, actor_id: $actor_id);
|
||||
DB::flush();
|
||||
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $repeat_activity, [], _m('{actor_id} repeated note {note_id}.', ['{actor_id}' => $actor->getId(), '{note_id}' => $repeat_activity->getObjectId()])]);
|
||||
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $repeat_activity, $repeat_activity->getAttentionTargets(), _m('{actor_id} repeated note {note_id}.', ['{actor_id}' => $actor->getId(), '{note_id}' => $repeat_activity->getObjectId()])]);
|
||||
|
||||
// Redirect user to where they came from
|
||||
// Prevent open redirect
|
||||
|
@ -132,7 +132,7 @@ class Repeat extends Controller
|
|||
if ($form_remove_repeat->isSubmitted()) {
|
||||
if (!\is_null($undo_repeat_activity = \Plugin\RepeatNote\RepeatNote::unrepeatNote(note_id: $note_id, actor_id: $actor_id))) {
|
||||
DB::flush();
|
||||
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $undo_repeat_activity, [], _m('{actor_id} unrepeated note {note_id}.', ['{actor_id}' => $actor->getId(), '{note_id}' => $note_id])]);
|
||||
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $undo_repeat_activity, $undo_repeat_activity->getAttentionTargets(), _m('{actor_id} unrepeated note {note_id}.', ['{actor_id}' => $actor->getId(), '{note_id}' => $note_id])]);
|
||||
} else {
|
||||
throw new ClientException(_m('Note wasn\'t repeated!'));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user