diff --git a/app/sagas/rooms.js b/app/sagas/rooms.js index 3f240f729d..44eb41d85a 100644 --- a/app/sagas/rooms.js +++ b/app/sagas/rooms.js @@ -61,7 +61,13 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) { const subsToCreate = subscriptions.filter(i1 => !existingSubs.find(i2 => i1._id === i2._id)); const subsToDelete = existingSubs.filter(i1 => !subscriptions.find(i2 => i1._id === i2._id)); + const openedRooms = yield select(state => state.room.rooms); const lastMessages = subscriptions + /** Checks for opened rooms and filter them out. + * It prevents this process to try persisting the same last message on the room messages fetch. + * This race condition is easy to reproduce on push notification tap. + */ + .filter(sub => !openedRooms.includes(sub.rid)) .map(sub => sub.lastMessage && buildMessage(sub.lastMessage)) .filter(lm => lm); const lastMessagesIds = lastMessages.map(lm => lm._id);