2
2
3
3
namespace HMS \Entities ;
4
4
5
+ use App \Notifications \NotificationSensitivityInterface ;
6
+ use App \Notifications \NotificationSensitivityType ;
5
7
use Doctrine \Common \Collections \ArrayCollection ;
6
8
use HMS \Helpers \Discord ;
7
9
use HMS \Traits \Entities \SoftDeletable ;
@@ -447,9 +449,11 @@ public function routeNotificationForSlack(): false|string
447
449
/**
448
450
* Route notifications to the Discord channel.
449
451
*
452
+ * @param mixed $notification
453
+ *
450
454
* @return null|string
451
455
*/
452
- public function routeNotificationForDiscord (): ?string
456
+ public function routeNotificationForDiscord ($ notification ): ?string
453
457
{
454
458
if (! config ('services.discord.token ' )) {
455
459
return null ;
@@ -468,15 +472,25 @@ public function routeNotificationForDiscord(): ?string
468
472
469
473
$ discord = app (Discord::class);
470
474
471
- if ($ this ->getDiscordPrivateChannel ()) {
472
- return $ discord ->findChannelByName ($ this ->getDiscordPrivateChannel ())['id ' ];
473
- }
475
+ $ privateChannel = $ discord ->findChannelByName ($ this ->getDiscordPrivateChannel ())['id ' ];
476
+ $ publicChannel = $ discord ->findChannelByName ($ this ->getDiscordChannel ())['id ' ];
477
+
478
+ // If they are null it'll cancel the notification, so it's ok
479
+ // to just return the whatever is returned from the ORM.
480
+ if ($ notification instanceof NotificationSensitivityInterface) {
481
+ switch ($ notification ->getDiscordSensitivity ()) {
482
+ case NotificationSensitivityType::PRIVATE :
483
+ return $ privateChannel ;
484
+
485
+ case NotificationSensitivityType::PUBLIC :
486
+ return $ publicChannel ;
474
487
475
- if ($ this ->getDiscordChannel ()) {
476
- return $ discord ->findChannelByName ($ this ->getDiscordChannel ())['id ' ];
488
+ case NotificationSensitivityType::ANY :
489
+ break ;
490
+ }
477
491
}
478
492
479
- return null ;
493
+ return $ privateChannel ? $ privateChannel : $ publicChannel ;
480
494
}
481
495
482
496
/**
0 commit comments