Return the newly created notification for handling

This commit is contained in:
2025-08-11 14:30:07 +02:00
parent 658c9fecf6
commit e75254f930

View File

@ -112,7 +112,7 @@ class InstagramNotificationHandlingJob extends InstagramAbstractJob implements S
} }
} }
private function saveNotifications(Browser $browser): void private function saveNotifications(Browser $browser): ?array
{ {
$this->openNotificationsPanel($browser); $this->openNotificationsPanel($browser);
try { try {
@ -123,7 +123,7 @@ class InstagramNotificationHandlingJob extends InstagramAbstractJob implements S
$DOMnotificationText = $DOMnotification->findElement(WebDriverBy::xpath('./div[2]/span')); $DOMnotificationText = $DOMnotification->findElement(WebDriverBy::xpath('./div[2]/span'));
$notification = new InstagramNotification(); $notification = new InstagramNotification();
$notification->username = str_replace( "/", "", $DOMnotificationText->findElement(WebDriverBy::xpath('./a[1]'))->getAttribute('href')); $notification->username = str_replace("/", "", $DOMnotificationText->findElement(WebDriverBy::xpath('./a[1]'))->getAttribute('href'));
$notification->notification_type = NotificationTypeDetector::detectType($DOMnotificationText->getText()); $notification->notification_type = NotificationTypeDetector::detectType($DOMnotificationText->getText());
// 05/08/2025 : Instagram removed the link to the post in the notification, the day I'm working on it :() // 05/08/2025 : Instagram removed the link to the post in the notification, the day I'm working on it :()
$postId = null; $postId = null;
@ -135,8 +135,7 @@ class InstagramNotificationHandlingJob extends InstagramAbstractJob implements S
if ($repostId) { if ($repostId) {
$notification->instagram_repost_id = $repostId; $notification->instagram_repost_id = $repostId;
} }
} } catch (\Exception $e) {
catch (\Exception $e) {
Log::error("Failed to get post ID from notification : " . $e->getMessage()); Log::error("Failed to get post ID from notification : " . $e->getMessage());
} }
$notification->message = $DOMnotificationText->getText(); $notification->message = $DOMnotificationText->getText();
@ -146,16 +145,17 @@ class InstagramNotificationHandlingJob extends InstagramAbstractJob implements S
$notification->save(); $notification->save();
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error("Failed to save notification : " . $e->getMessage()); Log::error("Failed to save notification : " . $e->getMessage());
continue; // Skip to the next notification break; // Stop processing further notifications if one fails
} }
dump("Notification saved : " . $notification); dump("Notification saved : " . $notification);
$notifications[] = $notification; $notifications[] = $notification;
} }
return $notifications;
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error("Failed to get notifications : " . $e->getMessage()); Log::error("Failed to get notifications : " . $e->getMessage());
$browser->screenshot(JobDebugScreenshot::getFileName($this->jobId)); $browser->screenshot(JobDebugScreenshot::getFileName($this->jobId));
AllNotification::send(new JobDebugNotification($this->jobId, "Failed to open notifications panel: " . $e->getMessage())); AllNotification::send(new JobDebugNotification($this->jobId, "Failed to open notifications panel: " . $e->getMessage()));
return; return null;
} }
} }