Skip to content

Commit 1bc815f

Browse files
committed
Code review
1 parent 25e4f5f commit 1bc815f

File tree

3 files changed

+54
-60
lines changed

3 files changed

+54
-60
lines changed

android/src/main/java/app/notifee/core/model/NotificationAndroidStyleModel.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public Bundle toBundle() {
119119
return (Bundle) mNotificationAndroidStyleBundle.clone();
120120
}
121121

122-
@SuppressLint("NewApi")
123122
@Nullable
124123
public ListenableFuture<NotificationCompat.Style> getStyleTask(
125124
ListeningExecutorService lExecutor, int notificationHashCode) {

packages/react-native/src/types/NotificationAndroid.ts

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,36 @@ export interface AndroidMessagingStyle {
723723
group?: boolean;
724724
}
725725

726+
/**
727+
* The interface for messages when constructing a Messaging Style notification.
728+
*
729+
* <Vimeo id="android-style-messaging" caption="Android Messaging Style" />
730+
*
731+
* View the [`AndroidMessagingStyle`](/react-native/reference/androidmessagingstyle) reference
732+
* and [Messaging](/react-native/docs/android/styles#messaging) documentation to learn more.
733+
*
734+
* @platform android
735+
*/
736+
export interface AndroidMessagingStyleMessage {
737+
/**
738+
* The content of the message.
739+
*/
740+
text: string;
741+
742+
/**
743+
* The timestamp of when the message arrived in milliseconds.
744+
*/
745+
timestamp: number;
746+
747+
/**
748+
* The sender of this message. See [`AndroidPerson`](/react-native/reference/androidperson) reference
749+
* for more information on the properties available.
750+
*
751+
* This property should only be provided if the message is from an external person, and not the person receiving the message.
752+
*/
753+
person?: AndroidPerson;
754+
}
755+
726756
export const enum AndroidCallType {
727757
INCOMING = 1,
728758
ONGOING = 2,
@@ -746,13 +776,12 @@ export interface AndroidCallTypeScreening {
746776
hangUpAction: AndroidAction;
747777
}
748778

749-
750779
/**
751-
* The interface used when displaying a Phone Style notification.
780+
* The interface used when displaying a Call Style notification.
752781
*
753-
* <Vimeo id="android-style-messaging" caption="Android Messaging Style" />
782+
* <Vimeo id="android-style-call" caption="Android Call Style" />
754783
*
755-
* View the [Messaging](/react-native/docs/android/styles#messaging) documentation to learn more.
784+
* View the [Call](/react-native/docs/android/styles#call) documentation to learn more.
756785
*
757786
* @platform android
758787
*/
@@ -763,7 +792,7 @@ export interface AndroidCallStyle {
763792
type: AndroidStyle.CALL;
764793

765794
/**
766-
* The person who is receiving a message on the current device.
795+
* The person who is on the phone call.
767796
*/
768797
person: AndroidPerson;
769798

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

776-
/**
777-
* The interface for messages when constructing a Messaging Style notification.
778-
*
779-
* <Vimeo id="android-style-messaging" caption="Android Messaging Style" />
780-
*
781-
* View the [`AndroidMessagingStyle`](/react-native/reference/androidmessagingstyle) reference
782-
* and [Messaging](/react-native/docs/android/styles#messaging) documentation to learn more.
783-
*
784-
* @platform android
785-
*/
786-
export interface AndroidMessagingStyleMessage {
787-
/**
788-
* The content of the message.
789-
*/
790-
text: string;
791-
792-
/**
793-
* The timestamp of when the message arrived in milliseconds.
794-
*/
795-
timestamp: number;
796-
797-
/**
798-
* The sender of this message. See [`AndroidPerson`](/react-native/reference/androidperson) reference
799-
* for more information on the properties available.
800-
*
801-
* This property should only be provided if the message is from an external person, and not the person receiving the message.
802-
*/
803-
person?: AndroidPerson;
804-
}
805-
806805
/**
807806
* The interface used to describe a person shown in notifications.
808807
*

packages/react-native/src/validators/validateAndroidStyle.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
AndroidCallStyle,
1313
AndroidStyle,
1414
AndroidCallType,
15+
AndroidAction,
1516
} from '../types/NotificationAndroid';
1617
import { objectHasProperty, isArray, isBoolean, isNumber, isObject, isString } from '../utils';
1718
import validateAndroidPressAction from './validateAndroidPressAction';
@@ -322,7 +323,7 @@ export function validateAndroidMessagingStyle(style: AndroidMessagingStyle): And
322323
*/
323324
export 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

Comments
 (0)