Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ECFMP/flow
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.11.1
Choose a base ref
...
head repository: ECFMP/flow
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
Showing with 4,683 additions and 1,585 deletions.
  1. +6 −0 .env.example
  2. +16 −1 .github/workflows/test.yml
  3. +3 −0 .gitignore
  4. +3 −0 .gitmodules
  5. +38 −0 app/Console/Commands/SendEcfmpDiscordMessages.php
  6. +32 −0 app/Discord/Client/ClientFactory.php
  7. +10 −0 app/Discord/Client/ClientFactoryInterface.php
  8. +16 −0 app/Discord/DiscordServiceInterface.php
  9. +61 −0 app/Discord/DiscordServiceMessageSender.php
  10. +2 −2 app/Discord/{DiscordInterface.php → DiscordWebhookInterface.php}
  11. +1 −1 app/Discord/{DiscordMessageSender.php → DiscordWebhookSender.php}
  12. +9 −0 app/Discord/Exception/DiscordServiceException.php
  13. +3 −3 app/Discord/FlowMeasure/Associator/FlowMeasureAssociator.php
  14. +25 −6 app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php
  15. +1 −1 app/Discord/FlowMeasure/Embed/ActivatedEmbeds.php
  16. +1 −1 app/Discord/FlowMeasure/Embed/NotifiedEmbeds.php
  17. +37 −0 app/Discord/FlowMeasure/Generator/EcfmpFlowMeasureMessageGenerator.php
  18. +24 −0 app/Discord/FlowMeasure/Helper/EcfmpNotificationReissuer.php
  19. +5 −4 app/Discord/FlowMeasure/Helper/NotificationReissuer.php
  20. +2 −2 app/Discord/FlowMeasure/Logger/FlowMeasureLogger.php
  21. +37 −0 app/Discord/FlowMeasure/Message/EcfmpFlowMeasureMessage.php
  22. +12 −1 app/Discord/FlowMeasure/Message/FlowMeasureMessageFactory.php
  23. +2 −2 app/Discord/FlowMeasure/Provider/{MessageProvider.php → DivisionWebhookMessageProvider.php}
  24. +6 −1 app/Discord/FlowMeasure/Provider/{PendingDiscordMessage.php → PendingDiscordWebhookMessage.php}
  25. +43 −0 app/Discord/FlowMeasure/Provider/PendingEcfmpMessage.php
  26. +5 −3 app/Discord/FlowMeasure/Provider/PendingMessageInterface.php
  27. +10 −0 app/Discord/FlowMeasure/Provider/PendingWebhookMessageInterface.php
  28. +66 −0 app/Discord/FlowMeasure/Sender/EcfmpFlowMeasureSender.php
  29. +2 −2 app/Discord/FlowMeasure/Webhook/Filter/ActivatedWebhookFilter.php
  30. +7 −7 app/Discord/FlowMeasure/Webhook/Filter/ExpiredWebhookFilter.php
  31. +3 −3 app/Discord/FlowMeasure/Webhook/Filter/NotifiedWebhookFilter.php
  32. +2 −2 app/Discord/FlowMeasure/Webhook/Filter/WithdrawnWebhookFilter.php
  33. +2 −5 app/Discord/FlowMeasure/Webhook/WebhookMapper.php
  34. +2 −2 app/Discord/Message/Associator/AssociatorInterface.php
  35. +26 −0 app/Discord/Message/EcfmpMessageInterface.php
  36. +32 −0 app/Discord/Message/Embed/Embed.php
  37. +5 −0 app/Discord/Message/Embed/EmbedCollection.php
  38. +7 −0 app/Discord/Message/Embed/EmbedInterface.php
  39. +2 −2 app/Discord/Message/Logger/LoggerInterface.php
  40. +6 −6 app/Discord/Message/Sender/{Sender.php → DivisionWebhookSender.php}
  41. +0 −21 app/Discord/Webhook/EcfmpWebhook.php
  42. +2 −2 app/Filament/Resources/DivisionDiscordWebhookResource.php
  43. +2 −0 app/Filament/Resources/FlowMeasureResource/Pages/CreateFlowMeasure.php
  44. +4 −0 app/Filament/Resources/FlowMeasureResource/Pages/EditFlowMeasure.php
  45. +23 −2 app/Helpers/FlowMeasureIdentifierGenerator.php
  46. +10 −3 app/Jobs/SendDiscordNotifications.php
  47. +3 −0 app/Jobs/UpdateNetworkData.php
  48. +2 −37 app/Models/DiscordNotification.php
  49. +60 −0 app/Models/DivisionDiscordNotification.php
  50. +83 −23 app/Models/FlowMeasure.php
  51. +40 −14 app/Providers/DiscordServiceProvider.php
  52. +34 −1 app/Repository/FlowMeasureNotification/ActiveRepository.php
  53. +31 −1 app/Repository/FlowMeasureNotification/ExpiredRepository.php
  54. +14 −0 app/Repository/FlowMeasureNotification/FlowMeasureForNotification.php
  55. +36 −1 app/Repository/FlowMeasureNotification/NotifiedRepository.php
  56. +5 −0 app/Repository/FlowMeasureNotification/RepositoryInterface.php
  57. +28 −1 app/Repository/FlowMeasureNotification/WithdrawnRepository.php
  58. +8 −2 composer.json
  59. +729 −387 composer.lock
  60. +5 −1 config/discord.php
  61. +1 −13 database/factories/DiscordNotificationFactory.php
  62. +35 −0 database/factories/DivisionDiscordNotificationFactory.php
  63. +12 −1 database/factories/FlowMeasureFactory.php
  64. +22 −0 database/migrations/2023_10_08_112953_rename_discord_notifications_tables.php
  65. +24 −0 ...grations/2023_10_08_122743_rename_column_on_division_discord_notification_flow_measures_table.php
  66. +28 −0 database/migrations/2023_10_08_123536_create_discord_notifications_table.php
  67. +44 −0 database/migrations/2023_10_08_123708_create_discord_notification_flow_measure_table.php
  68. +34 −0 database/migrations/2023_10_14_150204_add_columns_to_flow_measures_table.php
  69. +27 −0 database/migrations/2023_10_14_150428_update_flow_measure_data.php
  70. +726 −0 database/schema/mysql-schema.sql
  71. +42 −21 docker-compose.yml
  72. +59 −0 docker/8.2/Dockerfile
  73. +4 −0 docker/8.2/php.ini
  74. +17 −0 docker/8.2/start-container
  75. +14 −0 docker/8.2/supervisord.conf
  76. +275 −180 package-lock.json
  77. +5 −5 package.json
  78. +1 −0 protobuf
  79. +0 −1 routes/web.php
  80. +39 −0 tests/Console/Commands/SendEcfmpDiscordMessagesTest.php
  81. +108 −0 tests/Discord/DiscordServiceMessageSenderTest.php
  82. +4 −4 tests/Discord/{DiscordMessageSenderTest.php → DiscordWebhookSenderTest.php}
  83. +5 −5 tests/Discord/FlowMeasure/Associator/FlowMeasureAssociatorTest.php
  84. +166 −45 tests/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactoryTest.php
  85. +4 −10 tests/Discord/FlowMeasure/Embed/ActivatedEmbedsTest.php
  86. +4 −10 tests/Discord/FlowMeasure/Embed/NotifiedEmbedsTest.php
  87. +65 −0 tests/Discord/FlowMeasure/Generator/EcfmpFlowMeasureMessageGeneratorTest.php
  88. +35 −0 tests/Discord/FlowMeasure/Helper/EcfmpNotificationReissuerTest.php
  89. +142 −159 tests/Discord/FlowMeasure/Helper/NotificationReissuerTest.php
  90. +5 −5 tests/Discord/FlowMeasure/Logger/FlowMeasureLoggerTest.php
  91. +21 −6 tests/Discord/FlowMeasure/Message/FlowMeasureMessageFactoryTest.php
  92. +3 −3 tests/Discord/FlowMeasure/Message/MessageGeneratorTest.php
  93. +4 −4 ...s/Discord/FlowMeasure/Provider/{MessageProviderTest.php → DivisionWebhookMessageProviderTest.php}
  94. +10 −4 ...gDiscordMessageTest.php → tests/Discord/FlowMeasure/Provider/PendingDiscordWebhookMessageTest.php
  95. +47 −0 tests/Discord/FlowMeasure/Provider/PendingEcfmpMessageTest.php
  96. +88 −0 tests/Discord/FlowMeasure/Sender/EcfmpFlowMeasureSenderTest.php
  97. +7 −90 tests/Discord/FlowMeasure/Webhook/Filter/ActivatedWebhookFilterTest.php
  98. +9 −172 tests/Discord/FlowMeasure/Webhook/Filter/ExpiredWebhookFilterTest.php
  99. +7 −90 tests/Discord/FlowMeasure/Webhook/Filter/NotifiedWebhookFilterTest.php
  100. +11 −124 tests/Discord/FlowMeasure/Webhook/Filter/WithdrawnWebhookFilterTest.php
  101. +8 −20 tests/Discord/FlowMeasure/Webhook/WebhookMapperTest.php
  102. +19 −0 tests/Discord/Message/Embed/EmbedCollectionTest.php
  103. +95 −0 tests/Discord/Message/Embed/EmbedTest.php
  104. +7 −7 tests/Discord/Message/Sender/{SenderTest.php → DivisionWebhookSenderTest.php}
  105. +0 −37 tests/Discord/Webhook/EcfmpWebhookTest.php
  106. +64 −2 tests/Feature/Filament/FlowMeasureResourceTest.php
  107. +23 −0 tests/Helpers/FlowMeasureIdentifierGeneratorTest.php
  108. +14 −5 tests/Jobs/SendDiscordNotificationsTest.php
  109. +149 −2 tests/Repository/FlowMeasureNotification/ActiveRepositoryTest.php
  110. +207 −3 tests/Repository/FlowMeasureNotification/ExpiredRepositoryTest.php
  111. +105 −2 tests/Repository/FlowMeasureNotification/NotifiedRepositoryTest.php
  112. +146 −2 tests/Repository/FlowMeasureNotification/WithdrawnRepositoryTest.php
  113. +1 −0 tests/TestCase.php
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -62,7 +62,13 @@ DISCORD_AUTH_TOKEN=abc
DISCORD_WEBHOOK_URL=def
DISCORD_USERNAME=FlowBot
DISCORD_AVATAR_URL="${APP_URL}/images/logo.png"
DISCORD_ECFMP_CHANNEL_ID="971531731096203364"

