From 90834ad3b40491aa7acb92f30abcc9e976e3d2b3 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 19 Feb 2020 13:41:43 -0300 Subject: [PATCH] Prevent pending updates error --- app/lib/methods/subscriptions/rooms.js | 4 ++-- app/lib/methods/updateMessages.js | 12 ++++++++++++ app/lib/rocketchat.js | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/lib/methods/subscriptions/rooms.js b/app/lib/methods/subscriptions/rooms.js index 5dc0913c16..02fac22f3b 100644 --- a/app/lib/methods/subscriptions/rooms.js +++ b/app/lib/methods/subscriptions/rooms.js @@ -242,12 +242,12 @@ export default function subscribeRooms() { log(e); } } else { - // debouncedUpdateSub(data); + debouncedUpdateSub(data); } } if (/rooms/.test(ev)) { if (type === 'updated' || type === 'inserted') { - // debouncedUpdateRoom(data); + debouncedUpdateRoom(data); } } if (/message/.test(ev)) { diff --git a/app/lib/methods/updateMessages.js b/app/lib/methods/updateMessages.js index 77a0ced435..350ece5019 100644 --- a/app/lib/methods/updateMessages.js +++ b/app/lib/methods/updateMessages.js @@ -74,17 +74,29 @@ export default function updateMessages({ rid, update = [], remove = [] }) { // Update msgsToUpdate = msgsToUpdate.map((message) => { const newMessage = update.find(m => m._id === message.id); + if (message._hasPendingUpdate) { + console.log(message); + return; + } return message.prepareUpdate(protectedFunction((m) => { Object.assign(m, newMessage); })); }); threadsToUpdate = threadsToUpdate.map((thread) => { + if (thread._hasPendingUpdate) { + console.log(thread); + return; + } const newThread = allThreads.find(t => t._id === thread.id); return thread.prepareUpdate(protectedFunction((t) => { Object.assign(t, newThread); })); }); threadMessagesToUpdate = threadMessagesToUpdate.map((threadMessage) => { + if (threadMessage._hasPendingUpdate) { + console.log(threadMessage); + return; + } const newThreadMessage = allThreadMessages.find(t => t._id === threadMessage.id); return threadMessage.prepareUpdate(protectedFunction((tm) => { Object.assign(tm, newThreadMessage); diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 866145fe2e..634cbb812f 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -1096,7 +1096,7 @@ const RocketChat = { InteractionManager.runAfterInteractions(() => { reduxStore.dispatch(setActiveUsers(activeUsers)); }); - // this.sdk.subscribe('stream-notify-logged', 'user-status'); + this.sdk.subscribe('stream-notify-logged', 'user-status'); return resolve(); } }