Skip to content

Commit

Permalink
Merge pull request #18752 from Expensify/tgolen-remove-old-pusherevents
Browse files Browse the repository at this point in the history
Remove old single pusher events
  • Loading branch information
yuwenmemon authored Jul 13, 2023
2 parents 9ef57bc + ebe00b9 commit 92ecd6b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 73 deletions.
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.
// 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

0 comments on commit 92ecd6b

Please sign in to comment.