# Sentry monitoring
SENTRY_LARAVEL_DSN=
SENTRY_TRACES_SAMPLE_RATE=1.0

# Discord bot
DISCORD_BOT_SERVICE_URL="discord-bot:80"
DISCORD_BOT_JWT="eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJlY2ZtcC1mbG93IiwiYXVkIjoiZWNmbXAtZGlzY29yZC1kZXYiLCJpYXQiOjIxMzg0NTQ1NTUsImlzcyI6ImVjZm1wLWF1dGgifQ.PqbCEe_zW1WBLio6aD0P5OksRI1H-hoRRA8168OJg-h11SjyZeDCAAf0CjgZAUy6vUpSdfgN9KH1SgCSM4J38-2txpZLr_VlJTu9_W1mGEVr1_pGjMgbkwx8PMTP1f3J2R0BwGz-324vpPVB9zu6NG9ujS48AD28mDoqMpqc7UOK0_e9WJ7cQBb8BxU10w4TQXbwhjUMyZBIpdiaDK5OsQeXJruo0OjSlltiFJkXPmESTz_DwwTSvIqzmhjzQfNW62RVcnBrnbWaaCg1mC6FSIMffjrEgian_AyAg1iftjy_fa3f-sU-z65xMh8vVwAvJEhYJCA0CZO4lKn_OV0RXqYjCLI4t-Rp6MYULyLbp6QZ88MOvSXd-8GnYnxDE5o5-rLFnQ04LCGx2-yBDPZ80brdxZR26Im1DrNiPyUFadINGf8wwZ4-iWqmY6_QSfJYU1C3Y5s7TxMBFfa934NHICg53gVSEdfCHQIaciOSu91P1FnGIvdtOQV_n7urF5HRYyxOUomSa4MY4m5C1-TJqpBkCsAXbMdC_mIllFWnUCB5uBj5T18mxW1mrGQiF3Vy6_MrSeFoY0LEnd58QpvnG7-OuZWnrIbDDTAnTcI1IMVUA4zcoUvkUcCcRvBQD2bXsPgL9Lh8RmYvjrR2hWhmlJU-k_CPiQOLfW9qOFGp5rA"
DISCORD_CLIENT_REQUEST_APP_ID="ecfmpdev"
17 changes: 16 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -21,14 +21,29 @@ jobs:
composer: ["v2"]
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: true

