From 66ee8527a515408ecb3aa3d7f0e9840881c368d2 Mon Sep 17 00:00:00 2001 From: Choon Tat Date: Tue, 5 Nov 2024 15:28:11 +0800 Subject: [PATCH] PRESIDECMS-2698 Add option to raise a notification for 1 consumer --- .../notifications/NotificationService.cfc | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/system/services/notifications/NotificationService.cfc b/system/services/notifications/NotificationService.cfc index 0bdc0510ab..2ed4965f8d 100644 --- a/system/services/notifications/NotificationService.cfc +++ b/system/services/notifications/NotificationService.cfc @@ -60,7 +60,12 @@ component autodoc=true displayName="Notification Service" { * @data.hint Supporting data for the notification. This is used, in combination with the topic, to render the alert for the end users. * */ - public string function createNotification( required string topic, required string type, required struct data ) autodoc=true { + public string function createNotification( + required string topic + , required string type + , required struct data + , string consumer = "" + ) autodoc=true { var topicConfig = getGlobalTopicConfiguration( arguments.topic ); var args = Duplicate( arguments ); @@ -81,7 +86,7 @@ component autodoc=true displayName="Notification Service" { } ); if ( existingNotification.recordCount ) { - createNotificationConsumers( existingNotification.id, args.topic, args.data ); + createNotificationConsumers( existingNotification.id, args.topic, args.data, args.consumer ); return existingNotification.id; } @@ -91,7 +96,7 @@ component autodoc=true displayName="Notification Service" { _announceInterception( "postCreateNotification", args ); - createNotificationConsumers( args.notificationId, topic, args.data ); + createNotificationConsumers( args.notificationId, topic, args.data, args.consumer ); if ( Len( Trim( topicConfig.send_to_email_address ?: "" ) ) ) { sendGlobalNotificationEmail( @@ -467,11 +472,24 @@ component autodoc=true displayName="Notification Service" { } } - public void function createNotificationConsumers( required string notificationId, required string topic, required struct data ) { - var subscribedToAll = _getUserDao().selectData( selectFields=[ "id" ], filter={ subscribed_to_all_notifications=true, active=true } ); - var subscribedToTopic = _getSubscriptionDao().selectData( selectFields=[ "security_user", "get_email_notifications" ], filter={ topic=arguments.topic , "security_user.active"=true } ); - var subscribers = {}; - var interceptorArgs = Duplicate( arguments ); + public void function createNotificationConsumers( + required string notificationId + , required string topic + , required struct data + , string consumer = "" + ) { + var subscribedToAllFilter = { subscribed_to_all_notifications=true, active=true }; + var subscribedToTopicFilter = { topic=arguments.topic, "security_user.active"=true }; + + if ( len( arguments.consumer ) ) { + subscribedToAllFilter.id = arguments.consumer; + subscribedToTopicFilter.security_user = arguments.consumer; + } + + var subscribedToAll = _getUserDao().selectData( selectFields=[ "id" ], filter=subscribedToAllFilter ); + var subscribedToTopic = _getSubscriptionDao().selectData( selectFields=[ "security_user", "get_email_notifications" ], filter=subscribedToTopicFilter ); + var subscribers = {}; + var interceptorArgs = Duplicate( arguments ); for( var subscriber in subscribedToAll ){ subscribers[ subscriber.id ] = {}; } for( var subscriber in subscribedToTopic ){ subscribers[ subscriber.security_user ] = subscriber; }