From 3437b9039f0a17b165550aa3d2666e702efa6853 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 30 Mar 2020 17:10:19 -0300 Subject: [PATCH] [FIX] Load messages (#1910) * Create updateLastOpen param on readMessages * Remove InteractionManager from load messages --- app/lib/methods/loadMessagesForRoom.js | 8 ++------ app/lib/methods/loadMissedMessages.js | 6 +----- app/lib/methods/readMessages.js | 8 +++++--- app/views/RoomView/index.js | 2 +- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/lib/methods/loadMessagesForRoom.js b/app/lib/methods/loadMessagesForRoom.js index c337bcc0f..41fe32161 100644 --- a/app/lib/methods/loadMessagesForRoom.js +++ b/app/lib/methods/loadMessagesForRoom.js @@ -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); - }); + await updateMessages({ rid: args.rid, update: data }); + return resolve(data); } else { return resolve([]); } diff --git a/app/lib/methods/loadMissedMessages.js b/app/lib/methods/loadMissedMessages.js index 3437044f8..82c2e1bda 100644 --- a/app/lib/methods/loadMissedMessages.js +++ b/app/lib/methods/loadMissedMessages.js @@ -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 }); - }); + await updateMessages({ rid: args.rid, update: updated, remove: deleted }); } resolve(); } catch (e) { diff --git a/app/lib/methods/readMessages.js b/app/lib/methods/readMessages.js index 552cd1e0e..e813a68b4 100644 --- a/app/lib/methods/readMessages.js +++ b/app/lib/methods/readMessages.js @@ -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 diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 2dd13f2d9..c450a866e 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -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(); } }