@@ -12,6 +12,7 @@ import {
1212 AndroidCallStyle ,
1313 AndroidStyle ,
1414 AndroidCallType ,
15+ AndroidAction ,
1516} from '../types/NotificationAndroid' ;
1617import { objectHasProperty , isArray , isBoolean , isNumber , isObject , isString } from '../utils' ;
1718import validateAndroidPressAction from './validateAndroidPressAction' ;
@@ -322,7 +323,7 @@ export function validateAndroidMessagingStyle(style: AndroidMessagingStyle): And
322323 */
323324export function validateAndroidCallStyle ( style : AndroidCallStyle ) : AndroidCallStyle {
324325 if ( ! isObject ( style . person ) ) {
325- throw new Error ( "'notification.android.style' CallStyle: 'person' an object value." ) ;
326+ throw new Error ( "'notification.android.style' CallStyle: 'person' expected an object value." ) ;
326327 }
327328
328329 let person ;
@@ -334,7 +335,7 @@ export function validateAndroidCallStyle(style: AndroidCallStyle): AndroidCallSt
334335 }
335336
336337 if ( ! isObject ( style . callTypeActions ) ) {
337- throw new Error ( "'notification.android.style' CallStyle: 'callTypeActions' an object value." ) ;
338+ throw new Error ( "'notification.android.style' CallStyle: 'callTypeActions' expected an object value." ) ;
338339 }
339340
340341 if ( ! isNumber ( style . callTypeActions . callType ) ) {
@@ -349,37 +350,32 @@ export function validateAndroidCallStyle(style: AndroidCallStyle): AndroidCallSt
349350
350351 switch ( out . callTypeActions . callType ) {
351352 case AndroidCallType . INCOMING :
352- if ( ! isString ( out . callTypeActions . answerAction . title ) ) {
353- throw new Error ( "'notification.android.style' CallStyle: 'callTypeActions.answerAction.title' an string value." ) ;
354- }
355- if ( ! isString ( out . callTypeActions . declineAction . title ) ) {
356- throw new Error ( "'notification.android.style' CallStyle: 'callTypeActions.declineAction.title' an string value." ) ;
357- }
358-
359- out . callTypeActions . answerAction . pressAction = validateAndroidPressAction ( out . callTypeActions . answerAction . pressAction )
360- out . callTypeActions . declineAction . pressAction = validateAndroidPressAction ( out . callTypeActions . declineAction . pressAction )
353+ out . callTypeActions . answerAction = validateAndroidAction ( out . callTypeActions . answerAction )
354+ out . callTypeActions . declineAction = validateAndroidAction ( out . callTypeActions . declineAction )
361355 break ;
362356 case AndroidCallType . ONGOING :
363- if ( ! isString ( out . callTypeActions . hangUpAction . title ) ) {
364- throw new Error ( "'notification.android.style' CallStyle: 'callTypeActions.hangUpAction.title' an string value." ) ;
365- }
366357
367- out . callTypeActions . hangUpAction . pressAction = validateAndroidPressAction ( out . callTypeActions . hangUpAction . pressAction )
358+ out . callTypeActions . hangUpAction = validateAndroidAction ( out . callTypeActions . hangUpAction )
368359 break ;
369360 case AndroidCallType . SCREENING :
370- if ( ! isString ( out . callTypeActions . answerAction . title ) ) {
371- throw new Error ( "'notification.android.style' CallStyle: 'callTypeActions.answerAction.title' an string value." ) ;
372- }
373- if ( ! isString ( out . callTypeActions . hangUpAction . title ) ) {
374- throw new Error ( "'notification.android.style' CallStyle: 'callTypeActions.hangUpAction.title' an string value." ) ;
375- }
376-
377- out . callTypeActions . answerAction . pressAction = validateAndroidPressAction ( out . callTypeActions . answerAction . pressAction )
378- out . callTypeActions . hangUpAction . pressAction = validateAndroidPressAction ( out . callTypeActions . hangUpAction . pressAction )
361+ out . callTypeActions . answerAction = validateAndroidAction ( out . callTypeActions . answerAction )
362+ out . callTypeActions . hangUpAction = validateAndroidAction ( out . callTypeActions . hangUpAction )
379363 break ;
380364 default :
381365 throw new Error ( "'callType' expected a value of 0, 1 or 2." ) ;
382366 }
383367
384368 return out ;
385369}
370+
371+ function validateAndroidAction (
372+ action : AndroidAction ,
373+ ) : AndroidAction {
374+ if ( ! isString ( action . title ) ) {
375+ throw new Error ( "'title' expected a string value." ) ;
376+ }
377+
378+ action . pressAction = validateAndroidPressAction ( action . pressAction )
379+
380+ return action ;
381+ } ;
0 commit comments