- name: Checkout Discord Service
uses: actions/checkout@v4
with:
repository: ecfmp/discord
path: ecfmp-discord

- name: Move Discord Service
run: mv ecfmp-discord ../ecfmp-discord

- name: Build Protobuf
run: (cd protobuf && make pull_builder && make discord_proto)

- name: Configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: pcov
tools: composer:${{ matrix.composer }}
extensions: grpc

# Setting up composer dependencies
- name: Get Composer Cache Directory
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache
.phpunit.cache
.idea

# Laravel IDE Helper
@@ -39,3 +40,5 @@ public/mix-manifest.json
storage/imports

.vscode

.DS_STORE
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "protobuf"]
path = protobuf
url = git@github.com:ECFMP/ecfmp-protobuf.git
38 changes: 38 additions & 0 deletions app/Console/Commands/SendEcfmpDiscordMessages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use App\Discord\FlowMeasure\Generator\EcfmpFlowMeasureMessageGenerator;

class SendEcfmpDiscordMessages extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'discord:send-ecfmp-messages';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Send ECFMP Discord messages';

public function handle(EcfmpFlowMeasureMessageGenerator $generator): int
{
if (!config('discord.enabled')) {
Log::info('Skipping discord notifications, disabled in config');
return 0;
}

Log::info('Sending discord notifications');
$generator->generateAndSend();
Log::info('Discord notification sending complete');

return 0;
}
}
32 changes: 32 additions & 0 deletions app/Discord/Client/ClientFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Discord\Client;

