Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MonilBhavsar committed Aug 15, 2023
1 parent f6bd06a commit 5d3edd4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import * as OptionsListUtils from '../OptionsListUtils';
import * as Environment from '../Environment/Environment';

let currentUserAccountID;

Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
Expand Down
14 changes: 7 additions & 7 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ function keyExtractor(item) {
return item.reportActionID;
}

function isUnreadMsg(message, lastRead) {
return message && lastRead && message.created && lastRead < message.created;
function isMessageUnread(message, lastReadTime) {
return Boolean(message && lastReadTime && message.created && lastReadTime < message.created);
}

function ReportActionsList({
Expand All @@ -113,6 +113,7 @@ function ReportActionsList({
const scrollingVerticalOffset = useRef(0);
const readActionSkipped = useRef(false);
const reportActionSize = useRef(sortedReportActions.length);

// Considering that renderItem is enclosed within a useCallback, marking it as "read" twice will retain the value as "true," preventing the useCallback from re-executing.
// However, if we create and listen to an object, it will lead to a new useCallback execution.
const [messageManuallyMarked, setMessageManuallyMarked] = useState({read: false});
Expand All @@ -128,8 +129,8 @@ function ReportActionsList({

useEffect(() => {
// If the reportID changes, we reset the userActiveSince to null, we need to do it because
// the parent component is sending the previous reportID even when the user isn't activily
// into the report
// the parent component is sending the previous reportID even when the user isn't active
// on the report
if (userActiveSince.current && prevReportID && prevReportID !== report.reportID) {
userActiveSince.current = null;
} else {
Expand Down Expand Up @@ -162,7 +163,6 @@ function ReportActionsList({

useEffect(() => {
const didManuallyMarkReportAsUnread = report.lastReadTime < DateUtils.getDBTime() && ReportUtils.isUnread(report);

if (!didManuallyMarkReportAsUnread) {
setMessageManuallyMarked({read: false});
return;
Expand Down Expand Up @@ -227,8 +227,8 @@ function ReportActionsList({

if (!currentUnreadMarker.current) {
const nextMessage = sortedReportActions[index + 1];
const isCurrentMessageUnread = !!isUnreadMsg(reportAction, report.lastReadTime);
shouldDisplayNewMarker = isCurrentMessageUnread && !isUnreadMsg(nextMessage, report.lastReadTime);
const isCurrentMessageUnread = isMessageUnread(reportAction, report.lastReadTime);
shouldDisplayNewMarker = isCurrentMessageUnread && !isMessageUnread(nextMessage, report.lastReadTime);

if (!messageManuallyMarked.read) {
shouldDisplayNewMarker = shouldDisplayNewMarker && reportAction.actorAccountID !== Report.getCurrentUserAccountID();
Expand Down
1 change: 0 additions & 1 deletion tests/actions/ReportTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ describe('actions/Report', () => {
.then(() => {
// The report will be read
expect(ReportUtils.isUnread(report)).toBe(false);

expect(moment.utc(report.lastReadTime).valueOf()).toBeGreaterThanOrEqual(moment.utc(currentTime).valueOf());

// And no longer show the green dot for unread mentions in the LHN
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/UnreadIndicatorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ describe('Unread Indicators', () => {
return waitFor(() => expect(isNewMessagesBadgeVisible()).toBe(false));
}));

it('Keeps showing the new line indicator when a new message is created by the current user', () =>
it('Keep showing the new line indicator when a new message is created by the current user', () =>
signInAndGetAppWithUnreadChat()
.then(() => {
// Verify we are on the LHN and that the chat shows as unread in the LHN
Expand Down

0 comments on commit 5d3edd4

Please sign in to comment.