From d77ce13e3c7966e2d9f310909ab06ba5d971d4a6 Mon Sep 17 00:00:00 2001
From: Tim Golen <tgolen@expensify.com>
Date: Wed, 10 May 2023 15:46:40 -0600
Subject: [PATCH 1/6] Remove code for old pusher events

---
 src/libs/actions/User.js | 39 +++++++--------------------------------
 1 file changed, 7 insertions(+), 32 deletions(-)

diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js
index 71a9ee50f1c0..c65fe20a26de 100644
--- a/src/libs/actions/User.js
+++ b/src/libs/actions/User.js
@@ -563,10 +563,14 @@ function triggerNotifications(onyxUpdates) {
 }
 
 /**
- * Handles the newest events from Pusher where a single mega multipleEvents contains
- * an array of singular events all in one event
+ * Initialize our pusher subscription to listen for user changes
  */
-function subscribeToUserEventsUsingMultipleEventType() {
+function subscribeToUserEvents() {
+    // If we don't have the user's accountID 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) => {
@@ -584,35 +588,6 @@ function subscribeToUserEventsUsingMultipleEventType() {
     });
 }
 
-/**
- * Handles the older Pusher events where each event was pushed separately. This is considered legacy code
- * and should not be updated. Once the server is sending all pusher events using the multipleEvents type,
- * then this code can be removed. This will be handled in https://github.com/Expensify/Expensify/issues/279347
- * @deprecated
- */
-function subscribeToUserDeprecatedEvents() {
-    // Receive any relevant Onyx updates from the server
-    PusherUtils.subscribeToPrivateUserChannelEvent(Pusher.TYPE.ONYX_API_UPDATE, currentUserAccountID, (pushJSON) => {
-        SequentialQueue.getCurrentRequest().then(() => {
-            Onyx.update(pushJSON);
-            triggerNotifications(pushJSON);
-        });
-    });
-}
-
-/**
- * Initialize our pusher subscription to listen for user changes
- */
-function subscribeToUserEvents() {
-    // If we don't have the user's accountID yet we can't subscribe so return early
-    if (!currentUserAccountID) {
-        return;
-    }
-
-    subscribeToUserEventsUsingMultipleEventType();
-    subscribeToUserDeprecatedEvents();
-}
-
 /**
  * Sync preferredSkinTone with Onyx and Server
  * @param {String} skinTone

From c21d8a4a1ec55f5b9c7f0666809f0287e6f617af Mon Sep 17 00:00:00 2001
From: Tim Golen <tgolen@expensify.com>
Date: Wed, 17 May 2023 09:50:06 -0600
Subject: [PATCH 2/6] Rename method

---
 src/libs/actions/User.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js
index 63bc7be9e16f..0be3b49facd9 100644
--- a/src/libs/actions/User.js
+++ b/src/libs/actions/User.js
@@ -566,7 +566,7 @@ function triggerNotifications(onyxUpdates) {
  * Handles the newest events from Pusher where a single mega multipleEvents contains
  * an array of singular events all in one event
  */
