[fcm] Tweak names to make things clearer

This commit is contained in:
Chris Bianca 2018-02-09 09:23:03 +00:00
parent 326d1778c6
commit 7cac981468
5 changed files with 61 additions and 60 deletions

View File

@ -264,7 +264,7 @@ RCT_EXPORT_METHOD(unsubscribeFromTopic: (NSString*) topic) {
// Response handler methods
RCT_EXPORT_METHOD(finishNotificationResponse: (NSString*) messageId) {
RCT_EXPORT_METHOD(completeNotificationResponse: (NSString*) messageId) {
void(^callbackHandler)() = [_callbackHandlers objectForKey:messageId];
if (!callbackHandler) {
NSLog(@"There is no callback handler for messageId: %@", messageId);
@ -274,8 +274,8 @@ RCT_EXPORT_METHOD(finishNotificationResponse: (NSString*) messageId) {
[_callbackHandlers removeObjectForKey:messageId];
}
RCT_EXPORT_METHOD(finishPresentNotification: (NSString*) messageId
result: (NSString*) result) {
RCT_EXPORT_METHOD(completePresentNotification: (NSString*) messageId
result: (NSString*) result) {
void(^callbackHandler)(UNNotificationPresentationOptions) = [_callbackHandlers objectForKey:messageId];
if (!callbackHandler) {
NSLog(@"There is no callback handler for messageId: %@", messageId);
@ -294,8 +294,8 @@ RCT_EXPORT_METHOD(finishPresentNotification: (NSString*) messageId
[_callbackHandlers removeObjectForKey:messageId];
}
RCT_EXPORT_METHOD(finishRemoteNotification: (NSString*) messageId
result: (NSString*) result) {
RCT_EXPORT_METHOD(completeRemoteNotification: (NSString*) messageId
result: (NSString*) result) {
void(^callbackHandler)(UIBackgroundFetchResult) = [_callbackHandlers objectForKey:messageId];
if (!callbackHandler) {
NSLog(@"There is no callback handler for messageId: %@", messageId);

View File

@ -4,5 +4,6 @@
import firebase from './modules/core/firebase';
export type { default as User } from './modules/auth/User';
export type { default as Message } from './modules/messaging/Message';
export default firebase;

View File

@ -6,23 +6,23 @@ import { Platform } from 'react-native';
import { getNativeModule } from '../../utils/native';
import {
MessageType,
PresentNotificationResult,
RemoteNotificationResult,
WillPresentNotificationResult,
} from './types';
import type Messaging from './';
import type {
MessageTypeType,
NativeMessage,
Notification,
PresentNotificationResultType,
RemoteNotificationResultType,
WillPresentNotificationResultType,
} from './types';
/**
* @class Message
*/
export default class Message {
_finished: boolean;
_completed: boolean;
_messaging: Messaging;
_message: NativeMessage;
@ -71,19 +71,19 @@ export default class Message {
return this._message.ttl;
}
finish(
result?: RemoteNotificationResultType | WillPresentNotificationResultType
complete(
result?: PresentNotificationResultType | RemoteNotificationResultType
): void {
if (Platform.OS !== 'ios') {
return;
}
if (!this._finished) {
this._finished = true;
if (!this._completed) {
this._completed = true;
switch (this.messageType) {
case MessageType.NotificationResponse:
getNativeModule(this._messaging).finishNotificationResponse(
getNativeModule(this._messaging).completeNotificationResponse(
this.messageId
);
break;
@ -91,13 +91,13 @@ export default class Message {
case MessageType.PresentNotification:
if (
result &&
!Object.values(WillPresentNotificationResult).includes(result)
!Object.values(PresentNotificationResult).includes(result)
) {
throw new Error(`Invalid WillPresentNotificationResult: ${result}`);
throw new Error(`Invalid PresentNotificationResult: ${result}`);
}
getNativeModule(this._messaging).finishPresentNotification(
getNativeModule(this._messaging).completePresentNotification(
this.messageId,
result || WillPresentNotificationResult.None
result || PresentNotificationResult.None
);
break;
@ -108,7 +108,7 @@ export default class Message {
) {
throw new Error(`Invalid RemoteNotificationResult: ${result}`);
}
getNativeModule(this._messaging).finishRemoteNotification(
getNativeModule(this._messaging).completeRemoteNotification(
this.messageId,
result || RemoteNotificationResult.NoData
);

View File

@ -12,8 +12,8 @@ import Message from './Message';
import RemoteMessage from './RemoteMessage';
import {
MessageType,
PresentNotificationResult,
RemoteNotificationResult,
WillPresentNotificationResult,
} from './types';
import type App from '../core/firebase-app';
@ -92,7 +92,7 @@ export default class Messaging extends ModuleBase {
const wrappedListener = async (nativeMessage: NativeMessage) => {
const message = new Message(this, nativeMessage);
await listener(message);
message.finish();
message.complete();
};
SharedEventEmitter.addListener('onMessage', wrappedListener);
@ -201,7 +201,7 @@ export default class Messaging extends ModuleBase {
export const statics = {
MessageType,
PresentNotificationResult,
RemoteMessage,
RemoteNotificationResult,
WillPresentNotificationResult,
};

View File

@ -11,24 +11,24 @@ export const MessageType = {
RemoteNotificationHandler: 'RemoteNotificationHandler',
};
export const PresentNotificationResult = {
All: 'UNNotificationPresentationOptionAll',
None: 'UNNotificationPresentationOptionNone',
};
export const RemoteNotificationResult = {
NewData: 'UIBackgroundFetchResultNewData',
NoData: 'UIBackgroundFetchResultNoData',
ResultFailed: 'UIBackgroundFetchResultFailed',
};
export const WillPresentNotificationResult = {
All: 'UNNotificationPresentationOptionAll',
None: 'UNNotificationPresentationOptionNone',
};
export type MessageTypeType = $Values<typeof MessageType>;
export type PresentNotificationResultType = $Values<
typeof PresentNotificationResult
>;
export type RemoteNotificationResultType = $Values<
typeof RemoteNotificationResult
>;
export type WillPresentNotificationResultType = $Values<
typeof WillPresentNotificationResult
>;
export type Notification = {
body: string,