Skip to content

Push notification: add notification id #1451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function registerPushNotifications(#[MapRequestPayload] RegisterPushReque
$this->entityManager->flush();

try {
$testNotification = new PushNotification('', $this->translator->trans('test_push_message', locale: $pushSubscription->locale));
$testNotification = new PushNotification(null, '', $this->translator->trans('test_push_message', locale: $pushSubscription->locale));
$this->pushSubscriptionManager->sendTextToUser($user, $testNotification, specificDeviceKey: $payload->deviceKey);

return new JsonResponse();
Expand Down Expand Up @@ -311,7 +311,7 @@ public function testPushNotification(#[MapRequestPayload] TestPushRequestPayload
{
$user = $this->getUserOrThrow();
try {
$this->pushSubscriptionManager->sendTextToUser($user, new PushNotification('', $this->translator->trans('test_push_message')), specificDeviceKey: $payload->deviceKey);
$this->pushSubscriptionManager->sendTextToUser($user, new PushNotification(null, '', $this->translator->trans('test_push_message')), specificDeviceKey: $payload->deviceKey);

return new JsonResponse();
} catch (\ErrorException $e) {
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Api/Notification/NotificationPushApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function createSubscription(
$this->entityManager->flush();

try {
$testNotification = new PushNotification('', $translator->trans('test_push_message', locale: $pushSubscription->locale));
$testNotification = new PushNotification(null, '', $translator->trans('test_push_message', locale: $pushSubscription->locale));
$pushSubscriptionManager->sendTextToUser($user, $testNotification, specificToken: $apiToken);

return new JsonResponse(headers: $headers);
Expand Down Expand Up @@ -220,7 +220,7 @@ public function testSubscription(

$sub = $repository->findOneBy(['user' => $user, 'apiToken' => $apiToken]);
if ($sub) {
$testNotification = new PushNotification('', $translator->trans('test_push_message', locale: $sub->locale));
$testNotification = new PushNotification(null, '', $translator->trans('test_push_message', locale: $sub->locale));
try {
$pushSubscriptionManager->sendTextToUser($user, $testNotification, specificToken: $apiToken);

Expand Down
2 changes: 1 addition & 1 deletion src/Entity/EntryCommentCreatedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'comment_id' => $this->entryComment->getId(),
]);

return new PushNotification($message, $trans->trans('notification_title_new_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_new_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/EntryCommentDeletedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'comment_id' => $this->entryComment->getId(),
]);

return new PushNotification($message, $trans->trans('notification_title_removed_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_removed_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/EntryCommentEditedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'comment_id' => $this->entryComment->getId(),
]);

return new PushNotification($message, $trans->trans('notification_title_edited_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_edited_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/EntryCommentMentionedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'comment_id' => $this->entryComment->getId(),
]);

return new PushNotification($message, $trans->trans('notification_title_mention', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_mention', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/EntryCommentReplyNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'comment_id' => $this->entryComment->getId(),
]);

return new PushNotification($message, $trans->trans('notification_title_new_reply', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_new_reply', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/EntryCreatedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => $this->entry->slug ?? '-',
]);

return new PushNotification($message, $trans->trans('notification_title_new_thread', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_new_thread', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/EntryDeletedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => $this->entry->slug ?? '-',
]);

return new PushNotification($message, $trans->trans('notification_title_removed_thread', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_removed_thread', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/EntryEditedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => $this->entry->slug ?? '-',
]);

return new PushNotification($message, $trans->trans('notification_title_edited_thread', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_edited_thread', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/EntryMentionedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => $this->entry->slug ?? '-',
]);

return new PushNotification($message, $trans->trans('notification_title_mention', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_mention', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/MagazineBanNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
$slash = $this->ban->bannedBy->avatar && !str_starts_with('/', $this->ban->bannedBy->avatar->filePath) ? '/' : '';
$avatarUrl = $this->ban->bannedBy->avatar ? '/media/cache/resolve/avatar_thumb'.$slash.$this->ban->bannedBy->avatar->filePath : null;

return new PushNotification($message, $trans->trans('notification_title_ban', locale: $locale), avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_ban', locale: $locale), avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/MessageNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
$avatarUrl = $this->message->sender->avatar ? '/media/cache/resolve/avatar_thumb'.$slash.$this->message->sender->avatar->filePath : null;
$url = $urlGenerator->generate('messages_single', ['id' => $this->message->thread->getId()]);

return new PushNotification($message, $trans->trans('notification_title_message', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl, category: EPushNotificationType::Message);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_message', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl, category: EPushNotificationType::Message);
}
}
2 changes: 1 addition & 1 deletion src/Entity/NewSignupNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
$slash = $this->newUser->avatar && !str_starts_with('/', $this->newUser->avatar->filePath) ? '/' : '';
$avatarUrl = $this->newUser->avatar ? '/media/cache/resolve/avatar_thumb'.$slash.$this->newUser->avatar->filePath : null;

return new PushNotification($message, $title, actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $title, actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/PostCommentCreatedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => empty($this->postComment->post->slug) ? '-' : $this->postComment->post->slug,
]).'#post-comment-'.$this->postComment->getId();

return new PushNotification($message, $trans->trans('notification_title_new_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_new_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/PostCommentDeletedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => empty($this->postComment->post->slug) ? '-' : $this->postComment->post->slug,
]).'#post-comment-'.$this->postComment->getId();

return new PushNotification($message, $trans->trans('notification_title_removed_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_removed_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/PostCommentEditedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => empty($this->postComment->post->slug) ? '-' : $this->postComment->post->slug,
]).'#post-comment-'.$this->postComment->getId();

return new PushNotification($message, $trans->trans('notification_title_edited_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_edited_comment', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/PostCommentMentionedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => empty($this->postComment->post->slug) ? '-' : $this->postComment->post->slug,
]).'#post-comment-'.$this->postComment->getId();

return new PushNotification($message, $trans->trans('notification_title_mention', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_mention', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/PostCommentReplyNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => empty($this->postComment->post->slug) ? '-' : $this->postComment->post->slug,
]).'#post-comment-'.$this->postComment->getId();

return new PushNotification($message, $trans->trans('notification_title_new_reply', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_new_reply', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/PostCreatedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => empty($this->postComment->post->slug) ? '-' : $this->postComment->post->slug,
]);

return new PushNotification($message, $trans->trans('notification_title_new_post', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_new_post', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/PostDeletedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => empty($this->postComment->post->slug) ? '-' : $this->postComment->post->slug,
]);

return new PushNotification($message, $trans->trans('notification_title_removed_post', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_removed_post', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/PostEditedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => empty($this->postComment->post->slug) ? '-' : $this->postComment->post->slug,
]);

return new PushNotification($message, $trans->trans('notification_title_edited_post', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_edited_post', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/PostMentionedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
'slug' => empty($this->postComment->post->slug) ? '-' : $this->postComment->post->slug,
]);

return new PushNotification($message, $trans->trans('notification_title_mention', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_mention', locale: $locale), actionUrl: $url, avatarUrl: $avatarUrl);
}
}
2 changes: 1 addition & 1 deletion src/Entity/ReportApprovedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
$actionUrl = $linkToReport;
}

return new PushNotification($message, $title, actionUrl: $actionUrl);
return new PushNotification($this->getId(), $message, $title, actionUrl: $actionUrl);
}

private function getSubjectLink(ReportInterface $subject, UrlGeneratorInterface $urlGenerator): string
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/ReportCreatedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
$message = \sprintf('%s %s %s\n%s: %s', $this->report->reporting->username, $trans->trans('reported', locale: $locale), $this->report->reported->username,
$trans->trans('report_subject', locale: $locale), $subject->getShortTitle());

return new PushNotification($message, $trans->trans('notification_title_new_report'), actionUrl: $reportLink);
return new PushNotification($this->getId(), $message, $trans->trans('notification_title_new_report'), actionUrl: $reportLink);
}
}
2 changes: 1 addition & 1 deletion src/Entity/ReportRejectedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getMessage(TranslatorInterface $trans, string $locale, UrlGenera
$trans->trans('report_subject', locale: $locale), $subject->getShortTitle()
);

return new PushNotification($message, $trans->trans('own_report_rejected', locale: $locale), actionUrl: $this->getSubjectLink($subject, $urlGenerator));
return new PushNotification($this->getId(), $message, $trans->trans('own_report_rejected', locale: $locale), actionUrl: $this->getSubjectLink($subject, $urlGenerator));
}

private function getSubjectLink(ReportInterface $subject, UrlGeneratorInterface $urlGenerator): string
Expand Down
2 changes: 2 additions & 0 deletions src/Payloads/PushNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
class PushNotification
{
public function __construct(
// The id of the notification entity
public ?int $id,
public string $message,
public string $title,
public ?string $actionUrl = null,
Expand Down
Loading