Skip to content

Commit

Permalink
Removes opened rooms from last message persisting
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello committed Jan 5, 2021
1 parent ae74e87 commit ecd7cfb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/sagas/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ecd7cfb

Please sign in to comment.