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

[$1000] Chat - Offline sent messages with emojis added are displayed without emojis after going online #17110

Closed
3 of 6 tasks
kbecciv opened this issue Apr 7, 2023 · 21 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@kbecciv
Copy link

kbecciv commented Apr 7, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Go to https://staging.new.expensify.com/
  2. Switch offline
  3. Send several message in any chat
  4. Mark those messages with emojis
  5. Go online

Expected Result:

Emojis should stay

Actual Result:

Emojis disappear until page refresh

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • Windows / Chrome
  • MacOS / Desktop

Version Number: 1.2.96.0

Reproducible in staging?: Yes

Reproducible in production?: Yes

If this was caught during regression testing, add the test name, ID and link from TestRail:

Email or phone of affected tester (no customers):

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

Bug6009088_video_63.mp4

Expensify/Expensify Issue URL:

Issue reported by: Applause - Internal Team

Slack conversation:

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01dfa3e3f4c38de68c
  • Upwork Job ID: 1645558204841316352
  • Last Price Increase: 2023-04-10
@kbecciv kbecciv added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Apr 7, 2023
@MelvinBot
Copy link

Triggered auto assignment to @stephanieelliott (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@MelvinBot
Copy link

MelvinBot commented Apr 7, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@melvin-bot melvin-bot bot added the Overdue label Apr 10, 2023
@MelvinBot
Copy link

@stephanieelliott Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

1 similar comment
@MelvinBot
Copy link

@stephanieelliott Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@stephanieelliott
Copy link
Contributor

I was able to repro this on iOS/Safari

@melvin-bot melvin-bot bot removed the Overdue label Apr 10, 2023
@stephanieelliott stephanieelliott added the External Added to denote the issue can be worked on by a contributor label Apr 10, 2023
@melvin-bot melvin-bot bot changed the title Chat - Offline sent messages with emojis added are displayed without emojis after going online [$1000] Chat - Offline sent messages with emojis added are displayed without emojis after going online Apr 10, 2023
@MelvinBot
Copy link

Job added to Upwork: https://www.upwork.com/jobs/~01dfa3e3f4c38de68c

@MelvinBot
Copy link

Current assignee @stephanieelliott is eligible for the External assigner, not assigning anyone new.

@MelvinBot
Copy link

Triggered auto assignment to Contributor-plus team member for initial proposal review - @eVoloshchak (External)

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 10, 2023
@MelvinBot
Copy link

Triggered auto assignment to @bondydaa (External), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@dukenv0307
Copy link
Contributor

dukenv0307 commented Apr 11, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Chat - Offline sent messages with emojis added are displayed without emojis after going online

What is the root cause of that problem?

When sending a message and then adding the emoji, the app will be received 2 eventData from pusher in the correct order, the first one is adding a new message (pushJSON 1) and the second one is adding emoji (pushJSON 2). But the application will update pushJSON 2 into ONYX before updating pushJSON 1. So that the pushJSON 1 will override the pushJSON 2 and the change of pushJSON 2 will not be saved in ONYX

This line makes pushJSON update order reversed.

SequentialQueue.getCurrentRequest().then(() => {

To explain this, we can take a look at this function

function process() {
const persistedRequests = PersistedRequests.getAll();
if (_.isEmpty(persistedRequests) || NetworkStore.isOffline()) {
return Promise.resolve();
}
const requestToProcess = persistedRequests[0];
// Set the current request to a promise awaiting its processing so that getCurrentRequest can be used to take some action after the current request has processed.
currentRequest = Request.processWithMiddleware(requestToProcess, true).then(() => {
PersistedRequests.remove(requestToProcess);
RequestThrottle.clear();
return process();
}).catch((error) => {
// On sign out we cancel any in flight requests from the user. Since that user is no longer signed in their requests should not be retried.
if (error.name === CONST.ERROR.REQUEST_CANCELLED) {
PersistedRequests.remove(requestToProcess);
RequestThrottle.clear();
return process();
}
return RequestThrottle.sleep().then(process);
});
return currentRequest;
}

We just run update callback when SequentialQueue.getCurrentRequest() or process() get finished, but the currentRequest is re-assign to the next request and run process() recursively if the persistedRequests is not empty. That makes the callbacks are executed in the reverse order

What changes do you think we should make in order to solve the problem?

in here

PusherUtils.subscribeToPrivateUserChannelEvent(Pusher.TYPE.ONYX_API_UPDATE, currentUserAccountID, (pushJSON) => {
SequentialQueue.getCurrentRequest().then(() => {
Onyx.update(pushJSON);
triggerNotifications(pushJSON);
});
});

After theCurrentRequest is resolved, we shouldn't update the PushJSON into ONYX immediately. First, we should push all PushJSON into a new array. After all, pushJSONs are added to the new array (The order of pushing pushJSONs into the array is being reversed), we will reverse the new array and update each element of the new array to ONYX

This is the demo code

let pushJSONData = [];   
let numberOfPushJSON = 0;  // To save the number of  pushJSON

    // Receive any relevant Onyx updates from the server
    PusherUtils.subscribeToPrivateUserChannelEvent(Pusher.TYPE.ONYX_API_UPDATE, currentUserAccountID, (pushJSON) => {
        numberOfPushJSON++;
        SequentialQueue.getCurrentRequest().then(() => {
            pushJSONData.push(pushJSON);
            if (numberOfPushJSON === pushJSONData.length) {     // check if the all PushJSONs are ready to update into ONYX
                pushJSONData.reverse().forEach((data) => {
                    Onyx.update(data);
                    triggerNotifications(data);
                });
                pushJSONData = [];
                numberOfPushJSON = 0;
            }
        });
    });

What alternative solutions did you explore? (Optional)

NA

Result

Work well
https://user-images.githubusercontent.com/129500732/230879227-1859d99f-d728-4198-8ec7-51fa355683e9.mp4

@hellohublot
Copy link
Contributor

There are several similar issues, #15998 (comment)
Maybe should hold by #12775

@melvin-bot melvin-bot bot added the Overdue label Apr 13, 2023
@bondydaa
Copy link
Contributor

I DM'd @neil-marcellini to see if he could confirm if #12775 would also fix this or not.

@melvin-bot melvin-bot bot removed the Overdue label Apr 13, 2023
@neil-marcellini
Copy link
Contributor

neil-marcellini commented Apr 13, 2023

Since it's two write actions taken while offline, and then a refresh is required to see the correct state, it's very likely the replay effect. I'll add it to the tracking issue.

@bondydaa bondydaa changed the title [$1000] Chat - Offline sent messages with emojis added are displayed without emojis after going online [Hold][$1000] Chat - Offline sent messages with emojis added are displayed without emojis after going online Apr 13, 2023
@bondydaa
Copy link
Contributor

awesome thank you. throwing a hold on this and taking off help wanted for now.

We can retest once and re-add once the main PR(s) are merged.

@bondydaa bondydaa added Monthly KSv2 and removed Help Wanted Apply this label when an issue is open to proposals by contributors labels Apr 13, 2023
@bondydaa bondydaa removed the Daily KSv2 label Apr 13, 2023
@melvin-bot melvin-bot bot added the Overdue label May 15, 2023
@stephanieelliott
Copy link
Contributor

Main PRs are still open, this is still on hold.

@melvin-bot melvin-bot bot removed the Overdue label May 16, 2023
@neil-marcellini
Copy link
Contributor

The replay effect fix is on staging so I'll take this off of hold and we can retest.

@neil-marcellini neil-marcellini changed the title [Hold][$1000] Chat - Offline sent messages with emojis added are displayed without emojis after going online [$1000] Chat - Offline sent messages with emojis added are displayed without emojis after going online May 16, 2023
@neil-marcellini
Copy link
Contributor

neil-marcellini commented May 16, 2023

It looks like it's mostly fixed, but there's still a problem with the first reacted message.

Screen.Recording.2023-05-16.at.8.47.57.AM.mov

@dukenv0307
Copy link
Contributor

dukenv0307 commented May 17, 2023

After checking the code carefully, i noticed that the function subscribeToUserDeprecatedEvents cause this bug. As @tgolen 's comment, this function will be removed soon cc @neil-marcellini.
#18192
Hope this helps

@neil-marcellini
Copy link
Contributor

Pusher events should not be sent to the requesting client because we use a Pusher socket_id to prevent sending the events to that socket. Can you add logging and provide evidence that we are in fact receiving Push events here?

If so then we'll have to figure out why the socket is still receiving the events.

@bondydaa bondydaa added Weekly KSv2 and removed Monthly KSv2 labels May 17, 2023
@tgolen
Copy link
Contributor

tgolen commented May 17, 2023

Hi! I think it's possible that what you're seeing is the same as #16506 that I've been working on for a couple of weeks 😅 . If you can verify it's the same issue, then you can ignore it for now.

@stephanieelliott
Copy link
Contributor

Ah yes, that seems like it may be the same issue. Will leave this open a bit longer for others to confirm for themselves though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests

9 participants