From fe36184dc8b2698e9edaebd41b3a9f0f2611ca0d Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Fri, 20 Oct 2023 14:39:05 +0700 Subject: [PATCH] fix: update gitlab event for bot setting --- src/Bot.php | 4 ++-- src/Trait/EventSettingTrait.php | 35 ++++++++++++++++++++++----------- src/Trait/EventTrait.php | 8 +++----- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Bot.php b/src/Bot.php index 2a2eb1c..7fa2a04 100644 --- a/src/Bot.php +++ b/src/Bot.php @@ -32,11 +32,11 @@ class Bot implements AppInterface, BotInterface, EventInterface, SettingInterfac public function __construct( Telegram $telegram = null, ?string $chatBotId = null, - Setting $setting = null, Event $event = null, - ?string $settingFile = null, ?string $platform = EventConstant::DEFAULT_PLATFORM, ?string $platformFile = null, + Setting $setting = null, + ?string $settingFile = null, ) { $this->telegram = $telegram ?? new Telegram(config('telegram-git-notifier.bot.token')); $this->setCurrentChatBotId($chatBotId); diff --git a/src/Trait/EventSettingTrait.php b/src/Trait/EventSettingTrait.php index 4f03c8f..36801c5 100644 --- a/src/Trait/EventSettingTrait.php +++ b/src/Trait/EventSettingTrait.php @@ -9,11 +9,13 @@ trait EventSettingTrait { public function eventMarkup( ?string $parentEvent = null, - string $platform = EventConstant::DEFAULT_PLATFORM + string $platform = EventConstant::DEFAULT_PLATFORM, + string $platformFile = null ): array { $replyMarkup = $replyMarkupItem = []; - $this->event->setEventConfig($platform); + $this->setPlatFormForEvent($platform, $platformFile); + $events = $parentEvent === null ? $this->event->getEventConfig() : $this->event->getEventConfig()[$parentEvent]; @@ -96,7 +98,8 @@ public function getEndKeyboard( public function eventHandle( ?string $callback = null, - ?string $platform = null + ?string $platform = null, + ?string $platFormFile = null ): void { $platform = $this->getPlatformFromCallback($callback, $platform); @@ -110,7 +113,7 @@ public function eventHandle( return; } - $this->handleEventUpdate($event, $platform); + $this->handleEventUpdate($event, $platform, $platFormFile); } public function getPlatformFromCallback( @@ -185,23 +188,33 @@ public function handleEventWithActions( return false; } - public function handleEventUpdate(string $event, string $platform): void - { + public function handleEventUpdate( + string $event, + string $platform, + string $platFormFile = null + ): void { if (str_contains($event, EventConstant::EVENT_UPDATE_SEPARATOR)) { $event = str_replace( EventConstant::EVENT_UPDATE_SEPARATOR, '', $event ); - $this->eventUpdateHandle($event, $platform); + $this->eventUpdateHandle($event, $platform, $platFormFile); } } - public function eventUpdateHandle(string $event, string $platform): void - { - [$event, $action] = explode('.', $event); + public function eventUpdateHandle( + string $event, + string $platform, + string $platFormFile = null + ): void { + if (str_contains($event, '.')) { + [$event, $action] = explode('.', $event); + } else { + $action = null; + } - $this->event->setEventConfig($platform); + $this->setPlatFormForEvent($platform); $this->event->updateEvent($event, $action); $this->eventHandle( $action diff --git a/src/Trait/EventTrait.php b/src/Trait/EventTrait.php index b29c157..98ec7d9 100644 --- a/src/Trait/EventTrait.php +++ b/src/Trait/EventTrait.php @@ -11,11 +11,9 @@ trait EventTrait public function setPlatFormForEvent(string $platform, string $platformFile = null): void { - if (!$this->event->getPlatformFile()) { - /** @var array $platformFileDefaults */ - $platformFileDefaults = config('telegram-git-notifier.data_file.platform'); - $this->event->setPlatformFile($platformFile ?? $platformFileDefaults[$platform]); - } + /** @var array $platformFileDefaults */ + $platformFileDefaults = config('telegram-git-notifier.data_file.platform'); + $this->event->setPlatformFile($platformFile ?? $platformFileDefaults[$platform]); $this->event->setEventConfig($platform); }