Skip to content

Commit

Permalink
Merge pull request #43021 from nkdengineer/fix/40724
Browse files Browse the repository at this point in the history
Fix chat doesn't scroll to bottom
  • Loading branch information
mountiny authored Jun 10, 2024
2 parents b5693a6 + 9f7ea10 commit feba10e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ function getDBTime(timestamp: string | number = ''): string {
*/
function getDBTimeWithSkew(timestamp: string | number = ''): string {
if (networkTimeSkew > 0) {
return getDBTime(new Date(timestamp).valueOf() + networkTimeSkew);
const datetime = timestamp ? new Date(timestamp) : new Date();
return getDBTime(datetime.valueOf() + networkTimeSkew);
}
return getDBTime(timestamp);
}
Expand Down
5 changes: 4 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ function buildOnyxDataForMoneyRequest(
...iouReport,
lastMessageText: iouAction.message?.[0]?.text,
lastMessageHtml: iouAction.message?.[0]?.html,
lastVisibleActionCreated: iouAction.created,
pendingFields: {
...(shouldCreateNewMoneyRequestReport ? {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : {preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
},
Expand Down Expand Up @@ -1983,6 +1984,7 @@ function getMoneyRequestInformation(
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, false, comment, optimisticTransaction);
} else {
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction);
chatReport.lastVisibleActionCreated = reportPreviewAction.created;

// 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 @@ -3835,6 +3837,7 @@ function createSplitsAndOnyxData(
splitChatReport.lastMessageText = splitIOUReportAction.message?.[0]?.text;
splitChatReport.lastMessageHtml = splitIOUReportAction.message?.[0]?.html;
splitChatReport.lastActorAccountID = currentUserAccountID;
splitChatReport.lastVisibleActionCreated = splitIOUReportAction.created;

let splitChatReportNotificationPreference = splitChatReport.notificationPreference;
if (splitChatReportNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
Expand Down Expand Up @@ -4639,7 +4642,7 @@ function startSplitBill({
API.write(WRITE_COMMANDS.START_SPLIT_BILL, parameters, {optimisticData, successData, failureData});

Navigation.dismissModalWithReport(splitChatReport);
Report.notifyNewAction(splitChatReport.chatReportID ?? '', currentUserAccountID);
Report.notifyNewAction(splitChatReport.reportID ?? '', currentUserAccountID);
}

/** Used for editing a split expense while it's still scanning or when SmartScan fails, it completes a split expense started by startSplitBill above.
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ function addActions(reportID: string, text = '', file?: FileObject) {
const lastCommentText = ReportUtils.formatReportLastMessageText(lastComment?.text ?? '');

const optimisticReport: Partial<Report> = {
lastVisibleActionCreated: currentTime,
lastVisibleActionCreated: lastAction?.created,
lastMessageTranslationKey: lastComment?.translationKey ?? '',
lastMessageText: lastCommentText,
lastMessageHtml: lastCommentText,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ function createTaskAndNavigate(
const optimisticAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(taskReportID, title, assigneeAccountID, `task for ${title}`, parentReportID);
optimisticTaskReport.parentReportActionID = optimisticAddCommentReport.reportAction.reportActionID;

const currentTime = DateUtils.getDBTime();
const currentTime = DateUtils.getDBTimeWithSkew();
const lastCommentText = ReportUtils.formatReportLastMessageText(optimisticAddCommentReport?.reportAction?.message?.[0]?.text ?? '');
const optimisticParentReport = {
lastVisibleActionCreated: currentTime,
lastVisibleActionCreated: optimisticAddCommentReport.reportAction.created,
lastMessageText: lastCommentText,
lastActorAccountID: currentUserAccountID,
lastReadTime: currentTime,
Expand Down
5 changes: 1 addition & 4 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,9 @@ function ReportActionsList({
[sortedReportActions, isOffline],
);

// whisper action doesn't affect lastVisibleActionCreated, so we should not take it into account while checking if there is the newest report action
const newestVisibleReportAction = useMemo(() => sortedVisibleReportActions.find((item) => !ReportActionsUtils.isWhisperAction(item)) ?? null, [sortedVisibleReportActions]);

const lastActionIndex = sortedVisibleReportActions[0]?.reportActionID;
const reportActionSize = useRef(sortedVisibleReportActions.length);
const hasNewestReportAction = newestVisibleReportAction?.created === report.lastVisibleActionCreated;
const hasNewestReportAction = sortedVisibleReportActions[0]?.created === report.lastVisibleActionCreated;
const hasNewestReportActionRef = useRef(hasNewestReportAction);
hasNewestReportActionRef.current = hasNewestReportAction;
const previousLastIndex = useRef(lastActionIndex);
Expand Down

0 comments on commit feba10e

Please sign in to comment.