@@ -64,9 +64,7 @@ final class CommandBarInternalSDK : CommandBarInternalSDKDelegate {
64
64
guard let config = CommandBarInternalSDK . shared. config else { return }
65
65
66
66
// TODO: Can probably hook up some sort of background queue to enqueue to from here
67
- if let nudge = config. nudges_v2. filter ( { nudge in
68
- return nudge. is_live && !nudge. archived && nudge. trigger == . whenConditionsPass
69
- } ) . first {
67
+ if let nudge = filterNudges ( ) . first {
70
68
NudgeWindowManager . shared. renderNudge ( nudge)
71
69
}
72
70
}
@@ -75,14 +73,55 @@ final class CommandBarInternalSDK : CommandBarInternalSDKDelegate {
75
73
func triggerNudges( withEvent event: String ) {
76
74
guard let config = CommandBarInternalSDK . shared. config else { return }
77
75
78
- if let nudge = config. nudges_v2. filter ( { nudge in
79
- return nudge. trigger == . onEvent( PushTrigger . OnEventMeta ( event: event) ) && nudge. is_live && !nudge. archived
80
- } ) . first {
76
+ if let nudge = filterNudges ( ) . first {
81
77
NudgeWindowManager . shared. renderNudge ( nudge)
82
78
}
83
79
}
84
80
85
81
82
+ func filterNudges( ) -> [ Nudge ] {
83
+ guard let config = CommandBarInternalSDK . shared. config else { return [ ] }
84
+
85
+ return config. nudges_v2. filter ( { nudge in
86
+ if ( !nudge. is_live || nudge. archived) {
87
+ return false
88
+ }
89
+
90
+ let hasUnsupportedStep = nudge. steps. contains ( where: { step in
91
+ if ( step. form_factor. type == . pin) {
92
+ return true
93
+ }
94
+ let hasUnsupportedContent = step. content. contains ( where: { content in
95
+ if ( content. type == . button) {
96
+ if let actionMeta = content. meta as? NudgeContentButtonBlockMeta {
97
+ if ( actionMeta. action. isSameType ( as: " execute_command " ) ) {
98
+ return true
99
+ } else if ( actionMeta. action. isSameType ( as: " click " ) ) {
100
+ return true
101
+ } else if ( actionMeta. action. isSameType ( as: " open_bar " ) ) {
102
+ return true
103
+ } else if ( actionMeta. action. isSameType ( as: " questlist " ) ) {
104
+ return true
105
+ } else if ( actionMeta. action. isSameType ( as: " snooze " ) ) {
106
+ return true
107
+ } else if ( actionMeta. action. isSameType ( as: " open_chat " ) ) {
108
+ return true
109
+ } else {
110
+ return false
111
+ }
112
+ }
113
+ } else if ( content. type == . contentList || content. type == . helpDoc) {
114
+ return true
115
+ }
116
+
117
+ return true
118
+ } )
119
+ return hasUnsupportedContent;
120
+ } )
121
+ return hasUnsupportedStep
122
+ } )
123
+ }
124
+
86
125
public func trackEvent( event: String ) {
87
126
CommandBarInternalSDK . shared. triggerNudges ( withEvent: event)
88
127
}
0 commit comments