Commit a516fa8b authored by Gijs Hendriksen's avatar Gijs Hendriksen
Browse files

Merge branch 'feature/pushnotification-token-refresh' into 'master'

Use tokenSelector in pushNotifications saga and dispatch register action on push token refresh

See merge request !70
parents 940d4cab 871e2e62
export const REGISTER = 'PUSH_NOTIFICATIONS_REGISTER';
export const INVALIDATE = 'PUSH_NOTIFICATIONS_INVALIDATE';
export function register(token) {
return { type: REGISTER, payload: { token } };
export function register() {
return { type: REGISTER };
}
export function invalidate() {
......
......@@ -45,6 +45,10 @@ FCM.on(FCMEvent.Notification, async (notif) => {
}
});
FCM.on(FCMEvent.RefreshToken, async () => {
store.dispatch(register());
});
class Main extends Component {
componentDidMount() {
Moment.locale('nl');
......@@ -59,7 +63,7 @@ class Main extends Component {
if (username !== null && token !== null) {
store.dispatch(loginActions.success(username, token, displayName, photo, ''));
store.dispatch(register(token));
store.dispatch(register());
}
});
}
......
......@@ -50,7 +50,7 @@ const login = function* login(action) {
yield put(loginActions.success(
user, token, displayName, avatar,
));
yield put(pushNotificationsActions.register(token));
yield put(pushNotificationsActions.register());
yield delay(2000);
yield put(loginActions.reset());
} catch (error) {
......
import { call, takeEvery } from 'redux-saga/effects';
import { call, takeEvery, select } from 'redux-saga/effects';
import { Platform } from 'react-native';
import FCM from 'react-native-fcm';
import { apiRequest } from '../url';
import { apiRequest, tokenSelector } from '../url';
import * as pushNotificationsActions from '../actions/pushNotifications';
const register = function* register(action) {
const { token } = action.payload;
const register = function* register() {
const token = yield select(tokenSelector);
let pushToken;
if (Platform.OS === 'ios') {
yield call(FCM.requestPermissions);
pushToken = yield call(FCM.getFCMToken);
} else {
yield call(FCM.requestPermissions);
pushToken = yield call(FCM.getFCMToken);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment