Skip to content

[HOLD for payment 2024-01-09] [$500] Web - Chat- A different group chat appears when refreshing the page #30868

Closed

Description

@kbecciv

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


Version Number: 1.3.94.0
Reproducible in staging?: y
Reproducible in production?: y
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
Expensify/Expensify Issue URL:
Issue reported by: @jliexpensify
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1698904742009159

Action Performed:

  1. Create a group conversation
  2. Type something
  3. Clicking on a profile
  4. Refresh the page

Expected Result:

The same group chat appears when refreshing the page

Actual Result:

A different group chat appears when refreshing the page

Workaround:

Unknown

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

2023-11-02_16-57-00.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01b7f90c720aa62a3c
  • Upwork Job ID: 1720504021677768704
  • Last Price Increase: 2023-11-03
  • Automatic offers:
    • shubham1206agra | Reviewer | 27782087
    • DylanDylann | Contributor | 27782088

Activity

  1. added
    External
    Daily
    Bug
    on Nov 3, 2023
  2. changed the title [-]Web - Chat- A different group chat appears when refreshing the page[/-] [+][$500] Web - Chat- A different group chat appears when refreshing the page[/+] on Nov 3, 2023
  3. melvin-bot commented on Nov 3, 2023

    @melvin-bot
  4. added
    Help Wanted
    on Nov 3, 2023
  5. melvin-bot commented on Nov 3, 2023

    @melvin-bot

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

  6. melvin-bot commented on Nov 3, 2023

    @melvin-bot

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

  7. melvin-bot commented on Nov 3, 2023

    @melvin-bot

    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
  8. FitseTLT commented on Nov 3, 2023

    @FitseTLT
    Contributor

    Proposal

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

    A different group chat is opened when we refresh while we have opened profile detail of group chat member

    What is the root cause of that problem?

    When we open profile detail of a member of a group chat the route is changed to '.../a/memberID or ParticipantID' so the report id is lost from the url, hence when we refresh the last group chat reportId will be populated to ReportScreen via ReportIDSetter in the below code

    // If there is no reportID in route, try to find last accessed and use it for setParams
    const reportID = getLastAccessedReportID(reports, !canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, lodashGet(route, 'params.openOnAdminRoom', false));

    which sets the reportID to the id returned from ReportUtils.findLastAccessedReport which does not reliably return the id of last opened report by the user.

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

    We need to save a stack of latest opened report ids the user opened in onyx everytime a user opens a report. Then we will populate the latest available report id from the stack in the ReportScreenIDSetter changing this line of code

    // If there is no reportID in route, try to find last accessed and use it for setParams
    const reportID = getLastAccessedReportID(reports, !canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, lodashGet(route, 'params.openOnAdminRoom', false));

    to

            const lastOpendAvailableID = _.find(lastOpenedReportIDs, (reportID) => _.find(reports, (report) => report.reportID === reportID));
            // If there is no reportID in route, try to find last accessed and use it for setParams
            const reportID =
                lastOpendAvailableID || getLastAccessedReportID(reports, !canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, lodashGet(route, 'params.openOnAdminRoom', false));
    
    

    after passing lastOpenedReportIDs prop via withOnyx here

    export default withOnyx({
        lastOpenedReportIDs: {
            key: ONYXKEYS.LAST_OPENED_REPORT_IDS,
        },
    

    So we will only fallback to the existing ReportUtils.findLastAccessedReport logic/code only in case when there is no available report id value saved in that new key ('LAST_OPENED_REPORT_IDS') we will create in onyx.
    We can update the 'LAST_OPENED_REPORT_IDS' value on onyx in a useEffect on ReportScreen that runs when there is a change in reportID and save up to say 10 recent opened ids which will serve us to be a back up in case last opened report id doesn't exist or got deleted.

         
        useEffect(() => {
            if (!_.isEmpty(reportID)) {
                const updatedLastOpenedIDs = _.clone(lastOpenedReportIDs || []);
    
                // to limit the no of ids saved to 10
                if (updatedLastOpenedIDs.length === 10) updatedLastOpenedIDs.pop();
                updatedLastOpenedIDs.unshift(reportID);
                Onyx.merge(ONYXKEYS.LAST_OPENED_REPORT_IDS, updatedLastOpenedIDs);
            }
        }, [reportID]);
    
    

    Moreover, we need to clear that value on onyx on signout so that a report ids saved for one user will not be used for another.

    POC:

    2023-11-03.23-07-08.mp4

    What alternative solutions did you explore? (Optional)

    or we can alternatively update the value in onyx every time the user navigates to a report.

  9. abzokhattab commented on Nov 3, 2023

    @abzokhattab
    Contributor

    Proposal

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

    A different report is opened when we refresh while we have opened profile detail of group chat member

    What is the root cause of that problem?

    the profile page route doesnt contain any info about the reportId therefore the opened report in the background is not the same

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

    we need to modify the url of the profile page to contain the url of the report:
    for example:
    this way the screenwrapper will get the reportid and then displays it
    /r/reportId/participants/:id/profile/

    or we can add reportId as a param and modify the screener to look for this param and open it in the background

  10. DylanDylann commented on Nov 4, 2023

    @DylanDylann
    Contributor

    Proposal

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

    • Web - Chat- A different group chat appears when refreshing the page

    What is the root cause of that problem?

    • When launching the app with the deeplink that does not contain reportID, we use the getLastAccessedReportID to get the report to display.
      const getLastAccessedReportID = (reports, ignoreDefaultRooms, policies, isFirstTimeNewExpensifyUser, openOnAdminRoom) => {
      // If deeplink url contains reportID params, we should show the report that has this reportID.
      const currentRoute = Navigation.getActiveRoute();
      const {reportID} = ReportUtils.parseReportRouteParams(currentRoute);
      if (reportID) {
      return reportID;
      }
      const lastReport = ReportUtils.findLastAccessedReport(reports, ignoreDefaultRooms, policies, isFirstTimeNewExpensifyUser, openOnAdminRoom);
      return lodashGet(lastReport, 'reportID');
      };
    • In the above, the findLastAccessedReport is not working properly.

      App/src/libs/ReportUtils.js

      Lines 575 to 581 in 7bd51eb

      function findLastAccessedReport(reports, ignoreDomainRooms, policies, isFirstTimeNewExpensifyUser, openOnAdminRoom = false) {
      // If it's the user's first time using New Expensify, then they could either have:
      // - just a Concierge report, if so we'll return that
      // - their Concierge report, and a separate report that must have deeplinked them to the app before they created their account.
      // If it's the latter, we'll use the deeplinked report over the Concierge report,
      // since the Concierge report would be incorrectly selected over the deep-linked report in the logic below.
      let sortedReports = sortReportsByLastRead(reports);
    • findLastAccessedReport uses sortReportsByLastRead:

      App/src/libs/ReportUtils.js

      Lines 263 to 269 in 7bd51eb

      function sortReportsByLastRead(reports) {
      return _.chain(reports)
      .toArray()
      .filter((report) => report && report.reportID && report.lastReadTime)
      .sortBy('lastReadTime')
      .value();
      }
      that will sort the reports by "lastReadTime". This is incorrect because the "lastReadTime" refers to the latest time the user read a new message, not the latest time the user visits a report. For example, if we read a new message A on 3/10/2023, and re-visit its report on 4/10/2023, the "lastReadTime" is still '3/10/2023'.

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

    • Once we visit the report, we need to add the lastVisitTime: DateUtils.getDBTime() to the report or use ONYXKEYS.COLLECTION.REPORT_METADATA to store the above data.

    • Then, in the sortReportsByLastRead, using lastVisitTime to sort the reports. We can do it by updating:

      App/src/libs/ReportUtils.js

      Lines 263 to 269 in 7bd51eb

      function sortReportsByLastRead(reports) {
      return _.chain(reports)
      .toArray()
      .filter((report) => report && report.reportID && report.lastReadTime)
      .sortBy('lastReadTime')
      .value();
      }

      to:

    function sortReportsByLastRead(reports) {
        return _.chain(reports)
    +        .map((report) => {
    +           const lastReadTime = lodashGet(report, 'lastVisitTime') || lodashGet(report, 'lastReadTime');
    +             return {...report, lastReadTime};
            })
            .toArray()
            .filter((report) => report && report.reportID && report.lastReadTime)
            .sortBy('lastReadTime')
            .value();
    }

    What alternative solutions did you explore? (Optional)

    • NA
  11. 59 remaining items

  12. removed
    Reviewing
    on Jan 2, 2024
  13. melvin-bot commented on Jan 2, 2024

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  14. melvin-bot commented on Jan 2, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.20-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2024-01-09. 🎊

    After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

    • External issue reporter
    • Contributor that fixed the issue
    • Contributor+ that helped on the issue and/or PR

    For reference, here are some details about the assignees on this issue:

  15. melvin-bot commented on Jan 2, 2024

    @melvin-bot

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@shubham1206agra] The PR that introduced the bug has been identified. Link to the PR:
    • [@shubham1206agra] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
    • [@shubham1206agra] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
    • [@shubham1206agra] Determine if we should create a regression test for this bug.
    • [@shubham1206agra] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • [@abekkala / @lschurr] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  16. lschurr commented on Jan 2, 2024

    @lschurr
    Contributor

    Leaving this with you @abekkala since I think you'll be back for the payout date!

  17. removed their assignment
    on Jan 2, 2024
  18. shubham1206agra commented on Jan 3, 2024

    @shubham1206agra
    Contributor

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@shubham1206agra] The PR that introduced the bug has been identified. Link to the PR: None as this is new functionality
    • [@shubham1206agra] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: NA
    • [@shubham1206agra] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: Not required
    • [@shubham1206agra] Determine if we should create a regression test for this bug. Yes
    • [@shubham1206agra] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    1. Navigate to a group conversation
    2. Clicking on a profile
    3. Refresh the page. Verify the background report opened is same as group conversation opened in step 1.
    • [@abekkala / @lschurr] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  19. added
    Daily
    and removed
    Weekly
    on Jan 9, 2024
  20. abekkala commented on Jan 9, 2024

    @abekkala
    Contributor

    @shubham1206agra I think we may need to get a bit more crisp on your regression test

    1. Navigate to a group conversation
    2. Clicking on a profile
    3. Refresh the page. Check the background report opened.

    Based on the OP

    Action Performed:

    1. Create a group conversation
    2. Type something
    3. Clicking on a profile
    4. Refresh the page

    Expected Result:

    The same group chat appears when refreshing the page

    in your regression would we need to type and/or send a message prior to clicking on a profile. After refreshing the page the last step should be "verifying" the correct result. Meaning, should it be "Verify the group chat still appears" rather than the issue of a different group chat appearing after refreshing the page

  21. shubham1206agra commented on Jan 10, 2024

    @shubham1206agra
    Contributor

    @abekkala Updated the test.

  22. abekkala commented on Jan 11, 2024

    @abekkala
    Contributor
    1. Navigate to a group conversation
    2. Click on a profile
    3. Refresh the page
    4. Verify the background report opened is same as group conversation opened in step 1.
  23. abekkala commented on Jan 11, 2024

    @abekkala
    Contributor

    @shubham1206agra payment sent and contract ended - thank you! 🎉

  24. abekkala commented on Jan 11, 2024

    @abekkala
    Contributor

    @DylanDylann payment sent and contract ended - thank you! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions