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

Allow optimistic assignee chat reports #22778

Merged
merged 49 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0ce8bec
Update the comments / remove the call to openReport when we select an…
thienlnam Jul 12, 2023
159f0c4
Update to chatReport
thienlnam Jul 12, 2023
34f32da
Clean up / add comments
thienlnam Jul 12, 2023
420084c
add optimistic onyx data for optimistic chat with assignee
thienlnam Jul 12, 2023
b9c4c71
Hook up CreateTask
thienlnam Jul 12, 2023
d874a0d
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Jul 12, 2023
c748622
make sure we grab the shareDestination
thienlnam Jul 12, 2023
2e2ee21
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Jul 13, 2023
c91a06e
Add hidden reports
thienlnam Jul 14, 2023
9528ad3
reorder quite a bit of logic
thienlnam Jul 15, 2023
5bc6757
prettier
thienlnam Jul 15, 2023
ec76615
comments and logic
thienlnam Jul 15, 2023
ac382ea
Update Task.js
thienlnam Jul 15, 2023
16dab5d
move storing personal details when you select a user
thienlnam Jul 17, 2023
b8bc106
fix the prop issue
thienlnam Jul 17, 2023
6a057fe
move back into assignee selector
thienlnam Jul 17, 2023
4f3587f
add failure data
thienlnam Jul 17, 2023
1b05d7d
Set the message
thienlnam Jul 17, 2023
edaf71d
remove logs / prettify
thienlnam Jul 17, 2023
b37174a
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Jul 24, 2023
ce262d8
clean up the logic / add more comments
thienlnam Jul 25, 2023
186221c
remove setting the text
thienlnam Jul 25, 2023
059737e
Fix issue with new created
thienlnam Jul 25, 2023
4cb65bc
remove clearing the optimistic personal details
thienlnam Jul 25, 2023
9f9dd5a
prettier
thienlnam Jul 25, 2023
6ed2ce5
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Jul 25, 2023
2c7e987
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Jul 25, 2023
ff58271
Fix is hidden
thienlnam Jul 25, 2023
32d9210
dry up the logic and use in EditTask
thienlnam Jul 25, 2023
a7ef027
Update Task.js
thienlnam Jul 25, 2023
de23dd7
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Jul 26, 2023
913563b
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Jul 26, 2023
5bf328c
return chatReport for EditTask
thienlnam Jul 27, 2023
7776ddc
Prettier
thienlnam Jul 27, 2023
55dea0a
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Jul 31, 2023
3451c38
JSDoc review comments
thienlnam Jul 31, 2023
6e5b6e7
Use getChatByParticipantsByLoginList
thienlnam Jul 31, 2023
b50ef1e
clean up
thienlnam Jul 31, 2023
2b2a9e4
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Aug 1, 2023
33e59da
remove editedTask
thienlnam Aug 1, 2023
c15afc2
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Aug 1, 2023
002fa5d
fallback to assigneeAccountID
thienlnam Aug 1, 2023
11c5b3e
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Aug 2, 2023
ed690eb
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Aug 2, 2023
92499de
Start using EditTaskAssignee
thienlnam Aug 2, 2023
e04be56
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Aug 8, 2023
a884a43
Update TaskAssigneeSelectorModal.js
thienlnam Aug 9, 2023
14afc1b
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Aug 10, 2023
62e2eb1
Merge branch 'main' into jack-allowOptimisticAssignee
thienlnam Aug 11, 2023
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
119 changes: 119 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,7 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep
if (
!report ||
!report.reportID ||
report.isHidden ||
(_.isEmpty(report.participantAccountIDs) && !isChatThread(report) && !isPublicRoom(report) && !isArchivedRoom(report) && !isMoneyRequestReport(report) && !isTaskReport(report))
) {
return false;
Expand Down Expand Up @@ -2903,6 +2904,123 @@ function shouldDisableRename(report, policy) {
return !_.keys(loginList).includes(policy.owner) && policy.role !== CONST.POLICY.ROLE.ADMIN;
}

/**
* Returns the onyx data needed for the task assignee chat
* @param {Number} accountID
* @param {String} assigneeEmail
* @param {Number} assigneeAccountID
* @param {String} taskReportID
* @param {String} assigneeChatReportID
* @param {String} parentReportID
* @param {String} title
* @param {Object} assigneeChatReport
* @returns {Object}
*/
function getTaskAssigneeChatOnyxData(accountID, assigneeEmail, assigneeAccountID, taskReportID, assigneeChatReportID, parentReportID, title, assigneeChatReport) {
// Set if we need to add a comment to the assignee chat notifying them that they have been assigned a task
let optimisticAssigneeAddComment;
// Set if this is a new chat that needs to be created for the assignee
let optimisticChatCreatedReportAction;
const currentTime = DateUtils.getDBTime();
const optimisticData = [];
const successData = [];
const failureData = [];

// You're able to assign a task to someone you haven't chatted with before - so we need to optimistically create the chat and the chat reportActions
// Only add the assignee chat report to onyx if we haven't already set it optimistically
if (assigneeChatReport.isOptimisticReport && lodashGet(assigneeChatReport, 'pendingFields.createChat') !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
optimisticChatCreatedReportAction = buildOptimisticCreatedReportAction(assigneeChatReportID);
optimisticData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${assigneeChatReportID}`,
value: {
pendingFields: {
createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
isHidden: false,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`,
value: {[optimisticChatCreatedReportAction.reportActionID]: optimisticChatCreatedReportAction},
},
);

successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${assigneeChatReportID}`,
value: {
pendingFields: {
createChat: null,
},
isOptimisticReport: false,
},
});

failureData.push(
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${assigneeChatReportID}`,
value: null,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`,
value: {[optimisticChatCreatedReportAction.reportActionID]: {pendingAction: null}},
},
// If we failed, we want to remove the optimistic personal details as it was likely due to an invalid login
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[assigneeAccountID]: null,
},
},
);
}

// If you're choosing to share the task in the same DM as the assignee then we don't need to create another reportAction indicating that you've been assigned
if (assigneeChatReportID !== parentReportID) {
optimisticAssigneeAddComment = buildOptimisticTaskCommentReportAction(taskReportID, title, assigneeEmail, assigneeAccountID, `Assigned a task to you: ${title}`, parentReportID);

const lastAssigneeCommentText = formatReportLastMessageText(optimisticAssigneeAddComment.reportAction.message[0].text);
const optimisticAssigneeReport = {
lastVisibleActionCreated: currentTime,
lastMessageText: lastAssigneeCommentText,
lastActorAccountID: accountID,
lastReadTime: currentTime,
};

optimisticData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`,
value: {[optimisticAssigneeAddComment.reportAction.reportActionID]: optimisticAssigneeAddComment.reportAction},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${assigneeChatReportID}`,
value: optimisticAssigneeReport,
},
);
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`,
value: {[optimisticAssigneeAddComment.reportAction.reportActionID]: {pendingAction: null}},
});
}

return {
optimisticData,
successData,
failureData,
optimisticAssigneeAddComment,
optimisticChatCreatedReportAction,
};
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -3024,4 +3142,5 @@ export {
shouldDisableSettings,
shouldDisableRename,
hasSingleParticipant,
getTaskAssigneeChatOnyxData,
};
Loading
Loading