3
3
namespace App \Discord \FlowMeasure \Content ;
4
4
5
5
use App \Discord \FlowMeasure \Provider \PendingMessageInterface ;
6
+ use App \Discord \FlowMeasure \Provider \PendingWebhookMessageInterface ;
6
7
use App \Discord \Message \Tag \Tag ;
7
8
use App \Enums \DiscordNotificationType ;
9
+ use App \Models \DiscordNotification ;
8
10
use App \Models \DivisionDiscordNotification ;
9
11
use App \Models \DiscordTag ;
10
12
use App \Models \DivisionDiscordWebhook ;
13
15
14
16
class FlowMeasureRecipientsFactory
15
17
{
16
- public function makeRecipients (PendingMessageInterface $ pendingMessage ): FlowMeasureRecipientsInterface
18
+ public function makeRecipients (PendingWebhookMessageInterface $ pendingMessage ): FlowMeasureRecipientsInterface
19
+ {
20
+ if ($ this ->hasRecentlyBeenNotifiedToWebhook ($ pendingMessage )) {
21
+ return new NoRecipients ();
22
+ }
23
+
24
+ return $ this ->divisionRecipients ($ pendingMessage );
25
+ }
26
+
27
+ public function makeEcfmpRecipients (PendingMessageInterface $ pendingMessage ): FlowMeasureRecipientsInterface
17
28
{
18
29
if ($ this ->hasRecentlyBeenNotified ($ pendingMessage )) {
19
30
return new NoRecipients ();
20
31
}
21
32
22
- return $ pendingMessage ->webhook () === null
23
- ? $ this ->ecfmpRecipients ($ pendingMessage )
24
- : $ this ->divisionRecipients ($ pendingMessage );
33
+ return $ this ->ecfmpRecipients ($ pendingMessage );
25
34
}
26
35
27
- private function hasRecentlyBeenNotified ( PendingMessageInterface $ pendingMessage ): bool
36
+ private function hasRecentlyBeenNotifiedToWebhook ( PendingWebhookMessageInterface $ pendingMessage ): bool
28
37
{
29
38
$ measure = $ pendingMessage ->flowMeasure ();
30
39
return $ pendingMessage ->type (
@@ -34,6 +43,16 @@ private function hasRecentlyBeenNotified(PendingMessageInterface $pendingMessage
34
43
) !== null ;
35
44
}
36
45
46
+ private function hasRecentlyBeenNotified (PendingMessageInterface $ pendingMessage ): bool
47
+ {
48
+ $ measure = $ pendingMessage ->flowMeasure ();
49
+ return $ pendingMessage ->type (
50
+ ) === DiscordNotificationType::FLOW_MEASURE_ACTIVATED && $ measure ->notifiedEcfmpNotifications ->firstWhere (
51
+ fn (DiscordNotification $ notification ) => $ notification ->created_at > Carbon::now ()->subHour () &&
52
+ $ notification ->pivot ->notified_as === $ measure ->identifier
53
+ ) !== null ;
54
+ }
55
+
37
56
private function ecfmpRecipients (PendingMessageInterface $ pendingMessage ): FlowMeasureRecipientsInterface
38
57
{
39
58
return new EcfmpInterestedParties (
@@ -44,7 +63,7 @@ private function ecfmpRecipients(PendingMessageInterface $pendingMessage): FlowM
44
63
);
45
64
}
46
65
47
- private function divisionRecipients (PendingMessageInterface $ pendingMessage ): FlowMeasureRecipientsInterface
66
+ private function divisionRecipients (PendingWebhookMessageInterface $ pendingMessage ): FlowMeasureRecipientsInterface
48
67
{
49
68
$ recipients = DivisionDiscordWebhook::find ($ pendingMessage ->webhook ()->id ())
50
69
->flightInformationRegions
0 commit comments