use Ecfmp_discord\DiscordClient;
use Grpc\ChannelCredentials;

/**
* This class exists because gRPC has trouble when the client is registered directly to the
* service container (the channel is closed before the request is sent). This class is a
* workaround for that issue.
* @codeCoverageIgnore
*/
class ClientFactory implements ClientFactoryInterface
{
private DiscordClient|null $client = null;

public function create(): DiscordClient
{
if ($this->client === null) {
$this->client = new DiscordClient(
config('discord.service_host'),
[
'credentials' => ChannelCredentials::createInsecure(),
'grpc.primary_user_agent' => config('app.name'),
],
);
}

return $this->client;
}
}
10 changes: 10 additions & 0 deletions app/Discord/Client/ClientFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Discord\Client;

use Ecfmp_discord\DiscordClient;

interface ClientFactoryInterface
{
public function create(): DiscordClient;
}
16 changes: 16 additions & 0 deletions app/Discord/DiscordServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Discord;

use App\Discord\Exception\DiscordServiceException;
use App\Discord\Message\EcfmpMessageInterface;

interface DiscordServiceInterface
{
/**
* Returns the remote message id, or throws an exception if the message could not be sent.
*
* @throws DiscordServiceException
*/
public function sendMessage(string $clientRequestId, EcfmpMessageInterface $message): string;
}
61 changes: 61 additions & 0 deletions app/Discord/DiscordServiceMessageSender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Discord;

use App\Discord\Client\ClientFactoryInterface;
use App\Discord\Exception\DiscordServiceException;
use App\Discord\Message\EcfmpMessageInterface;
use Ecfmp_discord\CreateRequest;
use Log;

use const Grpc\STATUS_OK;

