[FIX] Notification preferences update crashing the app (#2262)

This commit is contained in:
Diego Mello 2020-07-08 17:46:05 -03:00
parent fa2c93fa2b
commit fd3f0a3417
1 changed files with 23 additions and 18 deletions

View File

@ -16,6 +16,7 @@ import RocketChat from '../../lib/rocketchat';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import protectedFunction from '../../lib/methods/helpers/protectedFunction'; import protectedFunction from '../../lib/methods/helpers/protectedFunction';
import SafeAreaView from '../../containers/SafeAreaView'; import SafeAreaView from '../../containers/SafeAreaView';
import log from '../../utils/log';
const SectionTitle = React.memo(({ title, theme }) => ( const SectionTitle = React.memo(({ title, theme }) => (
<Text <Text
@ -183,26 +184,30 @@ class NotificationPreferencesView extends React.Component {
const { room } = this.state; const { room } = this.state;
const db = database.active; const db = database.active;
await db.action(async() => {
await room.update(protectedFunction((r) => {
r[key] = value;
}));
});
try { try {
const result = await RocketChat.saveNotificationSettings(this.rid, params); await db.action(async() => {
if (result.success) { await room.update(protectedFunction((r) => {
return; r[key] = value;
} }));
} catch { });
// do nothing
}
await db.action(async() => { try {
await room.update(protectedFunction((r) => { const result = await RocketChat.saveNotificationSettings(this.rid, params);
r[key] = room[key]; 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' }); onValueChangeSwitch = (key, value) => this.saveNotificationSettings(key, value, { [key]: value ? '1' : '0' });