Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Filter DeleteMessage when computing the oldest loaded message [WPB-3506] #15686

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

atomrc
Copy link
Contributor

@atomrc atomrc commented Aug 29, 2023

BugWPB-3506 [Web] Conversation list is not updated with new messages

The bug

loading a conversation that contains a DeleteMessage that hasn't been seen yet by the user will not show messages after this deleted message

The problem

When messages arrives for a conversation that is not currently viewed by the user, we stack those messages in the messages property of the conversation.

When the user clicks on a conversation to view, these are the steps that are triggered to load the messages we want to display to them:

  • we check what is the oldest message that we have in the messages list;
  • starting from this oldest message, we load 30 messages from DB in reverse chronology (so messages that were sent before this oldest message that we have loaded)
  • those loaded messages are added to the messages list
  • the conversation can finally be showed to the user

This logic works pretty fine, except for DeleteMessage which can have a timestamp in the past.
Since delete messages timestamp are actually the timestamp of the message that was deleted.

An example

let's say we have a conversation between user1 and user2 with those messages:

  • message1 by user2 (sent at timestamp 0)
  • message2 by user2 (sent at timestamp 2)
  • message3 by user2(sent at timestamp 3)

user1, is not currently looking at this conversation (so no messages are loaded into memory).

  • user2, now deletes message1.
  • user1 receives the delete event and store it in the messages list
  • the oldest message that user1 has loaded is the delete message for message1 which has a timestamp of 0.
  • user1 tries to load the conversation
  • we try to load all messages in the conversation from timestamp 0
  • we end-up not loading message2 and message3.

The fix

We computing the oldest message, we should not consider delete messages as we cannot trust their timestamp

@atomrc atomrc requested review from otto-the-bot and a team as code owners August 29, 2023 15:38
@atomrc atomrc changed the title fix: Filter DeleteMessage when computing the oldest loaded message fix: Filter DeleteMessage when computing the oldest loaded message [WPB-3506] Aug 29, 2023
@atomrc atomrc changed the base branch from fix/last-message-loading to dev August 29, 2023 15:40
@codecov
Copy link

codecov bot commented Aug 29, 2023

Codecov Report

Merging #15686 (0e6c6d4) into dev (36d7231) will increase coverage by 0.00%.
The diff coverage is 88.88%.

@@           Coverage Diff           @@
##              dev   #15686   +/-   ##
=======================================
  Coverage   43.81%   43.82%           
=======================================
  Files         672      672           
  Lines       22684    22688    +4     
  Branches     5159     5160    +1     
=======================================
+ Hits         9940     9944    +4     
  Misses      11494    11494           
  Partials     1250     1250           

Copy link
Contributor

@PatrykBuniX PatrykBuniX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing 🚀 Very nice explained, what a deep dive it was!

Copy link
Contributor

@tlebon tlebon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great that you left some info for anyone reading this in the future

@atomrc atomrc merged commit 0a29adc into dev Aug 29, 2023
13 checks passed
@atomrc atomrc deleted the fix/oldest-message branch August 29, 2023 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants