Repository navigation
Pusher suffix for internal devs - #8796
Conversation
|
@Beamanator can you check whether this is the direction we want to go - add a value to Some contextReading There's no easy way to update metro config to include and set a The easiest thing to do to expose |
kidroca
left a comment
There was a problem hiding this comment.
Added some notes on the changes
| */ | ||
| function subscribeToPrivateUserChannelEvent(eventName, onEvent, isChunked = false) { | ||
| const pusherChannelName = `private-user-accountID-${currentUserAccountID}`; | ||
| const pusherChannelName = `private-user-accountID-${currentUserAccountID}${CONFIG.PUSHER.SUFFIX}`; |
There was a problem hiding this comment.
Maybe we can introduce a method Pusher.subscribeToPrivateChannel so we have a only one place where we combine ${channelName}${CONFIG.PUSHER.SUFFIX}
There was a problem hiding this comment.
In the near future we're going to encrypt the user channel (private-encrypted) but the report channel will remain private. I like the idea of adding ${CONFIG.PUSHER.SUFFIX} in one place instead of all these files, maybe a different function name like Pusher.prepareChannelName or something generic just about the channel name?
There was a problem hiding this comment.
yeah, I'm just not sure where to put it, should it be part of Pusher or not
For example there's Pusher.init where we pass values from CONFIG.js so it seems importing CONFIG.js directly in Pusher was deliberately avoided
But if we are to create a method like Pusher.prepareChannelName we'll have to import CONFIG.js to pusher
There was a problem hiding this comment.
True true, looks like @tgolen made those changes, though it was a long time ago. I can't see why we wouldn't want to import Config into Pusher since we import Config into lots of other places 🤔
There was a problem hiding this comment.
I don't think there is much harm in importing CONFIG.js. I think it was at one point helpful to have it with fewer dependencies because some of this code I think originally came from OldDot. I would still be in favor of keeping it low on dependencies, and then having a method for getChannelName() which can add the suffix if it needs to.
There was a problem hiding this comment.
Ok so it sounds like you're good to add the new method to Pusher 👍
Edit: We'll refactor in a different PR
Co-authored-by: Alex Beaman <dabeamanator@gmail.com>
kidroca
left a comment
There was a problem hiding this comment.
Extracted Pusher channel names to CONST
Added a Pusher.getChannelName method
✔️ Ready for Review
| function getChannelName(...parts) { | ||
| return _.chain([...parts, CONFIG.PUSHER.SUFFIX]) | ||
| .filter(Boolean) | ||
| .join('-') | ||
| .value(); |
There was a problem hiding this comment.
Perhaps this should be named to getPrivateChannelName because I saw an instance that does not use the Pusher suffix (for the policy editor channel)
Or maybe we could try to make the logic "smarter" and try to append suffix only if any of the parts includes the word "private"?
Regarding the dash:
Onyx collection keys include the -inside the key name, perhaps you'd like the same here, though filtering out empty keys would require more logic
There was a problem hiding this comment.
I like the idea of this being getPrivateChannelName() 👍
Onyx collection keys include the -inside the key name, perhaps you'd like the same here, though filtering out empty keys would require more logic
I'm not really following this and what changes it would imply. What do the parts in the pusher channel name have to do with Onyx collection keys?
There was a problem hiding this comment.
Hm, I actually don't particularly like having the dash automatically derived in this code. I think it makes it trickier to keep the channels names in PHP in sync with the channel names in JS. I would propose that this function is more like this:
function getChannelNameWithSuffix(name) {
return `${name}-${CONFIG.PUSHER.SUFFIX}`;
}
There was a problem hiding this comment.
I'm not really following this and what changes it would imply. What do the parts in the pusher channel name have to do with Onyx collection keys?
It's only about dashes and concatenation, do we have a preference to include the dash in the key (like in Onyx keys) or not?
Onyx keys
Lines 99 to 103 in d1f3643
Usage (no dash in concatenation)
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, actionsToRemove);Following that pattern we can name Pusher channels like so:
PUSHER_CHANNEL: {
USER: 'private-user-accountID-',
REPORT: 'private-report-reportID-',
POLICY_EDITOR: 'public-policyEditor-',
},There was a problem hiding this comment.
Hm, I actually don't particularly like having the dash automatically derived in this code. I think it makes it trickier to keep the channels names in PHP in sync with the channel names in JS.
In that case maybe extracting names to CONST and a getName function is only getting in the way, can we stick with this?
const channelName = `private-user-accountID-${accountID}-${CONFIG.PUSHER.SUFFIX}`
Pusher.subscribe(channelName);I'll drop these changes and perhaps we can open a separate refactoring PR if needed
| "ipad-sm": "npm run check-metro-bundler-port && react-native run-ios --simulator=\"iPad Pro (9.7-inch)\"", | ||
| "start": "react-native start", | ||
| "web": "node web/proxy.js & webpack-dev-server --open --config config/webpack/webpack.dev.js", | ||
| "web": "concurrently npm:web-proxy npm:web-server", |
There was a problem hiding this comment.
How does dev.sh get ran in this instance?
There was a problem hiding this comment.
How does
dev.shget ran in this instance?
It's part of the web-server script
|
|
||
| SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}") | ||
|
|
||
| bash "$SCRIPTS_DIR/set-pusher-suffix.sh" |
There was a problem hiding this comment.
Why have this split up into separate files if this is all it does? Let's just put it all in one file if we can.
There was a problem hiding this comment.
The idea for dev.sh is to host a list of scripts we run before starting local development
If that's undesired, I'll just delete it and use set-pusher-suffix.sh directly
| */ | ||
| function getChannelName(...parts) { | ||
| return _.chain([...parts, CONFIG.PUSHER.SUFFIX]) | ||
| .filter(Boolean) |
There was a problem hiding this comment.
Is this doing something different than _.compact() would? I'd prefer _.compact() if it's just to remove falsy values.
| function getChannelName(...parts) { | ||
| return _.chain([...parts, CONFIG.PUSHER.SUFFIX]) | ||
| .filter(Boolean) | ||
| .join('-') | ||
| .value(); |
There was a problem hiding this comment.
I like the idea of this being getPrivateChannelName() 👍
Onyx collection keys include the -inside the key name, perhaps you'd like the same here, though filtering out empty keys would require more logic
I'm not really following this and what changes it would imply. What do the parts in the pusher channel name have to do with Onyx collection keys?
| } | ||
|
|
||
| /** | ||
| * Combines channel parts and adds Pusher suffix when necessary |
There was a problem hiding this comment.
| * Combines channel parts and adds Pusher suffix when necessary | |
| * Combines all parts into the channel name (separated by a dash) and puts the Pusher suffix on the end |
| function getChannelName(...parts) { | ||
| return _.chain([...parts, CONFIG.PUSHER.SUFFIX]) | ||
| .filter(Boolean) | ||
| .join('-') | ||
| .value(); |
There was a problem hiding this comment.
Hm, I actually don't particularly like having the dash automatically derived in this code. I think it makes it trickier to keep the channels names in PHP in sync with the channel names in JS. I would propose that this function is more like this:
function getChannelNameWithSuffix(name) {
return `${name}-${CONFIG.PUSHER.SUFFIX}`;
}
acc63a2 to
53f2ca0
Compare
|
I've reverted the refactoring work out of this PR since it's not essential to the feature - it seems raw concatenation is preferable in order to keep php and js channel names in sync We can open a separate PR to refactor |
|
I like the idea of doing the refactor in a separate PR to keep changes specific. Can you also add the pusher suffix to the |
Beamanator
left a comment
There was a problem hiding this comment.
Could you please add this comment & the suffix to the policyEditor channel? Then I think we're good to go
Sure, I thought it was intentionally left out Maybe in the future the suffix can be fetched as a param after login? |
✔️ Done & done |
7ae4149 to
1e04d06
Compare
Beamanator
left a comment
There was a problem hiding this comment.
Looks great, thanks for the great work as always @kidroca 💪
I'm going to hold off merging till another Internal PR goes through (hopefully today)
|
npm has a |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
Heh, yeah. I just ran into that. Oops! |
|
Thanks for fixing @kidroca ! 🙏 |
|
🚀 Cherry-picked to staging by @sketchydroide in version: 1.1.57-8 🚀
@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes. |
|
🚀 Deployed to production by @chiragsalian in version: 1.1.57-17 🚀
|

Details
Reads pusher suffix from local php config (in external sibling folder project)
Exposes it to
.envso it's available inCONFIG.js_config.local.phpfile (Expensify employees only) & append to pusher channel names #8727Fixed Issues
$ https://github.com/Expensify/Expensify/issues/207393
Tests
console.logit fromsrc/CONFIG.js''for production and staging buildsSample local dev output
PR Review Checklist
Contributor (PR Author) Checklist
### Fixed Issuessection aboveTestssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*filesSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */displayNamepropertythisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris working as expected in all cases)PR Reviewer Checklist
### Fixed Issuessection aboveTestssectionQA stepssectiontoggleReportand notonIconClick).src/languages/*filesSTYLE.md) were followed/** comment above it */displayNamepropertythisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris working as expected in all cases)QA Steps
Verify production or staging are unaffected.
The changes here should apply only to local development. Sending/receiving reports and "user typing" events should be be working without regressions
Screenshots
Web
Mobile Web
Desktop
iOS
Android
cc @Beamanator