From fd3f0a3417e44cddfe4c0912dc613e1d8bff94ea Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 8 Jul 2020 17:46:05 -0300 Subject: [PATCH] [FIX] Notification preferences update crashing the app (#2262) --- .../NotificationPreferencesView/index.js | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/app/views/NotificationPreferencesView/index.js b/app/views/NotificationPreferencesView/index.js index 1c0f43c8c..31a0fc679 100644 --- a/app/views/NotificationPreferencesView/index.js +++ b/app/views/NotificationPreferencesView/index.js @@ -16,6 +16,7 @@ import RocketChat from '../../lib/rocketchat'; import { withTheme } from '../../theme'; import protectedFunction from '../../lib/methods/helpers/protectedFunction'; import SafeAreaView from '../../containers/SafeAreaView'; +import log from '../../utils/log'; const SectionTitle = React.memo(({ title, theme }) => ( { - await room.update(protectedFunction((r) => { - r[key] = value; - })); - }); - try { - const result = await RocketChat.saveNotificationSettings(this.rid, params); - if (result.success) { - return; - } - } catch { - // do nothing - } + await db.action(async() => { + await room.update(protectedFunction((r) => { + r[key] = value; + })); + }); - await db.action(async() => { - await room.update(protectedFunction((r) => { - r[key] = room[key]; - })); - }); + try { + const result = await RocketChat.saveNotificationSettings(this.rid, params); + if (result.success) { + return; + } + } catch { + // do nothing + } + + await db.action(async() => { + await room.update(protectedFunction((r) => { + r[key] = room[key]; + })); + }); + } catch (e) { + log(e); + } } onValueChangeSwitch = (key, value) => this.saveNotificationSettings(key, value, { [key]: value ? '1' : '0' });