Version 4.7.0

This commit is contained in:
Neo committed 2025-12-19 16:00:35 -08:00
1 parent 517a5e1f70
commit 8ba7d43898
1933 files changed
+65613 -11332

No files matched your search

+27 -46
View File
@@ -81,7 +81,7 @@ class _Notification
*/
public static function canUseWebPush(): bool
{
if ( \IPS\IN_DEV or \IPS\CIC2 )
if ( \IPS\IN_DEV )
{
return TRUE;
}
@@ -111,6 +111,7 @@ class _Notification
{
/* Get data from the actual extensions */
$extensionDefaults = array();
$notificationGroups = [];
foreach( \IPS\Application::allExtensions( 'core', 'Notifications' ) as $group => $class )
{
if ( method_exists( $class, 'configurationOptions' ) )
@@ -126,6 +127,7 @@ class _Notification
foreach ( $details['notificationTypes'] as $type )
{
$notificationGroups[ $type ] = $key;
$extensionDefaults[ $type ] = array(
'default' => $details['default'],
'disabled' => $details['disabled']
@@ -153,12 +155,26 @@ class _Notification
{
if ( !isset( static::$defaultConfiguration[ $key ] ) )
{
/* Row isn't in DB, add it */
\IPS\Db::i()->insert( 'core_notification_defaults', array(
'notification_key' => $key,
'default' => implode( ',', $data['default'] ),
'disabled' => implode( ',', $data['disabled'] )
) );
/* If parent group already has defaults stored, use those */
if( isset( $notificationGroups[ $key ] ) AND isset( static::$defaultConfiguration[ $notificationGroups[ $key ] ] ) )
{
\IPS\Db::i()->insert( 'core_notification_defaults', array(
'notification_key' => $key,
'default' => implode( ',', static::$defaultConfiguration[ $notificationGroups[ $key ] ]['default'] ),
'disabled' => implode( ',', static::$defaultConfiguration[ $notificationGroups[ $key ] ]['disabled'] )
) );
$data['default'] = static::$defaultConfiguration[ $notificationGroups[ $key ] ]['default'];
$data['disabled'] = static::$defaultConfiguration[ $notificationGroups[ $key ] ]['disabled'];
}
else
{
/* Row isn't in DB, add it */
\IPS\Db::i()->insert( 'core_notification_defaults', array(
'notification_key' => $key,
'default' => implode( ',', $data['default'] ),
'disabled' => implode( ',', $data['disabled'] )
) );
}
static::$defaultConfiguration[ $key ] = array_merge( $data, array( 'editable' => TRUE ) );
}
@@ -216,7 +232,7 @@ class _Notification
{
$options = array();
$availableTypes = array('inline');
if ( ( \IPS\Settings::i()->mobile_app_id and $member->members_bitoptions['mobile_notifications'] ) || ( static::webPushEnabled() && \count( $member->getPwaAuths() ) ) )
if ( static::webPushEnabled() && \count( $member->getPwaAuths() ) )
{
$availableTypes[] = 'push';
}
@@ -834,7 +850,7 @@ class _Notification
}
/* They want to receive a push notification (we don't send until the end once we've collated all the notifications to send) */
if ( ( ( \IPS\Settings::i()->mobile_app_id and $member->members_bitoptions['mobile_notifications'] ) || ( static::webPushEnabled() && \count( $member->getPwaAuths() ) ) ) and isset( $notificationPreferences[ $keyToCheck ] ) AND \in_array( 'push', $notificationPreferences[ $keyToCheck ] ) and ( !isset( $sentTo[ $member->member_id ] ) or !\in_array( 'push', $sentTo[ $member->member_id ] ) ) and $licenseKey = \IPS\IPS::licenseKey() and $licenseKey['active'] )
if ( ( static::webPushEnabled() && \count( $member->getPwaAuths() ) ) and isset( $notificationPreferences[ $keyToCheck ] ) AND \in_array( 'push', $notificationPreferences[ $keyToCheck ] ) and ( !isset( $sentTo[ $member->member_id ] ) or !\in_array( 'push', $sentTo[ $member->member_id ] ) ) )
{
$language = $member->language();
if ( !isset( $pushNotifications[ $language->id ] ) )
@@ -948,8 +964,8 @@ class _Notification
'icon' => $data['icon'] ?? NULL,
'image' => $data['image'] ?? NULL,
'tag' => $data['tag'] ?? NULL,
'grouped' => static::textForPushNotification( $data['data']['grouped'] ) ?? NULL,
'groupedTitle' => static::textForPushNotification( $data['data']['groupedTitle'] ) ?? NULL,
'grouped' => !empty( $data['data']['grouped'] ) ? static::textForPushNotification( $data['data']['grouped'] ) : NULL,
'groupedTitle' => !empty( $data['data']['groupedTitle'] ) ? static::textForPushNotification( $data['data']['groupedTitle'] ) : NULL,
'groupedUrl' => isset( $data['data']['groupedUrl'] ) ? (string) $data['data']['groupedUrl'] : NULL
) );
@@ -979,41 +995,6 @@ class _Notification
\IPS\Task::queue( 'core', 'PWANotifications', $pwaPushNotifications, 2 );
}
}
/* Send mobile app notifications (send in batches of 100 to prevent a single massive request) */
$limit = 100;
$offset = 0;
while ( $slice = \array_slice( $pushNotifications, $offset, $limit ) )
{
try
{
/* Send to remoteservices */
$response = \IPS\Http\Url::ips('mobile/notify')->request()->login( \IPS\Settings::i()->mobile_app_id, \IPS\Settings::i()->mobile_app_secret )->post( array( 'data' => $slice ) );
if ( $response->httpResponseCode != 200 )
{
throw new \DomainException( $response );
}
$response = $response->decodeJson();
/* If any users have turned off notifications on all of their devices, we can remove them */
if ( isset( $response['unsubscribe'] ) and $response['unsubscribe'] )
{
\IPS\Db::i()->update( 'core_members', "members_bitoptions2 = members_bitoptions2 & ~" . \IPS\Member::$bitOptions['members_bitoptions']['members_bitoptions2']['mobile_notifications'], \IPS\Db::i()->in( 'member_id', $response['unsubscribe'] ) );
}
/* Log any errors */
if ( isset( $response['errors'] ) and $response['errors'] )
{
\IPS\Log::log( json_encode( $slice, JSON_PRETTY_PRINT ) . "\n\n==============================================================================\n\n" . json_encode( $response, JSON_PRETTY_PRINT ), 'mobile-push-notifications' );
}
}
catch ( \Exception $e )
{
\IPS\Log::log( $e, 'mobile-push-notifications' );
}
$offset += $limit;
}
}
/**