Skip to content

Commit

Permalink
PRESIDECMS-2698 Add option to raise a notification for 1 consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
choontat-pixl8 committed Nov 5, 2024
1 parent 2273e35 commit 66ee852
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions system/services/notifications/NotificationService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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;
}

Expand All @@ -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(
Expand Down Expand Up @@ -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; }
Expand Down

0 comments on commit 66ee852

Please sign in to comment.