From b4565c4639f5e90f3b3567bf4ad494583977fdb5 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 4 Dec 2019 10:02:27 -0300 Subject: [PATCH] [FIX] Init local settings on notification tap --- app/actions/actionsTypes.js | 2 +- app/actions/index.js | 6 ++++++ app/index.js | 3 ++- app/sagas/init.js | 21 ++++++++++++--------- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/actions/actionsTypes.js b/app/actions/actionsTypes.js index 5430706234..ced5b25ef4 100644 --- a/app/actions/actionsTypes.js +++ b/app/actions/actionsTypes.js @@ -31,7 +31,7 @@ export const ROOMS = createRequestTypes('ROOMS', [ 'CLOSE_SEARCH_HEADER' ]); export const ROOM = createRequestTypes('ROOM', ['LEAVE', 'ERASE', 'USER_TYPING']); -export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT']); +export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT', 'INIT_LOCAL_SETTINGS']); export const MESSAGES = createRequestTypes('MESSAGES', ['REPLY_BROADCAST']); export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [...defaultTypes]); export const SELECTED_USERS = createRequestTypes('SELECTED_USERS', ['ADD_USER', 'REMOVE_USER', 'RESET', 'SET_LOADING']); diff --git a/app/actions/index.js b/app/actions/index.js index ca322276ad..494cb1c934 100644 --- a/app/actions/index.js +++ b/app/actions/index.js @@ -20,6 +20,12 @@ export function appInit() { }; } +export function appInitLocalSettings() { + return { + type: APP.INIT_LOCAL_SETTINGS + }; +} + export function setCurrentServer(server) { return { type: types.SET_CURRENT_SERVER, diff --git a/app/index.js b/app/index.js index a75b956b2b..1b61e52c10 100644 --- a/app/index.js +++ b/app/index.js @@ -9,7 +9,7 @@ import Modal from 'react-native-modal'; import KeyCommands, { KeyCommandsEmitter } from 'react-native-keycommands'; import EventEmitter from './utils/events'; -import { appInit } from './actions'; +import { appInit, appInitLocalSettings } from './actions'; import { deepLinkingOpen } from './actions/deepLinking'; import Navigation from './lib/Navigation'; import Sidebar from './views/SidebarView'; @@ -508,6 +508,7 @@ export default class Root extends React.Component { init = async() => { const [notification, deepLinking] = await Promise.all([initializePushNotifications(), Linking.getInitialURL()]); const parsedDeepLinkingURL = parseDeepLinking(deepLinking); + store.dispatch(appInitLocalSettings()); if (notification) { onNotification(notification); } else if (parsedDeepLinkingURL) { diff --git a/app/sagas/init.js b/app/sagas/init.js index 022177c44a..696cef4280 100644 --- a/app/sagas/init.js +++ b/app/sagas/init.js @@ -20,6 +20,17 @@ import { isIOS } from '../utils/deviceInfo'; import database from '../lib/database'; import protectedFunction from '../lib/methods/helpers/protectedFunction'; +export const initLocalSettings = function* initLocalSettings() { + const sortPreferences = yield RocketChat.getSortPreferences(); + yield put(setAllPreferences(sortPreferences)); + + const useMarkdown = yield RocketChat.getUseMarkdown(); + yield put(toggleMarkdown(useMarkdown)); + + const allowCrashReport = yield RocketChat.getAllowCrashReport(); + yield put(toggleCrashReport(allowCrashReport)); +}; + const restore = function* restore() { try { let hasMigration; @@ -84,15 +95,6 @@ const restore = function* restore() { } } - const sortPreferences = yield RocketChat.getSortPreferences(); - yield put(setAllPreferences(sortPreferences)); - - const useMarkdown = yield RocketChat.getUseMarkdown(); - yield put(toggleMarkdown(useMarkdown)); - - const allowCrashReport = yield RocketChat.getAllowCrashReport(); - yield put(toggleCrashReport(allowCrashReport)); - if (!token || !server) { yield all([ RNUserDefaults.clear(RocketChat.TOKEN_KEY), @@ -127,5 +129,6 @@ const start = function* start({ root }) { const root = function* root() { yield takeLatest(APP.INIT, restore); yield takeLatest(APP.START, start); + yield takeLatest(APP.INIT_LOCAL_SETTINGS, initLocalSettings); }; export default root;