Skip to content
Merged
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
8 changes: 6 additions & 2 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as Localize from '../Localize';
import PusherUtils from '../PusherUtils';
import DateUtils from '../DateUtils';
import * as ReportActionsUtils from '../ReportActionsUtils';
import * as NumberUtils from '../NumberUtils';

let currentUserEmail;
let currentUserAccountID;
Expand Down Expand Up @@ -753,6 +754,7 @@ function buildOptimisticReportAction(reportID, text, file) {
return {
commentText,
reportAction: {
reportActionID: NumberUtils.rand64(),
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
actorEmail: currentUserEmail,
actorAccountID: currentUserAccountID,
Expand Down Expand Up @@ -838,14 +840,16 @@ function addActions(reportID, text = '', file) {
// Optimistically add the new actions to the store before waiting to save them to the server
const optimisticReportActions = {};
if (text) {
optimisticReportActions[reportCommentAction.clientID] = reportCommentAction;
optimisticReportActions[reportCommentAction.sequenceNumber] = reportCommentAction;
}
if (file) {
optimisticReportActions[attachmentAction.clientID] = attachmentAction;
optimisticReportActions[attachmentAction.sequenceNumber] = attachmentAction;
}

const parameters = {
reportID,
reportActionID: file ? attachmentAction.reportActionID : reportCommentAction.reportActionID,
commentReportActionID: file && reportCommentAction ? reportCommentAction.reportActionID : null,
reportComment: reportCommentText,
clientID: lastAction.clientID,
commentClientID: lodashGet(reportCommentAction, 'clientID', ''),
Expand Down
8 changes: 4 additions & 4 deletions src/libs/actions/ReportActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ function isFromCurrentUser(reportID, sequenceNumber, currentUserAccountID, actio

/**
* @param {Number} reportID
* @param {String} clientID
* @param {String} sequenceNumber
*/
function deleteClientAction(reportID, clientID) {
function deleteOptimisticReportAction(reportID, sequenceNumber) {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {
[clientID]: null,
[sequenceNumber]: null,
});
}

export {
getDeletedCommentsCount,
getLastVisibleMessageText,
isFromCurrentUser,
deleteClientAction,
deleteOptimisticReportAction,
};
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ReportActionItem extends Component {
)}
>
<OfflineWithFeedback
onClose={() => ReportActions.deleteClientAction(this.props.report.reportID, this.props.action.clientID)}
onClose={() => ReportActions.deleteOptimisticReportAction(this.props.report.reportID, this.props.action.sequenceNumber)}
pendingAction={this.props.action.pendingAction}
errors={this.props.action.errors}
errorRowStyles={[styles.ml10, styles.mr2]}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ class ReportActionsList extends React.Component {

/**
* Create a unique key for Each Action in the FlatList.
* We use a combination of sequenceNumber and clientID in case the clientID are the same - which
* shouldn't happen, but might be possible in some rare cases.
* We use the reportActionId that is a string representation of a random 64-bit int, which should be
* random enought to avoid colisions
* @param {Object} item
* @return {String}
*/
keyExtractor(item) {
return `${item.action.sequenceNumber}${item.action.clientID}`;
return `${item.action.reportActionID}`;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions tests/actions/ReportTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('actions/Report', () => {
callback: val => reportActions = val,
});

let clientID;
let sequenceNumber;

// Set up Onyx with some test user data
return TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN)
Expand All @@ -91,8 +91,8 @@ describe('actions/Report', () => {
.then(() => {
const resultAction = _.first(_.values(reportActions));

// Store the generated clientID so that we can send it with our mock Pusher update
clientID = resultAction.sequenceNumber;
// Store the generated sequenceNumber so that we can send it with our mock Pusher update
sequenceNumber = resultAction.sequenceNumber;
expect(resultAction.message).toEqual(REPORT_ACTION.message);
expect(resultAction.person).toEqual(REPORT_ACTION.person);
expect(resultAction.pendingAction).toEqual(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
Expand All @@ -119,7 +119,7 @@ describe('actions/Report', () => {
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`,
value: {
[clientID]: null,
[sequenceNumber]: null,
[ACTION_ID]: actionWithoutLoading,
},
},
Expand Down Expand Up @@ -349,9 +349,9 @@ describe('actions/Report', () => {
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`,
value: {
[_.toArray(reportActions)[1].clientID]: null,
[_.toArray(reportActions)[2].clientID]: null,
[_.toArray(reportActions)[3].clientID]: null,
[_.toArray(reportActions)[1].sequenceNumber]: null,
[_.toArray(reportActions)[2].sequenceNumber]: null,
[_.toArray(reportActions)[3].sequenceNumber]: null,
2: {
...USER_1_BASE_ACTION,
message: [{type: 'COMMENT', html: 'Current User Comment 1', text: 'Current User Comment 1'}],
Expand Down