-function subscribeToUserEventsUsingMultipleEventType() {
+function subscribeToUserEvents() {
     // 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) => {

From d7c8ac63396b87c499f8a94d5189952616ea852e Mon Sep 17 00:00:00 2001
From: Tim Golen <tgolen@expensify.com>
Date: Wed, 17 May 2023 12:17:27 -0600
Subject: [PATCH 3/6] Fix unit tests

---
 tests/ui/UnreadIndicatorsTest.js | 81 +++++++++++++++++---------------
 tests/utils/PusherHelper.js      |  5 +-
 2 files changed, 46 insertions(+), 40 deletions(-)

diff --git a/tests/ui/UnreadIndicatorsTest.js b/tests/ui/UnreadIndicatorsTest.js
index 0b848a5722e5..cb70206999b9 100644
--- a/tests/ui/UnreadIndicatorsTest.js
+++ b/tests/ui/UnreadIndicatorsTest.js
@@ -296,49 +296,52 @@ describe('Unread Indicators', () => {
                 const createdReportActionID = NumberUtils.rand64();
                 const commentReportActionID = NumberUtils.rand64();
                 const channel = Pusher.getChannel(`${CONST.PUSHER.PRIVATE_USER_CHANNEL_PREFIX}${USER_A_ACCOUNT_ID}${CONFIG.PUSHER.SUFFIX}`);
-                channel.emit(Pusher.TYPE.ONYX_API_UPDATE, [
-                    {
-                        onyxMethod: Onyx.METHOD.MERGE,
-                        key: `${ONYXKEYS.COLLECTION.REPORT}${NEW_REPORT_ID}`,
-                        value: {
-                            reportID: NEW_REPORT_ID,
-                            reportName: CONST.REPORT.DEFAULT_REPORT_NAME,
-                            lastReadTime: '',
-                            lastVisibleActionCreated: DateUtils.getDBTime(NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.utc().valueOf()),
-                            lastMessageText: 'Comment 1',
-                            participants: [USER_C_EMAIL],
-                        },
-                    },
-                    {
-                        onyxMethod: Onyx.METHOD.MERGE,
-                        key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${NEW_REPORT_ID}`,
-                        value: {
-                            [createdReportActionID]: {
-                                actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
-                                automatic: false,
-                                created: NEW_REPORT_CREATED_MOMENT.format(MOMENT_FORMAT),
-                                reportActionID: createdReportActionID,
+                channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [{
+                    eventType: Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE,
+                    data: [
+                        {
+                            onyxMethod: Onyx.METHOD.MERGE,
+                            key: `${ONYXKEYS.COLLECTION.REPORT}${NEW_REPORT_ID}`,
+                            value: {
+                                reportID: NEW_REPORT_ID,
+                                reportName: CONST.REPORT.DEFAULT_REPORT_NAME,
+                                lastReadTime: '',
+                                lastVisibleActionCreated: DateUtils.getDBTime(NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.utc().valueOf()),
+                                lastMessageText: 'Comment 1',
+                                participants: [USER_C_EMAIL],
                             },
-                            [commentReportActionID]: {
-                                actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
-                                actorEmail: USER_C_EMAIL,
-                                actorAccountID: USER_C_ACCOUNT_ID,
-                                person: [{type: 'TEXT', style: 'strong', text: 'User C'}],
-                                created: NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.format(MOMENT_FORMAT),
-                                message: [{type: 'COMMENT', html: 'Comment 1', text: 'Comment 1'}],
-                                reportActionID: commentReportActionID,
+                        },
+                        {
+                            onyxMethod: Onyx.METHOD.MERGE,
+                            key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${NEW_REPORT_ID}`,
+                            value: {
+                                [createdReportActionID]: {
+                                    actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
+                                    automatic: false,
+                                    created: NEW_REPORT_CREATED_MOMENT.format(MOMENT_FORMAT),
+                                    reportActionID: createdReportActionID,
+                                },
+                                [commentReportActionID]: {
+                                    actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
+                                    actorEmail: USER_C_EMAIL,
+                                    actorAccountID: USER_C_ACCOUNT_ID,
+                                    person: [{type: 'TEXT', style: 'strong', text: 'User C'}],
+                                    created: NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.format(MOMENT_FORMAT),
+                                    message: [{type: 'COMMENT', html: 'Comment 1', text: 'Comment 1'}],
+                                    reportActionID: commentReportActionID,
+                                },
                             },
+                            shouldNotify: true,
                         },
-                        shouldNotify: true,
-                    },
-                    {
-                        onyxMethod: Onyx.METHOD.MERGE,
-                        key: ONYXKEYS.PERSONAL_DETAILS,
-                        value: {
-                            [USER_C_EMAIL]: TestHelper.buildPersonalDetails(USER_C_EMAIL, USER_C_ACCOUNT_ID, 'C'),
+                        {
+                            onyxMethod: Onyx.METHOD.MERGE,
+                            key: ONYXKEYS.PERSONAL_DETAILS,
+                            value: {
+                                [USER_C_EMAIL]: TestHelper.buildPersonalDetails(USER_C_EMAIL, USER_C_ACCOUNT_ID, 'C'),
+                            },
                         },
-                    },
-                ]);
+                    ]
+                }]);
                 return waitForPromisesToResolve();
             })
             .then(() => {
diff --git a/tests/utils/PusherHelper.js b/tests/utils/PusherHelper.js
index d3d7cdede559..102f440375d2 100644
--- a/tests/utils/PusherHelper.js
+++ b/tests/utils/PusherHelper.js
@@ -27,7 +27,10 @@ function setup() {
  */
 function emitOnyxUpdate(args) {
     const channel = Pusher.getChannel(CHANNEL_NAME);
-    channel.emit(Pusher.TYPE.ONYX_API_UPDATE, args);
+    channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [{
+        eventType: Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE,
+        data: args,
+    }]);
 }
 
 function teardown() {

From 7e92ef90dc3085c7977f4d4b7263440848be4d05 Mon Sep 17 00:00:00 2001
From: Tim Golen <tgolen@expensify.com>
Date: Wed, 17 May 2023 12:25:15 -0600
Subject: [PATCH 4/6] lint

---
 tests/ui/UnreadIndicatorsTest.js | 86 ++++++++++++++++----------------
 tests/utils/PusherHelper.js      | 10 ++--
 2 files changed, 50 insertions(+), 46 deletions(-)

diff --git a/tests/ui/UnreadIndicatorsTest.js b/tests/ui/UnreadIndicatorsTest.js
index cb70206999b9..8e62bd42993c 100644
--- a/tests/ui/UnreadIndicatorsTest.js
+++ b/tests/ui/UnreadIndicatorsTest.js
@@ -296,52 +296,54 @@ describe('Unread Indicators', () => {
                 const createdReportActionID = NumberUtils.rand64();
                 const commentReportActionID = NumberUtils.rand64();
                 const channel = Pusher.getChannel(`${CONST.PUSHER.PRIVATE_USER_CHANNEL_PREFIX}${USER_A_ACCOUNT_ID}${CONFIG.PUSHER.SUFFIX}`);
-                channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [{
-                    eventType: Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE,
-                    data: [
-                        {
-                            onyxMethod: Onyx.METHOD.MERGE,
-                            key: `${ONYXKEYS.COLLECTION.REPORT}${NEW_REPORT_ID}`,
-                            value: {
-                                reportID: NEW_REPORT_ID,
-                                reportName: CONST.REPORT.DEFAULT_REPORT_NAME,
-                                lastReadTime: '',
-                                lastVisibleActionCreated: DateUtils.getDBTime(NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.utc().valueOf()),
-                                lastMessageText: 'Comment 1',
-                                participants: [USER_C_EMAIL],
-                            },
-                        },
-                        {
-                            onyxMethod: Onyx.METHOD.MERGE,
-                            key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${NEW_REPORT_ID}`,
-                            value: {
-                                [createdReportActionID]: {
-                                    actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
-                                    automatic: false,
-                                    created: NEW_REPORT_CREATED_MOMENT.format(MOMENT_FORMAT),
-                                    reportActionID: createdReportActionID,
+                channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [
+                    {
+                        eventType: Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE,
+                        data: [
+                            {
+                                onyxMethod: Onyx.METHOD.MERGE,
+                                key: `${ONYXKEYS.COLLECTION.REPORT}${NEW_REPORT_ID}`,
+                                value: {
+                                    reportID: NEW_REPORT_ID,
+                                    reportName: CONST.REPORT.DEFAULT_REPORT_NAME,
+                                    lastReadTime: '',
+                                    lastVisibleActionCreated: DateUtils.getDBTime(NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.utc().valueOf()),
+                                    lastMessageText: 'Comment 1',
+                                    participants: [USER_C_EMAIL],
                                 },
-                                [commentReportActionID]: {
-                                    actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
-                                    actorEmail: USER_C_EMAIL,
-                                    actorAccountID: USER_C_ACCOUNT_ID,
-                                    person: [{type: 'TEXT', style: 'strong', text: 'User C'}],
-                                    created: NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.format(MOMENT_FORMAT),
-                                    message: [{type: 'COMMENT', html: 'Comment 1', text: 'Comment 1'}],
-                                    reportActionID: commentReportActionID,
+                            },
+                            {
+                                onyxMethod: Onyx.METHOD.MERGE,
+                                key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${NEW_REPORT_ID}`,
+                                value: {
+                                    [createdReportActionID]: {
+                                        actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
+                                        automatic: false,
+                                        created: NEW_REPORT_CREATED_MOMENT.format(MOMENT_FORMAT),
+                                        reportActionID: createdReportActionID,
+                                    },
+                                    [commentReportActionID]: {
+                                        actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
+                                        actorEmail: USER_C_EMAIL,
+                                        actorAccountID: USER_C_ACCOUNT_ID,
+                                        person: [{type: 'TEXT', style: 'strong', text: 'User C'}],
+                                        created: NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.format(MOMENT_FORMAT),
+                                        message: [{type: 'COMMENT', html: 'Comment 1', text: 'Comment 1'}],
+                                        reportActionID: commentReportActionID,
+                                    },
                                 },
+                                shouldNotify: true,
                             },
-                            shouldNotify: true,
-                        },
-                        {
-                            onyxMethod: Onyx.METHOD.MERGE,
-                            key: ONYXKEYS.PERSONAL_DETAILS,
-                            value: {
-                                [USER_C_EMAIL]: TestHelper.buildPersonalDetails(USER_C_EMAIL, USER_C_ACCOUNT_ID, 'C'),
+                            {
+                                onyxMethod: Onyx.METHOD.MERGE,
+                                key: ONYXKEYS.PERSONAL_DETAILS,
+                                value: {
+                                    [USER_C_EMAIL]: TestHelper.buildPersonalDetails(USER_C_EMAIL, USER_C_ACCOUNT_ID, 'C'),
+                                },
                             },
-                        },
-                    ]
-                }]);
+                        ],
+                    },
+                ]);
                 return waitForPromisesToResolve();
             })
             .then(() => {
diff --git a/tests/utils/PusherHelper.js b/tests/utils/PusherHelper.js
index 102f440375d2..b763f4ebb28f 100644
--- a/tests/utils/PusherHelper.js
+++ b/tests/utils/PusherHelper.js
@@ -27,10 +27,12 @@ function setup() {
  */
 function emitOnyxUpdate(args) {
     const channel = Pusher.getChannel(CHANNEL_NAME);
-    channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [{
-        eventType: Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE,
-        data: args,
-    }]);
+    channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [
+        {
+            eventType: Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE,
+            data: args,
+        },
+    ]);
 }
 
 function teardown() {

From 88735525486c0d86911b74f22b1b8f01bc4365c6 Mon Sep 17 00:00:00 2001
From: Tim Golen <tgolen@expensify.com>
Date: Fri, 19 May 2023 08:57:50 -0600
Subject: [PATCH 5/6] Add an early return if the app is not fully initialized

---
 src/libs/actions/User.js | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js
index 49ca1f15a4d5..dae15c46f359 100644
--- a/src/libs/actions/User.js
+++ b/src/libs/actions/User.js
@@ -585,6 +585,11 @@ function triggerNotifications(onyxUpdates) {
  * 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) => {

From 2ea6b3130556fb45bcbc61d8ad6df02af8c3f211 Mon Sep 17 00:00:00 2001
From: Ionatan Wiznia <ionatan@expensify.com>
Date: Mon, 19 Jun 2023 14:39:59 -0300
Subject: [PATCH 6/6] Styles

---
 tests/ui/UnreadIndicatorsTest.js | 82 ++++++++++++++++----------------
 1 file changed, 42 insertions(+), 40 deletions(-)

diff --git a/tests/ui/UnreadIndicatorsTest.js b/tests/ui/UnreadIndicatorsTest.js
index aede430f9dc0..f9642059ee3d 100644
--- a/tests/ui/UnreadIndicatorsTest.js
+++ b/tests/ui/UnreadIndicatorsTest.js
@@ -298,50 +298,52 @@ describe('Unread Indicators', () => {
                 channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [
                     {
                         eventType: Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE,
-                        data: [{
-                            onyxMethod: Onyx.METHOD.MERGE,
-                            key: `${ONYXKEYS.COLLECTION.REPORT}${NEW_REPORT_ID}`,
-                            value: {
-                                reportID: NEW_REPORT_ID,
-                                reportName: CONST.REPORT.DEFAULT_REPORT_NAME,
-                                lastReadTime: '',
-                                lastVisibleActionCreated: DateUtils.getDBTime(NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.utc().valueOf()),
-                                lastMessageText: 'Comment 1',
-                                participants: [USER_C_EMAIL],
-                                participantAccountIDs: [USER_C_ACCOUNT_ID],
-                            },
-                        },
-                        {
-                            onyxMethod: Onyx.METHOD.MERGE,
-                            key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${NEW_REPORT_ID}`,
-                            value: {
-                                [createdReportActionID]: {
-                                    actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
-                                    automatic: false,
-                                    created: NEW_REPORT_CREATED_MOMENT.format(MOMENT_FORMAT),
-                                    reportActionID: createdReportActionID,
+                        data: [
+                            {
+                                onyxMethod: Onyx.METHOD.MERGE,
+                                key: `${ONYXKEYS.COLLECTION.REPORT}${NEW_REPORT_ID}`,
+                                value: {
+                                    reportID: NEW_REPORT_ID,
+                                    reportName: CONST.REPORT.DEFAULT_REPORT_NAME,
+                                    lastReadTime: '',
+                                    lastVisibleActionCreated: DateUtils.getDBTime(NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.utc().valueOf()),
+                                    lastMessageText: 'Comment 1',
+                                    participants: [USER_C_EMAIL],
+                                    participantAccountIDs: [USER_C_ACCOUNT_ID],
                                 },
-                                [commentReportActionID]: {
-                                    actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
-                                    actorEmail: USER_C_EMAIL,
-                                    actorAccountID: USER_C_ACCOUNT_ID,
-                                    person: [{type: 'TEXT', style: 'strong', text: 'User C'}],
-                                    created: NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.format(MOMENT_FORMAT),
-                                    message: [{type: 'COMMENT', html: 'Comment 1', text: 'Comment 1'}],
-                                    reportActionID: commentReportActionID,
+                            },
+                            {
+                                onyxMethod: Onyx.METHOD.MERGE,
+                                key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${NEW_REPORT_ID}`,
+                                value: {
+                                    [createdReportActionID]: {
+                                        actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
+                                        automatic: false,
+                                        created: NEW_REPORT_CREATED_MOMENT.format(MOMENT_FORMAT),
+                                        reportActionID: createdReportActionID,
+                                    },
+                                    [commentReportActionID]: {
+                                        actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
+                                        actorEmail: USER_C_EMAIL,
+                                        actorAccountID: USER_C_ACCOUNT_ID,
+                                        person: [{type: 'TEXT', style: 'strong', text: 'User C'}],
+                                        created: NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.format(MOMENT_FORMAT),
+                                        message: [{type: 'COMMENT', html: 'Comment 1', text: 'Comment 1'}],
+                                        reportActionID: commentReportActionID,
+                                    },
                                 },
+                                shouldNotify: true,
                             },
-                            shouldNotify: true,
-                        },
-                        {
-                            onyxMethod: Onyx.METHOD.MERGE,
-                            key: ONYXKEYS.PERSONAL_DETAILS_LIST,
-                            value: {
-                                [USER_C_ACCOUNT_ID]: TestHelper.buildPersonalDetails(USER_C_EMAIL, USER_C_ACCOUNT_ID, 'C'),
+                            {
+                                onyxMethod: Onyx.METHOD.MERGE,
+                                key: ONYXKEYS.PERSONAL_DETAILS_LIST,
+                                value: {
+                                    [USER_C_ACCOUNT_ID]: TestHelper.buildPersonalDetails(USER_C_EMAIL, USER_C_ACCOUNT_ID, 'C'),
+                                },
                             },
-                        },
-                    ],
-                }]);
+                        ],
+                    },
+                ]);
                 return waitForPromisesToResolve();
             })
             .then(() => {
