@@ -1690,6 +1690,7 @@ + (void)maybePerformActions:(NSArray *)whenConditions
16901690{
16911691 NSDictionary *messages = [LPVarCache messages ];
16921692 NSMutableArray *actionContexts = [NSMutableArray array ];
1693+
16931694 for (NSString *messageId in [messages allKeys ]) {
16941695 if (sourceMessage != nil && [messageId isEqualToString: sourceMessage]) {
16951696 continue ;
@@ -1750,10 +1751,7 @@ + (void)maybePerformActions:(NSArray *)whenConditions
17501751 if (result.matchedTrigger ) {
17511752 [[LPInternalState sharedState ].actionManager recordMessageTrigger: internalMessageId];
17521753 if (result.matchedLimit ) {
1753- NSNumber *priority = messageConfig[@" priority" ];
1754- if (!priority) {
1755- priority = [NSNumber numberWithInt: DEFAULT_PRIORITY];
1756- }
1754+ NSNumber *priority = messageConfig[@" priority" ] ?: @(DEFAULT_PRIORITY);
17571755 LPActionContext *context = [LPActionContext
17581756 actionContextWithName: actionType
17591757 args: [messageConfig objectForKey: LP_KEY_VARS]
@@ -1766,27 +1764,35 @@ + (void)maybePerformActions:(NSArray *)whenConditions
17661764 }
17671765 }
17681766
1769- if ([actionContexts count ] > 0 ) {
1770- [LPActionContext sortByPriority: actionContexts];
1771- NSNumber *priorityThreshold = [((LPActionContext *) [actionContexts firstObject ]) priority ];
1772- for (LPActionContext *actionContext in actionContexts) {
1773- NSNumber *priority = [actionContext priority ];
1774- if ([priority intValue ] <= [priorityThreshold intValue ]) {
1775- if ([[actionContext actionName ] isEqualToString: LP_HELD_BACK_ACTION]) {
1776- [[LPInternalState sharedState ].actionManager
1777- recordHeldBackImpression: [actionContext messageId ]
1778- originalMessageId: [actionContext originalMessageId ]];
1779- } else {
1780- [self triggerAction: actionContext handledBlock: ^(BOOL success) {
1781- if (success) {
1782- [[LPInternalState sharedState ].actionManager
1783- recordMessageImpression: [actionContext messageId ]];
1784- }
1785- }];
1786- }
1787- } else {
1788- break ;
1789- }
1767+ // Return if there are no action to trigger.
1768+ if ([actionContexts count ] == 0 ) {
1769+ return ;
1770+ }
1771+
1772+ // Sort the action by priority and only show one message.
1773+ // Make sure to capture the held back.
1774+ [LPActionContext sortByPriority: actionContexts];
1775+ NSNumber *priorityThreshold = [((LPActionContext *) [actionContexts firstObject ]) priority ];
1776+ BOOL messageActionTriggered = NO ;
1777+
1778+ for (LPActionContext *actionContext in actionContexts) {
1779+ NSNumber *priority = [actionContext priority ];
1780+ if (priority.intValue > priorityThreshold.intValue ) {
1781+ break ;
1782+ }
1783+
1784+ if ([[actionContext actionName ] isEqualToString: LP_HELD_BACK_ACTION]) {
1785+ [[LPInternalState sharedState ].actionManager
1786+ recordHeldBackImpression: [actionContext messageId ]
1787+ originalMessageId: [actionContext originalMessageId ]];
1788+ } else if (!messageActionTriggered) {
1789+ messageActionTriggered = YES ;
1790+ [self triggerAction: actionContext handledBlock: ^(BOOL success) {
1791+ if (success) {
1792+ [[LPInternalState sharedState ].actionManager
1793+ recordMessageImpression: [actionContext messageId ]];
1794+ }
1795+ }];
17901796 }
17911797 }
17921798}
0 commit comments