-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
User.js
893 lines (840 loc) · 25.5 KB
/
User.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
import {isBefore} from 'date-fns';
import lodashGet from 'lodash/get';
import Onyx from 'react-native-onyx';
import _ from 'underscore';
import * as API from '@libs/API';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as SequentialQueue from '@libs/Network/SequentialQueue';
import * as Pusher from '@libs/Pusher/pusher';
import PusherUtils from '@libs/PusherUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import * as Link from './Link';
import * as OnyxUpdates from './OnyxUpdates';
import * as PersonalDetails from './PersonalDetails';
import * as Report from './Report';
import * as Session from './Session';
import redirectToSignIn from './SignInRedirect';
let currentUserAccountID = '';
let currentEmail = '';
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
currentUserAccountID = lodashGet(val, 'accountID', -1);
currentEmail = lodashGet(val, 'email', '');
},
});
let myPersonalDetails = {};
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => {
if (!val || !currentUserAccountID) {
return;
}
myPersonalDetails = val[currentUserAccountID];
},
});
/**
* Attempt to close the user's account
*
* @param {String} message optional reason for closing account
*/
function closeAccount(message) {
// Note: successData does not need to set isLoading to false because if the CloseAccount
// command succeeds, a Pusher response will clear all Onyx data.
API.write(
'CloseAccount',
{message},
{
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM,
value: {isLoading: true},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM,
value: {isLoading: false},
},
],
},
);
// Run cleanup actions to prevent reconnection callbacks from blocking logging in again
redirectToSignIn();
}
/**
* Resends a validation link to a given login
*
* @param {String} login
*/
function resendValidateCode(login) {
Session.resendValidateCode(login);
}
/**
* Requests a new validate code be sent for the passed contact method
*
* @param {String} contactMethod - the new contact method that the user is trying to verify
*/
function requestContactMethodValidateCode(contactMethod) {
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
validateCodeSent: false,
errorFields: {
validateCodeSent: null,
validateLogin: null,
},
pendingFields: {
validateCodeSent: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
},
];
const successData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
validateCodeSent: true,
pendingFields: {
validateCodeSent: null,
},
},
},
},
];
const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
validateCodeSent: false,
errorFields: {
validateCodeSent: ErrorUtils.getMicroSecondOnyxError('contacts.genericFailureMessages.requestContactMethodValidateCode'),
},
pendingFields: {
validateCodeSent: null,
},
},
},
},
];
API.write(
'RequestContactMethodValidateCode',
{
email: contactMethod,
},
{optimisticData, successData, failureData},
);
}
/**
* Sets whether or not the user is subscribed to Expensify news
*
* @param {Boolean} isSubscribed
*/
function updateNewsletterSubscription(isSubscribed) {
API.write(
'UpdateNewsletterSubscription',
{
isSubscribed,
},
{
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.USER,
value: {isSubscribedToNewsletter: isSubscribed},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.USER,
value: {isSubscribedToNewsletter: !isSubscribed},
},
],
},
);
}
/**
* Delete a specific contact method
*
* @param {String} contactMethod - the contact method being deleted
* @param {Array} loginList
*/
function deleteContactMethod(contactMethod, loginList) {
const oldLoginData = loginList[contactMethod];
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
partnerUserID: '',
errorFields: {
deletedLogin: null,
},
pendingFields: {
deletedLogin: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
},
},
},
},
];
const successData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: null,
},
},
];
const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
...oldLoginData,
errorFields: {
deletedLogin: ErrorUtils.getMicroSecondOnyxError('contacts.genericFailureMessages.deleteContactMethod'),
},
pendingFields: {
deletedLogin: null,
},
},
},
},
];
API.write(
'DeleteContactMethod',
{
partnerUserID: contactMethod,
},
{optimisticData, successData, failureData},
);
Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.route);
}
/**
* Clears any possible stored errors for a specific field on a contact method
*
* @param {String} contactMethod
* @param {String} fieldName
*/
function clearContactMethodErrors(contactMethod, fieldName) {
Onyx.merge(ONYXKEYS.LOGIN_LIST, {
[contactMethod]: {
errorFields: {
[fieldName]: null,
},
pendingFields: {
[fieldName]: null,
},
},
});
}
/**
* Resets the state indicating whether a validation code has been sent to a specific contact method.
*
* @param {String} contactMethod - The identifier of the contact method to reset.
*/
function resetContactMethodValidateCodeSentState(contactMethod) {
Onyx.merge(ONYXKEYS.LOGIN_LIST, {
[contactMethod]: {
validateCodeSent: false,
},
});
}
/**
* Adds a secondary login to a user's account
*
* @param {String} contactMethod
*/
function addNewContactMethodAndNavigate(contactMethod) {
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
partnerUserID: contactMethod,
validatedDate: '',
errorFields: {
addedLogin: null,
},
pendingFields: {
addedLogin: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
},
},
},
];
const successData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
pendingFields: {
addedLogin: null,
},
},
},
},
];
const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
errorFields: {
addedLogin: ErrorUtils.getMicroSecondOnyxError('contacts.genericFailureMessages.addContactMethod'),
},
pendingFields: {
addedLogin: null,
},
},
},
},
];
API.write('AddNewContactMethod', {partnerUserID: contactMethod}, {optimisticData, successData, failureData});
Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.route);
}
/**
* Validates a login given an accountID and validation code
*
* @param {Number} accountID
* @param {String} validateCode
*/
function validateLogin(accountID, validateCode) {
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, isLoading: true});
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {
isLoading: false,
},
},
];
API.write(
'ValidateLogin',
{
accountID,
validateCode,
},
{optimisticData},
);
Navigation.navigate(ROUTES.HOME);
}
/**
* Validates a secondary login / contact method
*
* @param {String} contactMethod - The contact method the user is trying to verify
* @param {String} validateCode
*/
function validateSecondaryLogin(contactMethod, validateCode) {
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
errorFields: {
validateLogin: null,
},
pendingFields: {
validateLogin: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {
...CONST.DEFAULT_ACCOUNT_DATA,
isLoading: true,
},
},
];
const successData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
pendingFields: {
validateLogin: null,
},
errorFields: {
validateCodeSent: null,
},
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {isLoading: false},
},
];
const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[contactMethod]: {
errorFields: {
validateLogin: ErrorUtils.getMicroSecondOnyxError('contacts.genericFailureMessages.validateSecondaryLogin'),
},
pendingFields: {
validateLogin: null,
},
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {isLoading: false},
},
];
API.write(
'ValidateSecondaryLogin',
{
partnerUserID: contactMethod,
validateCode,
},
{optimisticData, successData, failureData},
);
}
/**
* Checks the blockedFromConcierge object to see if it has an expiresAt key,
* and if so whether the expiresAt date of a user's ban is before right now
*
* @param {Object} blockedFromConciergeNVP
* @returns {Boolean}
*/
function isBlockedFromConcierge(blockedFromConciergeNVP) {
if (_.isEmpty(blockedFromConciergeNVP)) {
return false;
}
if (!blockedFromConciergeNVP.expiresAt) {
return false;
}
return isBefore(new Date(), new Date(blockedFromConciergeNVP.expiresAt));
}
function triggerNotifications(onyxUpdates) {
_.each(onyxUpdates, (update) => {
if (!update.shouldNotify) {
return;
}
const reportID = update.key.replace(ONYXKEYS.COLLECTION.REPORT_ACTIONS, '');
const reportActions = _.values(update.value);
// eslint-disable-next-line rulesdir/no-negated-variables
const notifiableActions = _.filter(reportActions, (action) => ReportActionsUtils.isNotifiableReportAction(action));
_.each(notifiableActions, (action) => Report.showReportActionNotification(reportID, action));
});
}
/**
* Handles the newest events from Pusher where a single mega multipleEvents contains
* an array of singular events all in one event
*/
function subscribeToUserEvents() {
// If we don't have the user's accountID yet (because the app isn't fully setup yet) we can't subscribe so return early
if (!currentUserAccountID) {
return;
}
// Handles the mega multipleEvents from Pusher which contains an array of single events.
// Each single event is passed to PusherUtils in order to trigger the callbacks for that event
PusherUtils.subscribeToPrivateUserChannelEvent(Pusher.TYPE.MULTIPLE_EVENTS, currentUserAccountID, (pushJSON) => {
// The data for this push event comes in two different formats:
// 1. Original format - this is what was sent before the RELIABLE_UPDATES project and will go away once RELIABLE_UPDATES is fully complete
// - The data is an array of objects, where each object is an onyx update
// Example: [{onyxMethod: 'whatever', key: 'foo', value: 'bar'}]
// 1. Reliable updates format - this is what was sent with the RELIABLE_UPDATES project and will be the format from now on
// - The data is an object, containing updateIDs from the server and an array of onyx updates (this array is the same format as the original format above)
// Example: {lastUpdateID: 1, previousUpdateID: 0, updates: [{onyxMethod: 'whatever', key: 'foo', value: 'bar'}]}
if (_.isArray(pushJSON)) {
_.each(pushJSON, (multipleEvent) => {
PusherUtils.triggerMultiEventHandler(multipleEvent.eventType, multipleEvent.data);
});
return;
}
const updates = {
type: CONST.ONYX_UPDATE_TYPES.PUSHER,
lastUpdateID: Number(pushJSON.lastUpdateID || 0),
updates: pushJSON.updates,
previousUpdateID: Number(pushJSON.previousUpdateID || 0),
};
if (!OnyxUpdates.doesClientNeedToBeUpdated(Number(pushJSON.previousUpdateID || 0))) {
OnyxUpdates.apply(updates);
return;
}
// If we reached this point, we need to pause the queue while we prepare to fetch older OnyxUpdates.
SequentialQueue.pause();
OnyxUpdates.saveUpdateInformation(updates);
});
// Handles Onyx updates coming from Pusher through the mega multipleEvents.
PusherUtils.subscribeToMultiEvent(Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE, (pushJSON) =>
SequentialQueue.getCurrentRequest().then(() => {
// If we don't have the currentUserAccountID (user is logged out) we don't want to update Onyx with data from Pusher
if (!currentUserAccountID) {
return;
}
const onyxUpdatePromise = Onyx.update(pushJSON).then(() => {
triggerNotifications(pushJSON);
});
// Return a promise when Onyx is done updating so that the OnyxUpdatesManager can properly apply all
// the onyx updates in order
return onyxUpdatePromise;
}),
);
}
/**
* Sync preferredSkinTone with Onyx and Server
* @param {Number} skinTone
*/
function updatePreferredSkinTone(skinTone) {
const optimisticData = [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE,
value: skinTone,
},
];
API.write(
'UpdatePreferredEmojiSkinTone',
{
value: skinTone,
},
{optimisticData},
);
}
/**
* Sync frequentlyUsedEmojis with Onyx and Server
* @param {Object[]} frequentlyUsedEmojis
*/
function updateFrequentlyUsedEmojis(frequentlyUsedEmojis) {
const optimisticData = [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.FREQUENTLY_USED_EMOJIS,
value: frequentlyUsedEmojis,
},
];
API.write(
'UpdateFrequentlyUsedEmojis',
{
value: JSON.stringify(frequentlyUsedEmojis),
},
{optimisticData},
);
}
/**
* Sync user chat priority mode with Onyx and Server
* @param {String} mode
* @param {boolean} [automatic] if we changed the mode automatically
*/
function updateChatPriorityMode(mode, automatic = false) {
const autoSwitchedToFocusMode = mode === CONST.PRIORITY_MODE.GSD && automatic;
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_PRIORITY_MODE,
value: mode,
},
];
if (autoSwitchedToFocusMode) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_TRY_FOCUS_MODE,
value: true,
});
}
API.write(
'UpdateChatPriorityMode',
{
value: mode,
automatic,
},
{optimisticData},
);
if (!autoSwitchedToFocusMode) {
Navigation.goBack(ROUTES.SETTINGS_PREFERENCES);
}
}
function clearFocusModeNotification() {
Onyx.set(ONYXKEYS.FOCUS_MODE_NOTIFICATION, false);
}
/**
* @param {Boolean} shouldUseStagingServer
*/
function setShouldUseStagingServer(shouldUseStagingServer) {
Onyx.merge(ONYXKEYS.USER, {shouldUseStagingServer});
}
function clearUserErrorMessage() {
Onyx.merge(ONYXKEYS.USER, {error: ''});
}
/**
* Clear the data about a screen share request from Onyx.
*/
function clearScreenShareRequest() {
Onyx.set(ONYXKEYS.SCREEN_SHARE_REQUEST, null);
}
/**
* Open an OldDot tab linking to a screen share request.
* @param {String} accessToken Access token required to join a screen share room, generated by the backend
* @param {String} roomName Name of the screen share room to join
*/
function joinScreenShare(accessToken, roomName) {
Link.openOldDotLink(`inbox?action=screenShare&accessToken=${accessToken}&name=${roomName}`);
clearScreenShareRequest();
}
/**
* Downloads the statement PDF for the provided period
* @param {String} period YYYYMM format
*/
function generateStatementPDF(period) {
API.read(
'GetStatementPDF',
{period},
{
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.WALLET_STATEMENT,
value: {
isGenerating: true,
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.WALLET_STATEMENT,
value: {
isGenerating: false,
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.WALLET_STATEMENT,
value: {
isGenerating: false,
},
},
],
},
);
}
/**
* Sets a contact method / secondary login as the user's "Default" contact method.
*
* @param {String} newDefaultContactMethod
*/
function setContactMethodAsDefault(newDefaultContactMethod) {
const oldDefaultContactMethod = currentEmail;
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.SESSION,
value: {
email: newDefaultContactMethod,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[newDefaultContactMethod]: {
pendingFields: {
defaultLogin: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
errorFields: {
defaultLogin: null,
},
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[currentUserAccountID]: {
login: newDefaultContactMethod,
displayName: PersonalDetails.getDisplayName(newDefaultContactMethod, myPersonalDetails),
},
},
},
];
const successData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[newDefaultContactMethod]: {
pendingFields: {
defaultLogin: null,
},
},
},
},
];
const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.SESSION,
value: {
email: oldDefaultContactMethod,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.LOGIN_LIST,
value: {
[newDefaultContactMethod]: {
pendingFields: {
defaultLogin: null,
},
errorFields: {
defaultLogin: ErrorUtils.getMicroSecondOnyxError('contacts.genericFailureMessages.setDefaultContactMethod'),
},
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[currentUserAccountID]: {...myPersonalDetails},
},
},
];
API.write('SetContactMethodAsDefault', {partnerUserID: newDefaultContactMethod}, {optimisticData, successData, failureData});
Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.route);
}
/**
* @param {String} theme
*/
function updateTheme(theme) {
const optimisticData = [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.PREFERRED_THEME,
value: theme,
},
];
API.write(
'UpdateTheme',
{
value: theme,
},
{optimisticData},
);
Navigation.navigate(ROUTES.SETTINGS_PREFERENCES);
}
/**
* Sets a custom status
*
* @param {Object} status
* @param {String} status.text
* @param {String} status.emojiCode
*/
function updateCustomStatus(status) {
API.write('UpdateStatus', status, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[currentUserAccountID]: {
status,
},
},
},
],
});
}
/**
* Clears the custom status
*/
function clearCustomStatus() {
API.write('ClearStatus', undefined, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[currentUserAccountID]: {
status: null, // Clearing the field
},
},
},
],
});
}
/**
* Sets a custom status
*
* @param {Object} status
* @param {String} status.text
* @param {String} status.emojiCode
* @param {String} status.clearAfter - ISO 8601 format string, which represents the time when the status should be cleared
*/
function updateDraftCustomStatus(status) {
Onyx.merge(ONYXKEYS.CUSTOM_STATUS_DRAFT, status);
}
/**
* Clear the custom draft status
*
*/
function clearDraftCustomStatus() {
Onyx.merge(ONYXKEYS.CUSTOM_STATUS_DRAFT, {text: '', emojiCode: '', clearAfter: '', customDateTemporary: ''});
}
export {
clearFocusModeNotification,
closeAccount,
resendValidateCode,
requestContactMethodValidateCode,
updateNewsletterSubscription,
deleteContactMethod,
clearContactMethodErrors,
addNewContactMethodAndNavigate,
validateLogin,
validateSecondaryLogin,
isBlockedFromConcierge,
subscribeToUserEvents,
updatePreferredSkinTone,
setShouldUseStagingServer,
clearUserErrorMessage,
updateFrequentlyUsedEmojis,
joinScreenShare,
clearScreenShareRequest,
generateStatementPDF,
updateChatPriorityMode,
setContactMethodAsDefault,
updateTheme,
resetContactMethodValidateCodeSentState,
updateCustomStatus,
clearCustomStatus,
updateDraftCustomStatus,
clearDraftCustomStatus,
};