@@ -154,10 +154,10 @@ type OptimisticExpenseReport = Pick<
154
154
| 'statusNum'
155
155
| 'total'
156
156
| 'nonReimbursableTotal'
157
- | 'notificationPreference'
158
157
| 'parentReportID'
159
158
| 'lastVisibleActionCreated'
160
159
| 'parentReportActionID'
160
+ | 'participants'
161
161
| 'fieldList'
162
162
> ;
163
163
@@ -274,7 +274,6 @@ type OptimisticChatReport = Pick<
274
274
| 'lastMessageText'
275
275
| 'lastReadTime'
276
276
| 'lastVisibleActionCreated'
277
- | 'notificationPreference'
278
277
| 'oldPolicyName'
279
278
| 'ownerAccountID'
280
279
| 'pendingFields'
@@ -355,7 +354,6 @@ type OptimisticTaskReport = Pick<
355
354
| 'policyID'
356
355
| 'stateNum'
357
356
| 'statusNum'
358
- | 'notificationPreference'
359
357
| 'parentReportActionID'
360
358
| 'lastVisibleActionCreated'
361
359
| 'hasParentAccess'
@@ -395,7 +393,6 @@ type OptimisticIOUReport = Pick<
395
393
| 'statusNum'
396
394
| 'total'
397
395
| 'reportName'
398
- | 'notificationPreference'
399
396
| 'parentReportID'
400
397
| 'lastVisibleActionCreated'
401
398
| 'fieldList'
@@ -1147,6 +1144,32 @@ function isSystemChat(report: OnyxEntry<Report>): boolean {
1147
1144
return getChatType ( report ) === CONST . REPORT . CHAT_TYPE . SYSTEM ;
1148
1145
}
1149
1146
1147
+ function getDefaultNotificationPreferenceForReport ( report : OnyxEntry < Report > ) : ValueOf < typeof CONST . REPORT . NOTIFICATION_PREFERENCE > {
1148
+ if ( isAnnounceRoom ( report ) ) {
1149
+ return CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS ;
1150
+ }
1151
+ if ( isPublicRoom ( report ) ) {
1152
+ return CONST . REPORT . NOTIFICATION_PREFERENCE . DAILY ;
1153
+ }
1154
+ if ( ! getChatType ( report ) || isGroupChat ( report ) ) {
1155
+ return CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS ;
1156
+ }
1157
+ if ( isAdminRoom ( report ) || isPolicyExpenseChat ( report ) || isInvoiceRoom ( report ) ) {
1158
+ return CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS ;
1159
+ }
1160
+ if ( isSelfDM ( report ) ) {
1161
+ return CONST . REPORT . NOTIFICATION_PREFERENCE . MUTE ;
1162
+ }
1163
+ return CONST . REPORT . NOTIFICATION_PREFERENCE . DAILY ;
1164
+ }
1165
+
1166
+ /**
1167
+ * Get the notification preference given a report
1168
+ */
1169
+ function getReportNotificationPreference ( report : OnyxEntry < Report > ) : ValueOf < typeof CONST . REPORT . NOTIFICATION_PREFERENCE > {
1170
+ return report ?. participants ?. [ currentUserAccountID ?? - 1 ] ?. notificationPreference ?? getDefaultNotificationPreferenceForReport ( report ) ;
1171
+ }
1172
+
1150
1173
const CONCIERGE_ACCOUNT_ID_STRING = CONST . ACCOUNT_ID . CONCIERGE . toString ( ) ;
1151
1174
/**
1152
1175
* Only returns true if this is our main 1:1 DM report with Concierge.
@@ -1252,7 +1275,7 @@ function hasExpensifyGuidesEmails(accountIDs: number[]): boolean {
1252
1275
1253
1276
function getMostRecentlyVisitedReport ( reports : Array < OnyxEntry < Report > > , reportMetadata : OnyxCollection < ReportMetadata > ) : OnyxEntry < Report > {
1254
1277
const filteredReports = reports . filter ( ( report ) => {
1255
- const shouldKeep = ! isChatThread ( report ) || report ?. notificationPreference !== CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ;
1278
+ const shouldKeep = ! isChatThread ( report ) || getReportNotificationPreference ( report ) !== CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ;
1256
1279
return shouldKeep && ! ! report ?. reportID && ! ! ( reportMetadata ?. [ `${ ONYXKEYS . COLLECTION . REPORT_METADATA } ${ report . reportID } ` ] ?. lastVisitTime ?? report ?. lastReadTime ) ;
1257
1280
} ) ;
1258
1281
return lodashMaxBy ( filteredReports , ( a ) => new Date ( reportMetadata ?. [ `${ ONYXKEYS . COLLECTION . REPORT_METADATA } ${ a ?. reportID } ` ] ?. lastVisitTime ?? a ?. lastReadTime ?? '' ) . valueOf ( ) ) ;
@@ -1622,13 +1645,6 @@ function isPayer(session: OnyxEntry<Session>, iouReport: OnyxEntry<Report>) {
1622
1645
return isAdmin || ( isMoneyRequestReport ( iouReport ) && isManager ) ;
1623
1646
}
1624
1647
1625
- /**
1626
- * Get the notification preference given a report
1627
- */
1628
- function getReportNotificationPreference ( report : OnyxEntry < Report > ) : string | number {
1629
- return report ?. notificationPreference ?? '' ;
1630
- }
1631
-
1632
1648
/**
1633
1649
* Checks if the current user is the action's author
1634
1650
*/
@@ -2063,7 +2079,7 @@ function getParticipantsAccountIDsForDisplay(report: OnyxEntry<Report>, shouldEx
2063
2079
return false ;
2064
2080
}
2065
2081
2066
- if ( shouldExcludeHidden && reportParticipants [ accountID ] ?. hidden ) {
2082
+ if ( shouldExcludeHidden && reportParticipants [ accountID ] ?. notificationPreference === CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ) {
2067
2083
return false ;
2068
2084
}
2069
2085
@@ -2116,7 +2132,7 @@ function buildParticipantsFromAccountIDs(accountIDs: number[]): Participants {
2116
2132
const finalParticipants : Participants = { } ;
2117
2133
return accountIDs . reduce ( ( participants , accountID ) => {
2118
2134
// eslint-disable-next-line no-param-reassign
2119
- participants [ accountID ] = { hidden : false } ;
2135
+ participants [ accountID ] = { notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS } ;
2120
2136
return participants ;
2121
2137
} , finalParticipants ) ;
2122
2138
}
@@ -4254,8 +4270,8 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number
4254
4270
const policy = getPolicy ( policyID ) ;
4255
4271
4256
4272
const participants : Participants = {
4257
- [ payeeAccountID ] : { hidden : true } ,
4258
- [ payerAccountID ] : { hidden : true } ,
4273
+ [ payeeAccountID ] : { notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN } ,
4274
+ [ payerAccountID ] : { notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN } ,
4259
4275
} ;
4260
4276
4261
4277
return {
@@ -4273,7 +4289,6 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number
4273
4289
4274
4290
// We don't translate reportName because the server response is always in English
4275
4291
reportName : `${ payerEmail } owes ${ formattedTotal } ` ,
4276
- notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
4277
4292
parentReportID : chatReportID ,
4278
4293
lastVisibleActionCreated : DateUtils . getDBTime ( ) ,
4279
4294
fieldList : policy ?. fieldList ,
@@ -4328,7 +4343,11 @@ function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, re
4328
4343
stateNum : CONST . REPORT . STATE_NUM . SUBMITTED ,
4329
4344
statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
4330
4345
total,
4331
- notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
4346
+ participants : {
4347
+ [ currentUserAccountID ?? - 1 ] : {
4348
+ notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
4349
+ } ,
4350
+ } ,
4332
4351
parentReportID : chatReportID ,
4333
4352
lastVisibleActionCreated : DateUtils . getDBTime ( ) ,
4334
4353
} ;
@@ -4378,7 +4397,11 @@ function buildOptimisticExpenseReport(
4378
4397
statusNum,
4379
4398
total : storedTotal ,
4380
4399
nonReimbursableTotal : reimbursable ? 0 : storedTotal ,
4381
- notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
4400
+ participants : {
4401
+ [ payeeAccountID ] : {
4402
+ notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
4403
+ } ,
4404
+ } ,
4382
4405
parentReportID : chatReportID ,
4383
4406
lastVisibleActionCreated : DateUtils . getDBTime ( ) ,
4384
4407
parentReportActionID,
@@ -5038,12 +5061,11 @@ function buildOptimisticChatReport(
5038
5061
description = '' ,
5039
5062
avatarUrl = '' ,
5040
5063
optimisticReportID = '' ,
5041
- shouldShowParticipants = true ,
5042
5064
) : OptimisticChatReport {
5043
5065
const isWorkspaceChatType = chatType && isWorkspaceChat ( chatType ) ;
5044
5066
const participants = participantList . reduce ( ( reportParticipants : Participants , accountID : number ) => {
5045
5067
const participant : ReportParticipant = {
5046
- hidden : ! shouldShowParticipants ,
5068
+ notificationPreference ,
5047
5069
...( ! isWorkspaceChatType && { role : accountID === currentUserAccountID ? CONST . REPORT . ROLE . ADMIN : CONST . REPORT . ROLE . MEMBER } ) ,
5048
5070
} ;
5049
5071
// eslint-disable-next-line no-param-reassign
@@ -5064,7 +5086,6 @@ function buildOptimisticChatReport(
5064
5086
lastMessageText : undefined ,
5065
5087
lastReadTime : currentTime ,
5066
5088
lastVisibleActionCreated : currentTime ,
5067
- notificationPreference,
5068
5089
oldPolicyName,
5069
5090
ownerAccountID : ownerAccountID || CONST . REPORT . OWNER_ACCOUNT_ID_FAKE ,
5070
5091
parentReportActionID,
@@ -5482,9 +5503,7 @@ function buildOptimisticWorkspaceChats(policyID: string, policyName: string, exp
5482
5503
policyName ,
5483
5504
undefined ,
5484
5505
undefined ,
5485
-
5486
- // #announce contains all policy members so notifying always should be opt-in only.
5487
- CONST . REPORT . NOTIFICATION_PREFERENCE . DAILY ,
5506
+ CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS ,
5488
5507
) ;
5489
5508
const announceChatReportID = announceChatData . reportID ;
5490
5509
const announceCreatedAction = buildOptimisticCreatedReportAction ( CONST . POLICY . OWNER_EMAIL_FAKE ) ;
@@ -5571,12 +5590,12 @@ function buildOptimisticTaskReport(
5571
5590
) : OptimisticTaskReport {
5572
5591
const participants : Participants = {
5573
5592
[ ownerAccountID ] : {
5574
- hidden : false ,
5593
+ notificationPreference ,
5575
5594
} ,
5576
5595
} ;
5577
5596
5578
5597
if ( assigneeAccountID ) {
5579
- participants [ assigneeAccountID ] = { hidden : false } ;
5598
+ participants [ assigneeAccountID ] = { notificationPreference } ;
5580
5599
}
5581
5600
5582
5601
return {
@@ -5591,7 +5610,6 @@ function buildOptimisticTaskReport(
5591
5610
policyID,
5592
5611
stateNum : CONST . REPORT . STATE_NUM . OPEN ,
5593
5612
statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
5594
- notificationPreference,
5595
5613
lastVisibleActionCreated : DateUtils . getDBTime ( ) ,
5596
5614
hasParentAccess : true ,
5597
5615
} ;
@@ -5669,10 +5687,6 @@ function buildTransactionThread(
5669
5687
CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
5670
5688
reportAction ?. reportActionID ,
5671
5689
moneyRequestReport ?. reportID ,
5672
- '' ,
5673
- '' ,
5674
- '' ,
5675
- false ,
5676
5690
) ;
5677
5691
}
5678
5692
@@ -6049,7 +6063,7 @@ function shouldReportBeInOptionList({
6049
6063
6050
6064
// 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
6051
6065
if ( isInFocusMode ) {
6052
- return isUnread ( report ) && report . notificationPreference !== CONST . REPORT . NOTIFICATION_PREFERENCE . MUTE ;
6066
+ return isUnread ( report ) && getReportNotificationPreference ( report ) !== CONST . REPORT . NOTIFICATION_PREFERENCE . MUTE ;
6053
6067
}
6054
6068
6055
6069
// 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.
@@ -7441,15 +7455,15 @@ function isAdminOwnerApproverOrReportOwner(report: OnyxEntry<Report>, policy: On
7441
7455
/**
7442
7456
* Whether the user can join a report
7443
7457
*/
7444
- function canJoinChat ( report : OnyxInputOrEntry < Report > , parentReportAction : OnyxInputOrEntry < ReportAction > , policy : OnyxInputOrEntry < Policy > ) : boolean {
7458
+ function canJoinChat ( report : OnyxEntry < Report > , parentReportAction : OnyxInputOrEntry < ReportAction > , policy : OnyxInputOrEntry < Policy > ) : boolean {
7445
7459
// We disabled thread functions for whisper action
7446
7460
// So we should not show join option for existing thread on whisper message that has already been left, or manually leave it
7447
7461
if ( ReportActionsUtils . isWhisperAction ( parentReportAction ) ) {
7448
7462
return false ;
7449
7463
}
7450
7464
7451
7465
// If the notification preference of the chat is not hidden that means we have already joined the chat
7452
- if ( report ?. notificationPreference !== CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ) {
7466
+ if ( getReportNotificationPreference ( report ) !== CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ) {
7453
7467
return false ;
7454
7468
}
7455
7469
@@ -7483,7 +7497,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo
7483
7497
return false ;
7484
7498
}
7485
7499
7486
- if ( report ?. notificationPreference === CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ) {
7500
+ if ( getReportNotificationPreference ( report ) === CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ) {
7487
7501
return false ;
7488
7502
}
7489
7503
@@ -7501,7 +7515,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo
7501
7515
return canLeaveInvoiceRoom ( report ) ;
7502
7516
}
7503
7517
7504
- return ( isChatThread ( report ) && ! ! report ?. notificationPreference ?. length ) || isUserCreatedPolicyRoom ( report ) || isNonAdminOrOwnerOfPolicyExpenseChat ( report , policy ) ;
7518
+ return ( isChatThread ( report ) && ! ! getReportNotificationPreference ( report ) ) || isUserCreatedPolicyRoom ( report ) || isNonAdminOrOwnerOfPolicyExpenseChat ( report , policy ) ;
7505
7519
}
7506
7520
7507
7521
function getReportActionActorAccountID ( reportAction : OnyxInputOrEntry < ReportAction > , iouReport : OnyxInputOrEntry < Report > | undefined ) : number | undefined {
@@ -8034,6 +8048,7 @@ export {
8034
8048
isInvoiceRoomWithID ,
8035
8049
isInvoiceReport ,
8036
8050
isOpenInvoiceReport ,
8051
+ getDefaultNotificationPreferenceForReport ,
8037
8052
canWriteInReport ,
8038
8053
navigateToDetailsPage ,
8039
8054
navigateToPrivateNotes ,
0 commit comments