Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.36k stars 2.79k forks source link

Room-Removed members from room shown in search as removed without user id #49982

Open IuliiaHerets opened 2 hours ago

IuliiaHerets commented 2 hours ago

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: v9.0.41-2 Reproducible in staging?: Y Reproducible in production?: Y Issue reported by: Applause Internal Team

Action Performed:

  1. Launch app
  2. Create a room
  3. Tap header - members
  4. Invite 2 members and remove the members
  5. Create a room
  6. Tap header - members
  7. Invite 3 members and remove the members
  8. Navigate to LHN and tap search
  9. In the dropdown list, note the room chat and their removed message

Expected Result:

Removed members from room must be shown in search as removed with their user id.

Actual Result:

In search, room chat of 2 members and 3 members removed are shown as "removed and", "removed, , and".

Removed members from room are shown in search as removed Or with commas without user id.

Workaround:

Unknown

Platforms:

Screenshots/Videos

https://github.com/user-attachments/assets/7886a078-a8fc-46e1-a505-40b78fb6447d

View all open jobs on GitHub

melvin-bot[bot] commented 2 hours ago

Triggered auto assignment to @kadiealexander (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

bernhardoj commented 1 hour ago

Proposal

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

The removed member system message shown on the chat finder page doesn't show the user login.

What is the root cause of that problem?

That's how it's from the report lastMessageText.

image

But if we see the LHN, the last message says "removed 2 users", which is different from the chat finder page's last message text. This is because, for LHN, we handle manually the invite/remove case and construct a new message for it. https://github.com/Expensify/App/blob/c7ee85b2ea207159ef85932055aced28d5d2e29a/src/libs/SidebarUtils.ts#L410-L429

But for the chat finder page, we just show the report lastMessageText because we are not handling the invite/remove action. https://github.com/Expensify/App/blob/c7ee85b2ea207159ef85932055aced28d5d2e29a/src/libs/OptionsListUtils.ts#L612-L697

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

It's confusing to have 2 sources of truth of last message which works differently between LHN and chat finder page, but in this issue, we can just copy the logic from the SidebarUtils to OptionslistUtils.getLastMessageTextForReport.

} else if (ReportActionUtils.isInviteOrRemovedAction(lastReportAction)) {
    const participants = ReportUtils.getParticipantsAccountIDsForDisplay(report);
    const hasMultipleParticipants = participants.length > 1 || ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isExpenseReport(report);
    const lastActorDisplayName = getLastActorDisplayName(lastActorDetails, hasMultipleParticipants);
    const lastActionName = lastReportAction?.actionName ?? report?.lastActionType;
    const lastActionOriginalMessage = lastReportAction?.actionName ? ReportActionUtils.getOriginalMessage(lastReportAction) : null;
    const targetAccountIDs = lastActionOriginalMessage?.targetAccountIDs ?? [];
    const targetAccountIDsLength = targetAccountIDs.length !== 0 ? targetAccountIDs.length : report?.lastMessageHtml?.match(/<mention-user[^>]*><\/mention-user>/g)?.length ?? 0;
    const verb =
        lastActionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM || lastActionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.INVITE_TO_ROOM
            ? Localize.translate(preferredLocale, 'workspace.invite.invited')
            : Localize.translate(preferredLocale, 'workspace.invite.removed');
    const users = Localize.translate(preferredLocale, targetAccountIDsLength > 1 ? 'workspace.invite.users' : 'workspace.invite.user');
    let alternateText = ReportUtils.formatReportLastMessageText(`${lastActorDisplayName} ${verb} ${targetAccountIDsLength} ${users}`);

    const roomName = lastActionOriginalMessage?.roomName ?? '';
    if (roomName) {
        const preposition =
            lastReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM || lastReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.INVITE_TO_ROOM
                ? ` ${Localize.translate(preferredLocale, 'workspace.invite.to')}`
                : ` ${Localize.translate(preferredLocale, 'workspace.invite.from')}`;
        alternateText += `${preposition} ${roomName}`;
    }

    return alternateText;
}