class DiscordServiceMessageSender implements DiscordServiceInterface
{
private readonly ClientFactoryInterface $discordClientFactory;

public function __construct(ClientFactoryInterface $discordClientFactory)
{
$this->discordClientFactory = $discordClientFactory;
}

public function sendMessage(string $clientRequestId, EcfmpMessageInterface $message): string
{
$client = $this->discordClientFactory->create();

// Wait for 1 second for the channel to be ready
$channelReady = $client->waitForReady(1000000);
if (!$channelReady) {
Log::error('Discord grpc channel not ready');
throw new DiscordServiceException('Discord grpc channel not ready');
}

/**
* @var $response \Ecfmp_discord\CreateResponse
*/
[$response, $status] = $client->Create(
new CreateRequest(
[
'channel' => $message->channel(),
'content' => $message->content(),
'embeds' => $message->embeds()->toProtobuf(),
]
),
[
'authorization' => [config('discord.service_token')],
'x-client-request-id' => [$clientRequestId],
],
)->wait();

if ($status->code !== STATUS_OK) {
Log::error('Discord grpc call failed', [
'code' => $status->code,
'details' => $status->details,
]);

throw new DiscordServiceException('Discord grpc call failed');
}

return $response->getId();
}
}
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@
/**
* To hide the details of how we go about doing Discord things...
*
* This class is the interface for interacting with Discord.
* This class is the interface for interacting with Discord via webhooks.
*/
interface DiscordInterface
interface DiscordWebhookInterface
{
public function sendMessage(MessageInterface $message): bool;
}
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
use Illuminate\Support\Facades\Http;
use Log;

