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

Expense chat doesn't scroll to bottom when send message or money request #42030

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function BaseInvertedFlatList<T>(props: BaseInvertedFlatListProps<T>, ref: Forwa

if (shouldEnableAutoScrollToTopThreshold) {
config.autoscrollToTopThreshold = AUTOSCROLL_TO_TOP_THRESHOLD;
} else {
config.autoscrollToTopThreshold = 0;
}

return config;
Expand Down
13 changes: 10 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3425,6 +3425,7 @@ function buildOptimisticAddCommentReportAction(
createdOffset = 0,
shouldEscapeText?: boolean,
reportID?: string,
currentTime?: string,
): OptimisticReportAction {
const parser = new ExpensiMark();
const commentText = getParsedComment(text ?? '', {shouldEscapeText, reportID});
Expand Down Expand Up @@ -3464,7 +3465,7 @@ function buildOptimisticAddCommentReportAction(
],
automatic: false,
avatar: allPersonalDetails?.[accountID ?? -1]?.avatar ?? UserUtils.getDefaultAvatarURL(accountID),
created: DateUtils.getDBTimeWithSkew(Date.now() + createdOffset),
created: currentTime ?? DateUtils.getDBTimeWithSkew(Date.now() + createdOffset),
message: [
{
translationKey: isAttachmentOnly ? CONST.TRANSLATION_KEYS.ATTACHMENT : '',
Expand Down Expand Up @@ -4072,11 +4073,17 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string,
* @param [comment] - User comment for the IOU.
* @param [transaction] - optimistic first transaction of preview
*/
function buildOptimisticReportPreview(chatReport: OnyxEntry<Report>, iouReport: Report, comment = '', transaction: OnyxEntry<Transaction> = null, childReportID?: string): ReportAction {
function buildOptimisticReportPreview(
chatReport: OnyxEntry<Report>,
iouReport: Report,
comment = '',
transaction: OnyxEntry<Transaction> = null,
childReportID?: string,
created = DateUtils.getDBTime(),
): ReportAction {
const hasReceipt = TransactionUtils.hasReceipt(transaction);
const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction);
const message = getReportPreviewMessage(iouReport);
const created = DateUtils.getDBTime();
return {
reportActionID: NumberUtils.rand64(),
reportID: chatReport?.reportID,
Expand Down
19 changes: 13 additions & 6 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1801,11 +1801,14 @@ function getMoneyRequestInformation(
const payerEmail = PhoneNumber.addSMSDomainIfPhoneNumber(participant.login ?? '');
const payerAccountID = Number(participant.accountID);
const isPolicyExpenseChat = participant.isPolicyExpenseChat;
const currentTime = DateUtils.getDBTime();

// STEP 1: Get existing chat report OR build a new optimistic one
let isNewChatReport = false;
let chatReport = !isEmptyObject(parentChatReport) && parentChatReport?.reportID ? parentChatReport : null;

if (chatReport) {
chatReport.lastVisibleActionCreated = currentTime;
}
// If this is a policyExpenseChat, the chatReport must exist and we can get it from Onyx.
// report is null if the flow is initiated from the global create menu. However, participant always stores the reportID if it exists, which is the case for policyExpenseChats
if (!chatReport && isPolicyExpenseChat) {
Expand Down Expand Up @@ -1920,7 +1923,7 @@ function getMoneyRequestInformation(
if (reportPreviewAction) {
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, false, comment, optimisticTransaction);
} else {
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction);
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction, '', currentTime);

// Generated ReportPreview action is a parent report action of the iou report.
// We are setting the iou report's parentReportActionID to display subtitle correctly in IOU page when offline.
Expand Down Expand Up @@ -3767,11 +3770,13 @@ function createSplitsAndOnyxData(
{},
isOwnPolicyExpenseChat,
);

splitChatReport.lastReadTime = DateUtils.getDBTime();
const currentTime = DateUtils.getDBTime();
splitChatReport.lastReadTime = currentTime;
splitChatReport.lastMessageText = splitIOUReportAction.message?.[0]?.text;
splitChatReport.lastMessageHtml = splitIOUReportAction.message?.[0]?.html;
splitChatReport.lastActorAccountID = currentUserAccountID;
splitChatReport.lastVisibleActionCreated = currentTime;
splitIOUReportAction.created = currentTime;

let splitChatReportNotificationPreference = splitChatReport.notificationPreference;
if (splitChatReportNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
Expand Down Expand Up @@ -4327,10 +4332,12 @@ function startSplitBill({
receiptObject,
isOwnPolicyExpenseChat,
);

splitChatReport.lastReadTime = DateUtils.getDBTime();
const currentTime = DateUtils.getDBTime();
splitChatReport.lastReadTime = currentTime;
splitChatReport.lastMessageText = splitIOUReportAction.message?.[0]?.text;
splitChatReport.lastMessageHtml = splitIOUReportAction.message?.[0]?.html;
splitChatReport.lastVisibleActionCreated = currentTime;
splitIOUReportAction.created = currentTime;

// If we have an existing splitChatReport (group chat or workspace) use it's pending fields, otherwise indicate that we are adding a chat
if (!existingSplitChatReport) {
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,10 @@ function addActions(reportID: string, text = '', file?: FileObject) {
let attachmentAction: OptimisticAddCommentReportAction | undefined;
let commandName: typeof WRITE_COMMANDS.ADD_COMMENT | typeof WRITE_COMMANDS.ADD_ATTACHMENT | typeof WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT = WRITE_COMMANDS.ADD_COMMENT;

const currentTime = DateUtils.getDBTimeWithSkew();

if (text && !file) {
const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(text, undefined, undefined, undefined, undefined, reportID);
const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(text, undefined, undefined, undefined, undefined, reportID, currentTime);
reportCommentAction = reportComment.reportAction;
reportCommentText = reportComment.commentText;
}
Expand All @@ -475,7 +477,6 @@ function addActions(reportID: string, text = '', file?: FileObject) {

// Always prefer the file as the last action over text
const lastAction = attachmentAction ?? reportCommentAction;
const currentTime = DateUtils.getDBTimeWithSkew();
const lastComment = lastAction?.message?.[0];
const lastCommentText = ReportUtils.formatReportLastMessageText(lastComment?.text ?? '');

Expand Down
Loading