[CHORE] Remove InteractionManager blocks (#2906)

* [FIX] Remove InteractionManager blocks

* Minor fix

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Gung Wah 2021-02-24 02:36:20 +08:00 committed by GitHub
parent 120f50d5d2
commit 3a950547f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 122 additions and 151 deletions

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import lt from 'semver/functions/lt';
import orderBy from 'lodash/orderBy';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
@ -95,7 +94,6 @@ export function getCustomEmojis() {
// RC 0.61.0
const result = await this.sdk.get('emoji-custom');
InteractionManager.runAfterInteractions(async() => {
let { emojis } = result;
emojis = emojis.filter(emoji => !updatedSince || emoji._updatedAt > updatedSince);
const changedEmojis = await updateEmojis({ update: emojis, allRecords });
@ -106,7 +104,6 @@ export function getCustomEmojis() {
setCustomEmojis();
}
return resolve();
});
} else {
const params = {};
if (updatedSince) {
@ -120,7 +117,6 @@ export function getCustomEmojis() {
return resolve();
}
InteractionManager.runAfterInteractions(async() => {
const { emojis } = result;
const { update, remove } = emojis;
const changedEmojis = await updateEmojis({ update, remove, allRecords });
@ -130,7 +126,6 @@ export function getCustomEmojis() {
if (changedEmojis) {
setCustomEmojis();
}
});
}
} catch (e) {
log(e);

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import lt from 'semver/functions/lt';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import orderBy from 'lodash/orderBy';
@ -85,10 +84,8 @@ export default function() {
if (!result.success) {
return resolve();
}
InteractionManager.runAfterInteractions(async() => {
await updatePermissions({ update: result.permissions, allRecords });
return resolve();
});
} else {
const params = {};
const updatedSince = await getUpdatedSince(allRecords);
@ -102,10 +99,8 @@ export default function() {
return resolve();
}
InteractionManager.runAfterInteractions(async() => {
await updatePermissions({ update: result.update, remove: result.delete, allRecords });
return resolve();
});
}
} catch (e) {
log(e);

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import database from '../database';
@ -19,7 +18,6 @@ export default function() {
const { roles } = result;
if (roles && roles.length) {
InteractionManager.runAfterInteractions(async() => {
await db.action(async() => {
const rolesCollections = db.collections.get('roles');
const allRolesRecords = await rolesCollections.query().fetch();
@ -55,7 +53,6 @@ export default function() {
return allRecords.length;
});
return resolve();
});
}
} catch (e) {
log(e);

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import database from '../database';
@ -20,7 +19,6 @@ export default function() {
const { commands } = result;
if (commands && commands.length) {
InteractionManager.runAfterInteractions(async() => {
await db.action(async() => {
const slashCommandsCollection = db.collections.get('slash_commands');
const allSlashCommandsRecords = await slashCommandsCollection.query().fetch();
@ -61,7 +59,6 @@ export default function() {
}
return allRecords.length;
});
});
}
} catch (e) {
log(e);

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import { Q } from '@nozbe/watermelondb';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
@ -30,7 +29,6 @@ export default function loadThreadMessages({ tmid, rid, offset = 0 }) {
let data = await load.call(this, { tmid, offset });
if (data && data.length) {
InteractionManager.runAfterInteractions(async() => {
try {
data = data.map(m => buildMessage(m));
data = await Encryption.decryptMessages(data);
@ -67,7 +65,6 @@ export default function loadThreadMessages({ tmid, rid, offset = 0 }) {
log(e);
}
return resolve(data);
});
} else {
return resolve([]);
}

View File

@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FlatList, InteractionManager } from 'react-native';
import { FlatList } from 'react-native';
import { connect } from 'react-redux';
import { Q } from '@nozbe/watermelondb';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
@ -73,9 +73,7 @@ class ThreadMessagesView extends React.Component {
componentDidMount() {
this.mounted = true;
this.mountInteraction = InteractionManager.runAfterInteractions(() => {
this.init();
});
}
componentDidUpdate(prevProps) {
@ -89,12 +87,6 @@ class ThreadMessagesView extends React.Component {
componentWillUnmount() {
console.countReset(`${ this.constructor.name }.render calls`);
if (this.mountInteraction && this.mountInteraction.cancel) {
this.mountInteraction.cancel();
}
if (this.syncInteraction && this.syncInteraction.cancel) {
this.syncInteraction.cancel();
}
if (this.subSubscription && this.subSubscription.unsubscribe) {
this.subSubscription.unsubscribe();
}
@ -330,10 +322,8 @@ class ThreadMessagesView extends React.Component {
rid: this.rid, updatedSince: updatedSince.toISOString()
});
if (result.success && result.threads) {
this.syncInteraction = InteractionManager.runAfterInteractions(() => {
const { update, remove } = result.threads;
this.updateThreads({ update, remove, lastThreadSync: updatedSince });
});
}
this.setState({
loading: false