Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
dprevost-LMI committed Oct 30, 2024
1 parent 25e4f5f commit 1bc815f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public Bundle toBundle() {
return (Bundle) mNotificationAndroidStyleBundle.clone();
}

@SuppressLint("NewApi")
@Nullable
public ListenableFuture<NotificationCompat.Style> getStyleTask(
ListeningExecutorService lExecutor, int notificationHashCode) {
Expand Down
69 changes: 34 additions & 35 deletions packages/react-native/src/types/NotificationAndroid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,36 @@ export interface AndroidMessagingStyle {
group?: boolean;
}

/**
* The interface for messages when constructing a Messaging Style notification.
*
* <Vimeo id="android-style-messaging" caption="Android Messaging Style" />
*
* View the [`AndroidMessagingStyle`](/react-native/reference/androidmessagingstyle) reference
* and [Messaging](/react-native/docs/android/styles#messaging) documentation to learn more.
*
* @platform android
*/
export interface AndroidMessagingStyleMessage {
/**
* The content of the message.
*/
text: string;

/**
* The timestamp of when the message arrived in milliseconds.
*/
timestamp: number;

/**
* The sender of this message. See [`AndroidPerson`](/react-native/reference/androidperson) reference
* for more information on the properties available.
*
* This property should only be provided if the message is from an external person, and not the person receiving the message.
*/
person?: AndroidPerson;
}

export const enum AndroidCallType {
INCOMING = 1,
ONGOING = 2,
Expand All @@ -746,13 +776,12 @@ export interface AndroidCallTypeScreening {
hangUpAction: AndroidAction;
}


/**
* The interface used when displaying a Phone Style notification.
* The interface used when displaying a Call Style notification.
*
* <Vimeo id="android-style-messaging" caption="Android Messaging Style" />
* <Vimeo id="android-style-call" caption="Android Call Style" />
*
* View the [Messaging](/react-native/docs/android/styles#messaging) documentation to learn more.
* View the [Call](/react-native/docs/android/styles#call) documentation to learn more.
*
* @platform android
*/
Expand All @@ -763,7 +792,7 @@ export interface AndroidCallStyle {
type: AndroidStyle.CALL;

/**
* The person who is receiving a message on the current device.
* The person who is on the phone call.
*/
person: AndroidPerson;

Expand All @@ -773,36 +802,6 @@ export interface AndroidCallStyle {
callTypeActions: AndroidCallTypeIncoming | AndroidCallTypeOngoing | AndroidCallTypeScreening;
}

/**
* The interface for messages when constructing a Messaging Style notification.
*
* <Vimeo id="android-style-messaging" caption="Android Messaging Style" />
*
* View the [`AndroidMessagingStyle`](/react-native/reference/androidmessagingstyle) reference
* and [Messaging](/react-native/docs/android/styles#messaging) documentation to learn more.
*
* @platform android
*/
export interface AndroidMessagingStyleMessage {
/**
* The content of the message.
*/
text: string;

/**
* The timestamp of when the message arrived in milliseconds.
*/
timestamp: number;

/**
* The sender of this message. See [`AndroidPerson`](/react-native/reference/androidperson) reference
* for more information on the properties available.
*
* This property should only be provided if the message is from an external person, and not the person receiving the message.
*/
person?: AndroidPerson;
}

/**
* The interface used to describe a person shown in notifications.
*
Expand Down
44 changes: 20 additions & 24 deletions packages/react-native/src/validators/validateAndroidStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
AndroidCallStyle,
AndroidStyle,
AndroidCallType,
AndroidAction,
} from '../types/NotificationAndroid';
import { objectHasProperty, isArray, isBoolean, isNumber, isObject, isString } from '../utils';
import validateAndroidPressAction from './validateAndroidPressAction';
Expand Down Expand Up @@ -322,7 +323,7 @@ export function validateAndroidMessagingStyle(style: AndroidMessagingStyle): And
*/
export function validateAndroidCallStyle(style: AndroidCallStyle): AndroidCallStyle {
if (!isObject(style.person)) {
throw new Error("'notification.android.style' CallStyle: 'person' an object value.");
throw new Error("'notification.android.style' CallStyle: 'person' expected an object value.");
}

let person;
Expand All @@ -334,7 +335,7 @@ export function validateAndroidCallStyle(style: AndroidCallStyle): AndroidCallSt
}

if (!isObject(style.callTypeActions)) {
throw new Error("'notification.android.style' CallStyle: 'callTypeActions' an object value.");
throw new Error("'notification.android.style' CallStyle: 'callTypeActions' expected an object value.");
}

if (!isNumber(style.callTypeActions.callType)) {
Expand All @@ -349,37 +350,32 @@ export function validateAndroidCallStyle(style: AndroidCallStyle): AndroidCallSt

switch (out.callTypeActions.callType) {
case AndroidCallType.INCOMING:
if (!isString(out.callTypeActions.answerAction.title)) {
throw new Error("'notification.android.style' CallStyle: 'callTypeActions.answerAction.title' an string value.");
}
if (!isString(out.callTypeActions.declineAction.title)) {
throw new Error("'notification.android.style' CallStyle: 'callTypeActions.declineAction.title' an string value.");
}

out.callTypeActions.answerAction.pressAction = validateAndroidPressAction(out.callTypeActions.answerAction.pressAction)
out.callTypeActions.declineAction.pressAction = validateAndroidPressAction(out.callTypeActions.declineAction.pressAction)
out.callTypeActions.answerAction = validateAndroidAction(out.callTypeActions.answerAction)
out.callTypeActions.declineAction = validateAndroidAction(out.callTypeActions.declineAction)
break;
case AndroidCallType.ONGOING:
if (!isString(out.callTypeActions.hangUpAction.title)) {
throw new Error("'notification.android.style' CallStyle: 'callTypeActions.hangUpAction.title' an string value.");
}

out.callTypeActions.hangUpAction.pressAction = validateAndroidPressAction(out.callTypeActions.hangUpAction.pressAction)
out.callTypeActions.hangUpAction = validateAndroidAction(out.callTypeActions.hangUpAction)
break;
case AndroidCallType.SCREENING:
if (!isString(out.callTypeActions.answerAction.title)) {
throw new Error("'notification.android.style' CallStyle: 'callTypeActions.answerAction.title' an string value.");
}
if (!isString(out.callTypeActions.hangUpAction.title)) {
throw new Error("'notification.android.style' CallStyle: 'callTypeActions.hangUpAction.title' an string value.");
}

out.callTypeActions.answerAction.pressAction = validateAndroidPressAction(out.callTypeActions.answerAction.pressAction)
out.callTypeActions.hangUpAction.pressAction = validateAndroidPressAction(out.callTypeActions.hangUpAction.pressAction)
out.callTypeActions.answerAction = validateAndroidAction(out.callTypeActions.answerAction)
out.callTypeActions.hangUpAction = validateAndroidAction(out.callTypeActions.hangUpAction)
break;
default:
throw new Error("'callType' expected a value of 0, 1 or 2.");
}

return out;
}

function validateAndroidAction(
action: AndroidAction,
): AndroidAction {
if (!isString(action.title)) {
throw new Error("'title' expected a string value.");
}

action.pressAction = validateAndroidPressAction(action.pressAction)

return action;
};

0 comments on commit 1bc815f

Please sign in to comment.