-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Migrate notification preference #47577
Merged
puneetlath
merged 23 commits into
Expensify:main
from
shubham1206agra:migrate-notification-preference
Sep 7, 2024
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4c41990
Migrating notification preference into participants
shubham1206agra 8504a1d
fix/tests
ishpaul777 4d34462
FIXES MORE TESTS
ishpaul777 49b79ca
Merge pull request #4 from ishpaul777/fix/ioutest
shubham1206agra 24fe828
Apply suggestions from code review
shubham1206agra cc71ee5
Fix lint
shubham1206agra 3aba64b
Apply suggestions from code review
shubham1206agra 6967e8d
Fix lint
shubham1206agra cf6ab27
Fix jest test
shubham1206agra 7733be8
Fix jest test
shubham1206agra ade6683
Merge branch 'Expensify:main' into migrate-notification-preference
shubham1206agra b8d8979
Apply suggestions from code review
shubham1206agra 8fe8e83
Fix ts
shubham1206agra aae2e2e
Merge branch 'main' into migrate-notification-preference
shubham1206agra f8d3e1f
Merge branch 'main' into migrate-notification-preference
shubham1206agra ce2fc9c
Merge branch 'main' into migrate-notification-preference
shubham1206agra fb066c1
Fix lint
shubham1206agra dbbf085
Fixed some optimistic cases
shubham1206agra ddb38a0
Fixed some more optimistic cases
shubham1206agra 292d348
Merge branch 'Expensify:main' into migrate-notification-preference
shubham1206agra ad7911f
Merge branch 'main' into migrate-notification-preference
shubham1206agra 152e09a
Fix test
shubham1206agra 26f8695
Fixed jest tests
shubham1206agra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -155,10 +155,10 @@ type OptimisticExpenseReport = Pick< | |||||
| 'statusNum' | ||||||
| 'total' | ||||||
| 'nonReimbursableTotal' | ||||||
| 'notificationPreference' | ||||||
| 'parentReportID' | ||||||
| 'lastVisibleActionCreated' | ||||||
| 'parentReportActionID' | ||||||
| 'participants' | ||||||
| 'fieldList' | ||||||
>; | ||||||
|
||||||
|
@@ -275,7 +275,6 @@ type OptimisticChatReport = Pick< | |||||
| 'lastMessageText' | ||||||
| 'lastReadTime' | ||||||
| 'lastVisibleActionCreated' | ||||||
| 'notificationPreference' | ||||||
| 'oldPolicyName' | ||||||
| 'ownerAccountID' | ||||||
| 'pendingFields' | ||||||
|
@@ -356,7 +355,6 @@ type OptimisticTaskReport = Pick< | |||||
| 'policyID' | ||||||
| 'stateNum' | ||||||
| 'statusNum' | ||||||
| 'notificationPreference' | ||||||
| 'parentReportActionID' | ||||||
| 'lastVisibleActionCreated' | ||||||
| 'hasParentAccess' | ||||||
|
@@ -396,7 +394,6 @@ type OptimisticIOUReport = Pick< | |||||
| 'statusNum' | ||||||
| 'total' | ||||||
| 'reportName' | ||||||
| 'notificationPreference' | ||||||
| 'parentReportID' | ||||||
| 'lastVisibleActionCreated' | ||||||
| 'fieldList' | ||||||
|
@@ -1148,6 +1145,32 @@ function isSystemChat(report: OnyxEntry<Report>): boolean { | |||||
return getChatType(report) === CONST.REPORT.CHAT_TYPE.SYSTEM; | ||||||
} | ||||||
|
||||||
function getDefaultNotificationPreferenceForReport(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE> { | ||||||
if (isAnnounceRoom(report)) { | ||||||
return CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS; | ||||||
} | ||||||
if (isPublicRoom(report)) { | ||||||
return CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY; | ||||||
} | ||||||
if (!getChatType(report) || isGroupChat(report)) { | ||||||
return CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS; | ||||||
} | ||||||
if (isAdminRoom(report) || isPolicyExpenseChat(report) || isInvoiceRoom(report)) { | ||||||
return CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS; | ||||||
} | ||||||
if (isSelfDM(report)) { | ||||||
return CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE; | ||||||
} | ||||||
return CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY; | ||||||
} | ||||||
shubham1206agra marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
/** | ||||||
* Get the notification preference given a report | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB but I think this is a bit more clear. |
||||||
*/ | ||||||
function getReportNotificationPreference(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE> { | ||||||
return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report); | ||||||
} | ||||||
|
||||||
const CONCIERGE_ACCOUNT_ID_STRING = CONST.ACCOUNT_ID.CONCIERGE.toString(); | ||||||
/** | ||||||
* Only returns true if this is our main 1:1 DM report with Concierge. | ||||||
|
@@ -1253,7 +1276,7 @@ function hasExpensifyGuidesEmails(accountIDs: number[]): boolean { | |||||
|
||||||
function getMostRecentlyVisitedReport(reports: Array<OnyxEntry<Report>>, reportMetadata: OnyxCollection<ReportMetadata>): OnyxEntry<Report> { | ||||||
const filteredReports = reports.filter((report) => { | ||||||
const shouldKeep = !isChatThread(report) || report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; | ||||||
const shouldKeep = !isChatThread(report) || getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; | ||||||
return shouldKeep && !!report?.reportID && !!(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime); | ||||||
}); | ||||||
return lodashMaxBy(filteredReports, (a) => new Date(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a?.reportID}`]?.lastVisitTime ?? a?.lastReadTime ?? '').valueOf()); | ||||||
|
@@ -1623,13 +1646,6 @@ function isPayer(session: OnyxEntry<Session>, iouReport: OnyxEntry<Report>) { | |||||
return isAdmin || (isMoneyRequestReport(iouReport) && isManager); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Get the notification preference given a report | ||||||
*/ | ||||||
function getReportNotificationPreference(report: OnyxEntry<Report>): string | number { | ||||||
return report?.notificationPreference ?? ''; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Checks if the current user is the action's author | ||||||
*/ | ||||||
|
@@ -2064,7 +2080,7 @@ function getParticipantsAccountIDsForDisplay(report: OnyxEntry<Report>, shouldEx | |||||
return false; | ||||||
} | ||||||
|
||||||
if (shouldExcludeHidden && reportParticipants[accountID]?.hidden) { | ||||||
if (shouldExcludeHidden && reportParticipants[accountID]?.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { | ||||||
return false; | ||||||
} | ||||||
|
||||||
|
@@ -2117,7 +2133,7 @@ function buildParticipantsFromAccountIDs(accountIDs: number[]): Participants { | |||||
const finalParticipants: Participants = {}; | ||||||
return accountIDs.reduce((participants, accountID) => { | ||||||
// eslint-disable-next-line no-param-reassign | ||||||
participants[accountID] = {hidden: false}; | ||||||
participants[accountID] = {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}; | ||||||
return participants; | ||||||
}, finalParticipants); | ||||||
} | ||||||
|
@@ -4240,8 +4256,8 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number | |||||
const policy = getPolicy(policyID); | ||||||
|
||||||
const participants: Participants = { | ||||||
[payeeAccountID]: {hidden: true}, | ||||||
[payerAccountID]: {hidden: true}, | ||||||
[payeeAccountID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN}, | ||||||
[payerAccountID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN}, | ||||||
}; | ||||||
|
||||||
return { | ||||||
|
@@ -4259,7 +4275,6 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number | |||||
|
||||||
// We don't translate reportName because the server response is always in English | ||||||
reportName: `${payerEmail} owes ${formattedTotal}`, | ||||||
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, | ||||||
parentReportID: chatReportID, | ||||||
lastVisibleActionCreated: DateUtils.getDBTime(), | ||||||
fieldList: policy?.fieldList, | ||||||
|
@@ -4314,7 +4329,11 @@ function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, re | |||||
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, | ||||||
statusNum: CONST.REPORT.STATUS_NUM.OPEN, | ||||||
total, | ||||||
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, | ||||||
participants: { | ||||||
[currentUserAccountID ?? -1]: { | ||||||
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, | ||||||
}, | ||||||
}, | ||||||
shubham1206agra marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
parentReportID: chatReportID, | ||||||
lastVisibleActionCreated: DateUtils.getDBTime(), | ||||||
}; | ||||||
|
@@ -4364,7 +4383,11 @@ function buildOptimisticExpenseReport( | |||||
statusNum, | ||||||
total: storedTotal, | ||||||
nonReimbursableTotal: reimbursable ? 0 : storedTotal, | ||||||
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, | ||||||
participants: { | ||||||
[payeeAccountID]: { | ||||||
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, | ||||||
}, | ||||||
}, | ||||||
parentReportID: chatReportID, | ||||||
lastVisibleActionCreated: DateUtils.getDBTime(), | ||||||
parentReportActionID, | ||||||
|
@@ -5005,12 +5028,11 @@ function buildOptimisticChatReport( | |||||
description = '', | ||||||
avatarUrl = '', | ||||||
optimisticReportID = '', | ||||||
shouldShowParticipants = true, | ||||||
): OptimisticChatReport { | ||||||
const isWorkspaceChatType = chatType && isWorkspaceChat(chatType); | ||||||
const participants = participantList.reduce((reportParticipants: Participants, accountID: number) => { | ||||||
const participant: ReportParticipant = { | ||||||
hidden: !shouldShowParticipants, | ||||||
notificationPreference, | ||||||
shubham1206agra marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
...(!isWorkspaceChatType && {role: accountID === currentUserAccountID ? CONST.REPORT.ROLE.ADMIN : CONST.REPORT.ROLE.MEMBER}), | ||||||
}; | ||||||
// eslint-disable-next-line no-param-reassign | ||||||
|
@@ -5031,7 +5053,6 @@ function buildOptimisticChatReport( | |||||
lastMessageText: undefined, | ||||||
lastReadTime: currentTime, | ||||||
lastVisibleActionCreated: currentTime, | ||||||
notificationPreference, | ||||||
oldPolicyName, | ||||||
ownerAccountID: ownerAccountID || CONST.REPORT.OWNER_ACCOUNT_ID_FAKE, | ||||||
parentReportActionID, | ||||||
|
@@ -5449,9 +5470,7 @@ function buildOptimisticWorkspaceChats(policyID: string, policyName: string, exp | |||||
policyName, | ||||||
undefined, | ||||||
undefined, | ||||||
|
||||||
// #announce contains all policy members so notifying always should be opt-in only. | ||||||
CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY, | ||||||
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, | ||||||
); | ||||||
const announceChatReportID = announceChatData.reportID; | ||||||
const announceCreatedAction = buildOptimisticCreatedReportAction(CONST.POLICY.OWNER_EMAIL_FAKE); | ||||||
|
@@ -5538,12 +5557,12 @@ function buildOptimisticTaskReport( | |||||
): OptimisticTaskReport { | ||||||
const participants: Participants = { | ||||||
[ownerAccountID]: { | ||||||
hidden: false, | ||||||
notificationPreference, | ||||||
shubham1206agra marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}, | ||||||
}; | ||||||
|
||||||
if (assigneeAccountID) { | ||||||
participants[assigneeAccountID] = {hidden: false}; | ||||||
participants[assigneeAccountID] = {notificationPreference}; | ||||||
} | ||||||
|
||||||
return { | ||||||
|
@@ -5558,7 +5577,6 @@ function buildOptimisticTaskReport( | |||||
policyID, | ||||||
stateNum: CONST.REPORT.STATE_NUM.OPEN, | ||||||
statusNum: CONST.REPORT.STATUS_NUM.OPEN, | ||||||
notificationPreference, | ||||||
lastVisibleActionCreated: DateUtils.getDBTime(), | ||||||
hasParentAccess: true, | ||||||
}; | ||||||
|
@@ -5636,10 +5654,6 @@ function buildTransactionThread( | |||||
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, | ||||||
reportAction?.reportActionID, | ||||||
moneyRequestReport?.reportID, | ||||||
'', | ||||||
'', | ||||||
'', | ||||||
false, | ||||||
); | ||||||
} | ||||||
|
||||||
|
@@ -6013,7 +6027,7 @@ function shouldReportBeInOptionList({ | |||||
|
||||||
// All unread chats (even archived ones) in GSD mode will be shown. This is because GSD mode is specifically for focusing the user on the most relevant chats, primarily, the unread ones | ||||||
if (isInFocusMode) { | ||||||
return isUnread(report) && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE; | ||||||
return isUnread(report) && getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE; | ||||||
} | ||||||
|
||||||
// Archived reports should always be shown when in default (most recent) mode. This is because you should still be able to access and search for the chats to find them. | ||||||
|
@@ -7405,15 +7419,15 @@ function isAdminOwnerApproverOrReportOwner(report: OnyxEntry<Report>, policy: On | |||||
/** | ||||||
* Whether the user can join a report | ||||||
*/ | ||||||
function canJoinChat(report: OnyxInputOrEntry<Report>, parentReportAction: OnyxInputOrEntry<ReportAction>, policy: OnyxInputOrEntry<Policy>): boolean { | ||||||
function canJoinChat(report: OnyxEntry<Report>, parentReportAction: OnyxInputOrEntry<ReportAction>, policy: OnyxInputOrEntry<Policy>): boolean { | ||||||
// We disabled thread functions for whisper action | ||||||
// So we should not show join option for existing thread on whisper message that has already been left, or manually leave it | ||||||
if (ReportActionsUtils.isWhisperAction(parentReportAction)) { | ||||||
return false; | ||||||
} | ||||||
|
||||||
// If the notification preference of the chat is not hidden that means we have already joined the chat | ||||||
if (report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { | ||||||
if (getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { | ||||||
return false; | ||||||
} | ||||||
|
||||||
|
@@ -7447,7 +7461,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo | |||||
return false; | ||||||
} | ||||||
|
||||||
if (report?.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { | ||||||
if (getReportNotificationPreference(report) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { | ||||||
return false; | ||||||
} | ||||||
|
||||||
|
@@ -7465,7 +7479,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo | |||||
return canLeaveInvoiceRoom(report); | ||||||
} | ||||||
|
||||||
return (isChatThread(report) && !!report?.notificationPreference?.length) || isUserCreatedPolicyRoom(report) || isNonAdminOrOwnerOfPolicyExpenseChat(report, policy); | ||||||
return (isChatThread(report) && !!getReportNotificationPreference(report)) || isUserCreatedPolicyRoom(report) || isNonAdminOrOwnerOfPolicyExpenseChat(report, policy); | ||||||
} | ||||||
|
||||||
function getReportActionActorAccountID(reportAction: OnyxInputOrEntry<ReportAction>, iouReport: OnyxInputOrEntry<Report> | undefined): number | undefined { | ||||||
|
@@ -7979,6 +7993,7 @@ export { | |||||
isInvoiceRoomWithID, | ||||||
isInvoiceReport, | ||||||
isOpenInvoiceReport, | ||||||
getDefaultNotificationPreferenceForReport, | ||||||
canWriteInReport, | ||||||
navigateToDetailsPage, | ||||||
navigateToPrivateNotes, | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the usage of the single source of truth i.e.
report.notificationPreference
resulted in #51410There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what do you mean by that? report.notificationPreference has been deprecated and shouldn't be used anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@puneetlath Well! I am not aware of the context behind deprecating
report.notificationPreference
. Let me know if I am missing something here. But, the reasoning for the decision is here i.e.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@puneetlath Its fine. It was a computed property for LHN.