-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[Payment Due Oct 1][$250] [#fast-apis] Subscribe guides to a new presence pusher channel #47888
Comments
Job added to Upwork: https://www.upwork.com/jobs/~01fe75f988a6386f2e |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @situchan ( |
ProposalPlease re-state the problem that we are trying to solve in this issue.[#fast-apis] Subscribe guides to a new presence pusher channel What is the root cause of that problem?Improvement. What changes do you think we should make in order to solve the problem?
What alternative solutions did you explore? (Optional)Result |
Edited by proposal-police: This proposal was edited at 2024-08-23 01:43:52 UTC. ProposalPlease re-state the problem that we are trying to solve in this issue.
What is the root cause of that problem?
What changes do you think we should make in order to solve the problem?
function subscribeToActiveGuides() {
Pusher.subscribe(`activeGuides`).catch((error: ReportError) => {
Log.hmmm('[Report] Failed to initially subscribe to Pusher channel');
});
}
function unsubscribeToActiveGuides() {
Pusher.unsubscribe(`activeGuides`);
} the
function ActiveGuidesEventListener({session, allPoliciesEmployeeList}) {
const flatternPoliciesEmployee = flatten(Object.values(allPoliciesEmployeeList));
const didSubscribeToActiveGuides = useRef(false);
useEffect(
() => () => {
const sessionEmail = session.email;
const emailDomain = Str.extractEmailDomain(sessionEmail ?? '');
if (didSubscribeToActiveGuides.current) {
return;
}
if (emailDomain !== CONST.EMAIL.GUIDES_DOMAIN) {
return;
}
if (some(flatternPoliciesEmployee, (user) => user.email === sessionEmail)) {
didSubscribeToActiveGuides.current = true;
subscribeToActiveGuides();
}
},
[session, flatternPoliciesEmployee],
);
return null;
}
export default withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
allPoliciesEmployeeList: {
key: ONYXKEYS.COLLECTION.POLICY,
selector: (policy) => policy.employeeList,
},
})(ActiveGuidesEventListener);
</View>
{didPusherInit && <ActiveGuidesEventListener />} with const [didPusherInit, setDidPusherInit] = useState(false); and we set it to
What alternative solutions did you explore? (Optional)
function ActiveGuidesEventListener({user}) {
const didSubscribeToActiveGuides = useRef(false);
useEffect(
() => () => {
if (didSubscribeToActiveGuides.current) {
return;
}
if (user.isGuide) {
didSubscribeToActiveGuides.current = true;
subscribeToActiveGuides();
}
},
[user],
);
return null;
}
export default withOnyx({
user: {
key: ONYXKEYS.USER,
},
})(ActiveGuidesEventListener);
|
This comment was marked as duplicate.
This comment was marked as duplicate.
@MonilBhavsar In the issue's description you said:
if user has team.expensify.com domain but does not belongs to specific workspace, should we subscribe to the presence pusher channel? |
No, both conditions are required |
Thanks for the proposals! 🚀 |
ProposalPlease re-state the problem that we are trying to solve in this issue.[#fast-apis] Subscribe guides to a new presence pusher channel #47888 What is the root cause of that problem?Guide users are subscribed to a private encrypted user channel only and not subscribed to a presence channel ('presence-activeGuides'). What changes do you think we should make in order to solve the problem?If a user is a guide, i.e. their email is an expensify team email, add a Pusher subscription to a presence channel request (PusherUtils.subscribeToPresenceChannelEvent) to the subscribeToUserEvents function in User (called in AuthScreens after Pusher init). Add a subscribeToPresenceChannelEvent function to Pusher Utils with a Pusher subscribe request. All guides are subscribed to the same presence channel. Subscription to a presence channel adds a members property to the pusher socket, which includes a members count. App/src/libs/Navigation/AppNavigator/AuthScreens.tsx Lines 254 to 262 in a29977b
Add a PusherUtils.subscribeToPresenceChannelEvent request just after PusherUtils.subscribeToPrivateUserChannelEvent. Lines 660 to 674 in a29977b
Add a subscribeToPresenceChannelEvent function just after subscribeToPrivateUserChannelEvent. Lines 29 to 31 in a29977b
Include a Pusher.subscribe request in the subscribeToPresenceChannelEvent function with channel name 'presence-activeGuides'. Line 48 in a29977b
What alternative solutions did you explore? (Optional)N/A |
@MonilBhavsar, @situchan Whoops! This issue is 2 days overdue. Let's get this updated quick! |
Thanks for the proposals. I think @Krishna2323's solution is the most simple, though the logic to check if user is guide or not is missing. And unsubscribe logic is also not clear. @daledah introducing new component is fine but I doubt subscribeToActiveGuides() is called before pusher init is complete. App/src/libs/Navigation/AppNavigator/AuthScreens.tsx Lines 254 to 262 in a29977b
@mariapeever I don't see any meaningful difference from @Krishna2323's proposal. |
|
@daledah thanks. What is the benefit of introducing new ActiveGuidesEventListener? Can't we just subscribe after subscribeToUserEvents()? |
As mentioned in the OP's description, we just want to subscribe to a new presence pusher channel if they have a team.expensify.com domain and belong to a specific policyID. If we subscribe after subscribeToUserEvents(), it will subscribe to presence channel even if user is not in any policy. |
Ofc we'll check if user belongs to specific policy |
Yeah. If we subscribe after subscribeToUserEvents(), we cannot check if user belongs to specific policy, right? |
@situchan, I think we are already disconnecting from the socket when the
App/src/libs/actions/Session/index.ts Lines 698 to 701 in d4d1c0c
|
Makes sense. We may need to connect ONYXKEYS.COLLECTION.POLICY in AuthScreens @Krishna2323 what about this concern? |
I'm not sure why we can't check if user belongs to specific policy, can you please help me understand? Can't we get the policy using |
@Krishna2323 pusher init is called on AuthScreens component mount |
@MonilBhavsar PR is up. |
Okay, this PR was deployed to production. I'll add a label to assign bug-zero team member to issue payment next week |
Triggered auto assignment to @trjExpensify ( |
|
Triggered auto assignment to Design team member for new feature review - @dannymcclain ( |
@dannymcclain sorry for the ping. This was just to issue the payment :D |
Wonderful! |
@trjExpensify, @MonilBhavsar, @situchan, @daledah Whoops! This issue is 2 days overdue. Let's get this updated quick! |
(Great timing, Melv). |
@trjExpensify looks like |
@trjExpensify Thank you I accepted the offer |
@daledah paid, closing! |
Context:
Guides are agents who help new customers with onboarding.
We use Pusher to send real time updates.
We have a private user channel here
App/src/CONST.ts
Line 1154 in f7d8e48
private-encrypted-user-accountID-<>
that is used to receive various events in real time like onyx updates, user typing and more.Problem
Pusher private channel is dynamic, or unique for each user as it contains an accountID.
For example: A channel name could look like
private-encrypted-user-accountID-5-b8645604fe014e82b765ca84b7df1f2e
At the server side, if we want to know how many guides are online at the current time, then we need to make an API call to each pusher channel and see if it is occupied or not.
If we have 20 guides, then we make 20 API calls to check guide's presence, which is not efficient.
Solution
Make guides subscribe to a presence channel -
activeGuides
https://pusher.com/docs/channels/using_channels/presence-channels/
With this, a server only will have to make one API call to find all active guides or users subscribed to this channel.
If a user is a guide - i.e. have a
team.expensify.com
domain and belongs to a specific policyID, then we additionally subscribe guide to the the guides presence channel.Like the private user channel, a subscription to the channel should indicate guide's presence in the app - They should be subscribed if they login and are active, and should be unsubscribed if they sign out.
We probably have most of the code and logic for the private user channel. We need to similarly subscribe guides to the new channel.
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @trjExpensifyThe text was updated successfully, but these errors were encountered: