-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[IMPROVEMENT] Request user presence on demand #1813
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ee333f5
[IMPROVEMENT] Users Presence on Demand
djorkaeffalexandre 2f859c1
[FIX] Users presence when authenticated
djorkaeffalexandre 3a3178a
Merge branch 'develop' into new.request-users-on-demand
djorkaeffalexandre ce7bc50
[FIX] Users presence when authenticated
djorkaeffalexandre 7f500f4
Merge Develop
djorkaeffalexandre 8cc01a8
[FIX] Prevent duplicated call
djorkaeffalexandre 667219b
[FIX] Handle case without rendered status
djorkaeffalexandre f255c2c
[FIX] Lint
djorkaeffalexandre 8e0f44c
[FIX] Only request userPresence if have ids
djorkaeffalexandre 434ec14
[FIX] Subscribe stream-notify-logged once
djorkaeffalexandre f367e1e
Merge branch 'develop' into new.request-users-on-demand
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { InteractionManager } from 'react-native'; | ||
| import semver from 'semver'; | ||
|
|
||
| import reduxStore from '../createStore'; | ||
| import { setActiveUsers } from '../../actions/activeUsers'; | ||
|
|
||
| let ids = []; | ||
|
|
||
| export default async function getUsersPresence() { | ||
| const serverVersion = reduxStore.getState().server.version; | ||
|
|
||
| // if server is lower than 1.1.0 | ||
| if (serverVersion && semver.lt(semver.coerce(serverVersion), '1.1.0')) { | ||
| if (this.activeUsersSubTimeout) { | ||
| clearTimeout(this.activeUsersSubTimeout); | ||
| this.activeUsersSubTimeout = false; | ||
| } | ||
| this.activeUsersSubTimeout = setTimeout(() => { | ||
| this.sdk.subscribe('activeUsers'); | ||
| }, 5000); | ||
| } else { | ||
| let params = {}; | ||
|
|
||
| // if server is greather than or equal 3.0.0 | ||
| if (serverVersion && !semver.lt(semver.coerce(serverVersion), '3.0.0')) { | ||
| // if not have any id, only subscribe to changes | ||
| if (!ids.length) { | ||
| this.sdk.subscribe('stream-notify-logged', 'user-status'); | ||
| return; | ||
| } | ||
| // Request userPresence on demand | ||
| params = { ids: ids.join(',') }; | ||
| ids = []; | ||
| } | ||
|
|
||
| // RC 1.1.0 | ||
| const result = await this.sdk.get('users.presence', params); | ||
| if (result.success) { | ||
| const activeUsers = result.users.reduce((ret, item) => { | ||
| ret[item._id] = item.status; | ||
| return ret; | ||
| }, {}); | ||
| InteractionManager.runAfterInteractions(() => { | ||
| reduxStore.dispatch(setActiveUsers(activeUsers)); | ||
| }); | ||
| this.sdk.subscribe('stream-notify-logged', 'user-status'); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let usersTimer = null; | ||
| export function getUserPresence(uid) { | ||
| const auth = reduxStore.getState().login.isAuthenticated; | ||
|
|
||
| if (!usersTimer) { | ||
| usersTimer = setTimeout(() => { | ||
| if (auth && ids.length) { | ||
| getUsersPresence.call(this); | ||
| } | ||
| usersTimer = null; | ||
| }, 2000); | ||
| } | ||
|
|
||
| ids.push(uid); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.