6
6
use App \Helpers \NameHelper ;
7
7
use App \Models \ContactReminder ;
8
8
use App \Models \UserNotificationChannel ;
9
- use App \Models \UserNotificationSent ;
10
9
use App \Notifications \ReminderTriggered ;
11
10
use Carbon \Carbon ;
12
11
use Illuminate \Bus \Queueable ;
@@ -39,24 +38,24 @@ public function handle()
39
38
->get ();
40
39
41
40
foreach ($ scheduledContactReminders as $ scheduledReminder ) {
42
- $ channel = UserNotificationChannel::findOrFail ($ scheduledReminder ->user_notification_channel_id );
41
+ $ userNotificationChannel = UserNotificationChannel::findOrFail ($ scheduledReminder ->user_notification_channel_id );
43
42
44
- if ($ channel ->type === UserNotificationChannel::TYPE_EMAIL ) {
45
- $ contactReminder = ContactReminder::find ($ scheduledReminder ->contact_reminder_id );
43
+ $ contactReminder = ContactReminder::find ($ scheduledReminder ->contact_reminder_id );
44
+
45
+ if ($ userNotificationChannel ->type === UserNotificationChannel::TYPE_EMAIL ) {
46
46
$ contact = $ contactReminder ->contact ;
47
- $ contactName = NameHelper::formatContactName ($ channel ->user , $ contact );
47
+ $ contactName = NameHelper::formatContactName ($ userNotificationChannel ->user , $ contact );
48
48
49
- Notification::route ('mail ' , $ channel ->content )
50
- ->notify (new ReminderTriggered ($ channel , $ contactReminder ->label , $ contactName ));
49
+ Notification::route ('mail ' , $ userNotificationChannel ->content )
50
+ ->notify (new ReminderTriggered ($ userNotificationChannel , $ contactReminder ->label , $ contactName ));
51
+ }
51
52
52
- UserNotificationSent::create ([
53
- 'user_notification_channel_id ' => $ channel ->id ,
54
- 'sent_at ' => Carbon::now (),
55
- 'subject_line ' => $ contactReminder ->label ,
56
- ]);
53
+ if ($ userNotificationChannel ->type === UserNotificationChannel::TYPE_TELEGRAM ) {
54
+ Notification::route ('telegram ' , $ userNotificationChannel ->content )
55
+ ->notify (new ReminderTriggered ($ userNotificationChannel , $ contactReminder ->label , '' ));
57
56
}
58
57
59
- $ this ->updateScheduledContactReminderTriggeredAt ($ scheduledReminder-> id );
58
+ $ this ->updateScheduledContactReminderTriggeredAt ($ scheduledReminder );
60
59
$ this ->updateNumberOfTimesTriggered ($ scheduledReminder ->contact_reminder_id );
61
60
62
61
$ this ->appendToChain (
@@ -69,13 +68,13 @@ public function handle()
69
68
}
70
69
}
71
70
72
- private function updateScheduledContactReminderTriggeredAt (int $ id ): void
71
+ private function updateScheduledContactReminderTriggeredAt ($ scheduledReminder ): void
73
72
{
74
- DB :: table ( ' contact_reminder_scheduled ' )
75
- -> where ( ' id ' , $ id )
76
- -> update ([
77
- ' triggered_at ' => Carbon:: now () ,
78
- ] );
73
+ ( new RescheduleContactReminderForChannel ([
74
+ ' contact_reminder_id ' => $ scheduledReminder -> contact_reminder_id ,
75
+ ' user_notification_channel_id ' => $ scheduledReminder -> user_notification_channel_id ,
76
+ ' contact_reminder_scheduled_id ' => $ scheduledReminder -> id ,
77
+ ]))-> handle ( );
79
78
}
80
79
81
80
private function updateNumberOfTimesTriggered (int $ id ): void
0 commit comments