@@ -238,9 +238,24 @@ module.exports = React.createClass({
238238 for ( var i in newKeywords ) {
239239 var keyword = newKeywords [ i ] ;
240240
241+ var pushRuleStateKind = self . state . vectorContentRules . state ;
242+ if ( pushRuleStateKind === PushRuleState . OFF ) {
243+ // When the current global keywords rule is OFF, we need to look at
244+ // the flavor of rules in 'vectorContentRules' to apply the same actions
245+ // when creating the new rule.
246+ // Thus, this new rule will join the 'vectorContentRules' set.
247+ if ( self . state . vectorContentRules . rules . length ) {
248+ pushRuleStateKind = self . _pushRuleStateKind ( self . state . vectorContentRules . rules [ 0 ] ) ;
249+ }
250+ else {
251+ // ON is default
252+ pushRuleStateKind = PushRuleState . ON ;
253+ }
254+ }
255+
241256 if ( vectorContentRulesPatterns . indexOf ( keyword ) < 0 ) {
242257 deferreds . push ( cli . addPushRule ( 'global' , 'content' , keyword , {
243- actions : self . _actionsFor ( self . state . vectorContentRules . state ) ,
258+ actions : self . _actionsFor ( pushRuleStateKind ) ,
244259 pattern : keyword
245260 } ) ) ;
246261 }
@@ -275,6 +290,31 @@ module.exports = React.createClass({
275290 ] ; ;
276291 }
277292 } ,
293+
294+ // Determine whether a rule is in the PushRuleState.ON category or in PushRuleState.LOUD
295+ // regardless of its enabled state.
296+ _pushRuleStateKind : function ( rule ) {
297+ var stateKind ;
298+
299+ // Count tweaks to determine if it is a ON or LOUD rule
300+ var tweaks = 0 ;
301+ for ( var j in rule . actions ) {
302+ var action = rule . actions [ j ] ;
303+ if ( action . set_tweak === 'sound' ||
304+ ( action . set_tweak === 'highlight' && action . value ) ) {
305+ tweaks ++ ;
306+ }
307+ }
308+ switch ( tweaks ) {
309+ case 0 :
310+ stateKind = PushRuleState . ON ;
311+ break ;
312+ case 2 :
313+ stateKind = PushRuleState . LOUD ;
314+ break ;
315+ }
316+ return stateKind ;
317+ } ,
278318
279319 _refreshFromServer : function ( ) {
280320 var self = this ;
@@ -317,26 +357,16 @@ module.exports = React.createClass({
317357 }
318358 }
319359 else if ( kind === 'content' ) {
320- // Count tweaks to determine if it is a ON or LOUD rule
321- var tweaks = 0 ;
322- for ( var j in r . actions ) {
323- var action = r . actions [ j ] ;
324- if ( action . set_tweak === 'sound' ||
325- ( action . set_tweak === 'highlight' && action . value ) ) {
326- tweaks ++ ;
327- }
328- }
329-
330- switch ( tweaks ) {
331- case 0 :
360+ switch ( self . _pushRuleStateKind ( r ) ) {
361+ case PushRuleState . ON :
332362 if ( r . enabled ) {
333363 contentRules . on . push ( r ) ;
334364 }
335365 else {
336366 contentRules . on_but_disabled . push ( r ) ;
337367 }
338368 break ;
339- case 2 :
369+ case PushRuleState . LOUD :
340370 if ( r . enabled ) {
341371 contentRules . loud . push ( r ) ;
342372 }
0 commit comments