summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Echo/includes/AttributeManager.php')
-rw-r--r--Echo/includes/AttributeManager.php68
1 files changed, 43 insertions, 25 deletions
diff --git a/Echo/includes/AttributeManager.php b/Echo/includes/AttributeManager.php
index 72e609b3..9851c8b3 100644
--- a/Echo/includes/AttributeManager.php
+++ b/Echo/includes/AttributeManager.php
@@ -54,7 +54,7 @@ class EchoAttributeManager {
* An EchoAttributeManager instance created from global variables
* @var self
*/
- protected static $globalVarInstance = null;
+ protected static $globalVarInstance;
/**
* @param array[] $notifications Notification attributes
@@ -119,9 +119,9 @@ class EchoAttributeManager {
public function getUserCallable( $type, $locator = self::ATTR_LOCATORS ) {
if ( isset( $this->notifications[$type][$locator] ) ) {
return (array)$this->notifications[$type][$locator];
- } else {
- return [];
}
+
+ return [];
}
/**
@@ -132,20 +132,15 @@ class EchoAttributeManager {
* @return string[]
*/
public function getUserEnabledEvents( User $user, $notifyType ) {
- $eventTypesToLoad = $this->notifications;
- foreach ( $eventTypesToLoad as $eventType => $eventData ) {
- $category = $this->getNotificationCategory( $eventType );
- // Make sure the user is eligible to receive this type of notification
- if ( !$this->getCategoryEligibility( $user, $category ) ) {
- unset( $eventTypesToLoad[$eventType] );
- }
- if ( !$user->getOption( 'echo-subscriptions-' . $notifyType . '-' . $category ) ) {
- unset( $eventTypesToLoad[$eventType] );
+ return array_values( array_filter(
+ array_keys( $this->notifications ),
+ function ( $eventType ) use ( $user, $notifyType ) {
+ $category = $this->getNotificationCategory( $eventType );
+ return $this->isNotifyTypeAvailableForCategory( $category, $notifyType ) &&
+ $this->getCategoryEligibility( $user, $category ) &&
+ $user->getOption( "echo-subscriptions-$notifyType-$category" );
}
- }
- $eventTypes = array_keys( $eventTypesToLoad );
-
- return $eventTypes;
+ ) );
}
/**
@@ -308,6 +303,22 @@ class EchoAttributeManager {
}
/**
+ * Get notify type availability for all notify types for a given category.
+ *
+ * This means whether users *can* turn notifications for this category and format
+ * on, regardless of the default or a particular user's preferences.
+ *
+ * @param string $category Category name
+ * @return array [ 'web' => bool, 'email' => bool ]
+ */
+ public function getNotifyTypeAvailabilityForCategory( $category ) {
+ return array_merge(
+ $this->defaultNotifyTypeAvailability,
+ $this->notifyTypeAvailabilityByCategory[$category] ?? []
+ );
+ }
+
+ /**
* Checks whether the specified notify type is available for the specified
* category.
*
@@ -319,11 +330,7 @@ class EchoAttributeManager {
* @return bool
*/
public function isNotifyTypeAvailableForCategory( $category, $notifyType ) {
- if ( isset( $this->notifyTypeAvailabilityByCategory[$category][$notifyType] ) ) {
- return $this->notifyTypeAvailabilityByCategory[$category][$notifyType];
- } else {
- return $this->defaultNotifyTypeAvailability[$notifyType];
- }
+ return $this->getNotifyTypeAvailabilityForCategory( $category )[$notifyType];
}
/**
@@ -367,11 +374,22 @@ class EchoAttributeManager {
* @return string
*/
public function getNotificationSection( $notificationType ) {
- if ( isset( $this->notifications[$notificationType]['section'] ) ) {
- return $this->notifications[$notificationType]['section'];
- }
+ return $this->notifications[$notificationType]['section'] ?? 'alert';
+ }
- return 'alert';
+ /**
+ * Get notification types that allow their own agent to be notified.
+ *
+ * @return string[] Notification types
+ */
+ public function getNotifyAgentEvents() {
+ $events = [];
+ foreach ( $this->notifications as $event => $attribs ) {
+ if ( $attribs['canNotifyAgent'] ?? false ) {
+ $events[] = $event;
+ }
+ }
+ return $events;
}
}