class DiscordMessageSender implements DiscordInterface
class DiscordWebhookSender implements DiscordWebhookInterface
{
public function sendMessage(MessageInterface $message): bool
{
9 changes: 9 additions & 0 deletions app/Discord/Exception/DiscordServiceException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Discord\Exception;

use RuntimeException;

class DiscordServiceException extends RuntimeException
{
}
6 changes: 3 additions & 3 deletions app/Discord/FlowMeasure/Associator/FlowMeasureAssociator.php
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

use App\Discord\Message\Associator\AssociatorInterface;
use App\Enums\DiscordNotificationType as DiscordNotificationTypeEnum;
use App\Models\DiscordNotification;
use App\Models\DivisionDiscordNotification;
use App\Models\DiscordNotificationType;
use App\Models\FlowMeasure;

@@ -20,9 +20,9 @@ public function __construct(FlowMeasure $flowMeasure, DiscordNotificationTypeEnu
}


public function associate(DiscordNotification $notification): void
public function associate(DivisionDiscordNotification $notification): void
{
$this->flowMeasure->discordNotifications()->attach(
$this->flowMeasure->divisionDiscordNotifications()->attach(
[
$notification->id => [
'discord_notification_type_id' => DiscordNotificationType::idFromEnum($this->type),
31 changes: 25 additions & 6 deletions app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php
Original file line number Diff line number Diff line change
@@ -3,32 +3,51 @@
namespace App\Discord\FlowMeasure\Content;

use App\Discord\FlowMeasure\Provider\PendingMessageInterface;
use App\Discord\FlowMeasure\Provider\PendingWebhookMessageInterface;
use App\Discord\Message\Tag\Tag;
use App\Enums\DiscordNotificationType;
use App\Models\DiscordNotification;
use App\Models\DivisionDiscordNotification;
use App\Models\DiscordTag;
use App\Models\DivisionDiscordWebhook;
use App\Models\FlightInformationRegion;
use Carbon\Carbon;

class FlowMeasureRecipientsFactory
{
public function makeRecipients(PendingMessageInterface $pendingMessage): FlowMeasureRecipientsInterface
public function makeRecipients(PendingWebhookMessageInterface $pendingMessage): FlowMeasureRecipientsInterface
{
if ($this->hasRecentlyBeenNotifiedToWebhook($pendingMessage)) {
return new NoRecipients();
}

return $this->divisionRecipients($pendingMessage);
}

public function makeEcfmpRecipients(PendingMessageInterface $pendingMessage): FlowMeasureRecipientsInterface
{
if ($this->hasRecentlyBeenNotified($pendingMessage)) {
return new NoRecipients();
}

return $pendingMessage->webhook()->id() === null
? $this->ecfmpRecipients($pendingMessage)
: $this->divisionRecipients($pendingMessage);
return $this->ecfmpRecipients($pendingMessage);
}

private function hasRecentlyBeenNotifiedToWebhook(PendingWebhookMessageInterface $pendingMessage): bool
{
$measure = $pendingMessage->flowMeasure();
return $pendingMessage->type(
) === DiscordNotificationType::FLOW_MEASURE_ACTIVATED && $measure->notifiedDivisionNotifications->firstWhere(
fn (DivisionDiscordNotification $notification) => $notification->created_at > Carbon::now()->subHour() &&
$notification->pivot->notified_as === $measure->identifier
) !== null;
}

private function hasRecentlyBeenNotified(PendingMessageInterface $pendingMessage): bool
{
$measure = $pendingMessage->flowMeasure();
return $pendingMessage->type(
) === DiscordNotificationType::FLOW_MEASURE_ACTIVATED && $measure->notifiedDiscordNotifications->firstWhere(
) === DiscordNotificationType::FLOW_MEASURE_ACTIVATED && $measure->notifiedEcfmpNotifications->firstWhere(
fn (DiscordNotification $notification) => $notification->created_at > Carbon::now()->subHour() &&
$notification->pivot->notified_as === $measure->identifier
) !== null;
@@ -44,7 +63,7 @@ private function ecfmpRecipients(PendingMessageInterface $pendingMessage): FlowM
);
}

private function divisionRecipients(PendingMessageInterface $pendingMessage): FlowMeasureRecipientsInterface
private function divisionRecipients(PendingWebhookMessageInterface $pendingMessage): FlowMeasureRecipientsInterface
{
$recipients = DivisionDiscordWebhook::find($pendingMessage->webhook()->id())
->flightInformationRegions
2 changes: 1 addition & 1 deletion app/Discord/FlowMeasure/Embed/ActivatedEmbeds.php
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public function embeds(): EmbedCollection
: IdentifierAndActiveStatus::create($this->pendingMessage->flowMeasure())
)
->withDescription(new EventName($this->pendingMessage->flowMeasure()))
->withField(Field::make(new IssuingUser($this->pendingMessage->flowMeasure())), is_null($this->pendingMessage->webhook()->id()))
->withField(Field::make(new IssuingUser($this->pendingMessage->flowMeasure())), $this->pendingMessage->isEcfmp())
->withField(Field::makeInline(new Restriction($this->pendingMessage->flowMeasure())))
->withField(Field::makeInline(new StartTime($this->pendingMessage->flowMeasure())))
->withField(Field::makeInline(new EndTime($this->pendingMessage->flowMeasure())))
2 changes: 1 addition & 1 deletion app/Discord/FlowMeasure/Embed/NotifiedEmbeds.php
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public function embeds(): EmbedCollection
: IdentifierAndNotifiedStatus::create($this->pendingMessage->flowMeasure())
)
->withDescription(new EventName($this->pendingMessage->flowMeasure()))
->withField(Field::make(new IssuingUser($this->pendingMessage->flowMeasure())), is_null($this->pendingMessage->webhook()->id()))
->withField(Field::make(new IssuingUser($this->pendingMessage->flowMeasure())), $this->pendingMessage->isEcfmp())
->withField(Field::makeInline(new Restriction($this->pendingMessage->flowMeasure())))
->withField(Field::makeInline(new StartTime($this->pendingMessage->flowMeasure())))
->withField(Field::makeInline(new EndTime($this->pendingMessage->flowMeasure())))
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Discord\FlowMeasure\Generator;

use App\Discord\FlowMeasure\Helper\EcfmpNotificationReissuer;
use App\Discord\FlowMeasure\Provider\PendingEcfmpMessage;
use App\Discord\FlowMeasure\Sender\EcfmpFlowMeasureSender;
use App\Repository\FlowMeasureNotification\RepositoryInterface;

class EcfmpFlowMeasureMessageGenerator
{
private readonly EcfmpFlowMeasureSender $sender;

/** @var RepositoryInterface[] */
private readonly array $repositories;

public function __construct(EcfmpFlowMeasureSender $sender, array $repositories)
{
$this->sender = $sender;
$this->repositories = $repositories;
}

public function generateAndSend(): void
{
foreach ($this->repositories as $repository) {
foreach ($repository->flowMeasuresToBeSentToEcfmp() as $measure) {
$pendingMessage = new PendingEcfmpMessage(
$measure->measure,
$repository->notificationType(),
new EcfmpNotificationReissuer($measure, $repository->notificationType())
);

$this->sender->send($pendingMessage);
}
}
}
}
Loading