[FIX] Load messages (#1910)

* Create updateLastOpen param on readMessages

* Remove InteractionManager from load messages
This commit is contained in:
Diego Mello 2020-03-30 17:10:19 -03:00 committed by GitHub
parent 475ccbd9c7
commit 3437b9039f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 15 deletions

View File

@ -1,5 +1,3 @@
import { InteractionManager } from 'react-native';
import log from '../../utils/log';
import updateMessages from './updateMessages';
@ -22,10 +20,8 @@ export default function loadMessagesForRoom(args) {
const data = await load.call(this, args);
if (data && data.length) {
InteractionManager.runAfterInteractions(async() => {
await updateMessages({ rid: args.rid, update: data });
return resolve(data);
});
} else {
return resolve([]);
}

View File

@ -1,5 +1,3 @@
import { InteractionManager } from 'react-native';
import database from '../database';
import log from '../../utils/log';
import updateMessages from './updateMessages';
@ -35,9 +33,7 @@ export default function loadMissedMessages(args) {
if (data) {
const { updated, deleted } = data;
InteractionManager.runAfterInteractions(async() => {
await updateMessages({ rid: args.rid, update: updated, remove: deleted });
});
}
resolve();
} catch (e) {

View File

@ -1,7 +1,7 @@
import database from '../database';
import log from '../../utils/log';
export default async function readMessages(rid, lastOpen) {
export default async function readMessages(rid, ls, updateLastOpen = false) {
try {
const db = database.active;
const subscription = await db.collections.get('subscriptions').find(rid);
@ -17,8 +17,10 @@ export default async function readMessages(rid, lastOpen) {
s.unread = 0;
s.userMentions = 0;
s.groupMentions = 0;
s.ls = lastOpen;
s.lastOpen = lastOpen;
s.ls = ls;
if (updateLastOpen) {
s.lastOpen = ls;
}
});
} catch (e) {
// Do nothing

View File

@ -341,7 +341,7 @@ class RoomView extends React.Component {
} else {
this.setLastOpen(null);
}
RocketChat.readMessages(room.rid, newLastOpen).catch(e => console.log(e));
RocketChat.readMessages(room.rid, newLastOpen, true).catch(e => console.log(e));
this.sub.subscribe();
}
}