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

Remove old single pusher events #18752

Merged
merged 14 commits into from
Jul 13, 2023
40 changes: 6 additions & 34 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,12 @@ 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() {
// 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    // If we don't have the user's accountID yet we can't subscribe so return early
    if (!currentUserAccountID) {
        return;
    }

Should we early return if currentUserAccountID not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we should.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's add that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, hahaha, I thought it was still there in the code. I didn't realize I had removed it, so I was a little confused about your first question :D I'll add it back in

// Each single event is passed to PusherUtils in order to trigger the callbacks for that event
PusherUtils.subscribeToPrivateUserChannelEvent(Pusher.TYPE.MULTIPLE_EVENTS, currentUserAccountID, (pushJSON) => {
Expand All @@ -585,39 +590,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(() => {
// 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;
}
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
Expand Down
81 changes: 43 additions & 38 deletions tests/ui/UnreadIndicatorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,47 +295,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, [
channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [
{
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,
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],
},
},
[commentReportActionID]: {
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
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,
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();
Expand Down
7 changes: 6 additions & 1 deletion tests/utils/PusherHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ 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() {
Expand Down
Loading