Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract activity related code into activityManager
- Loading branch information
1 parent
9ff1733
commit 8a861c6
Showing
10 changed files
with
73 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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,41 @@ | ||
import { | ||
AppState, | ||
} from 'react-native'; | ||
import throttle from 'lodash.throttle'; | ||
|
||
import { focusPing } from '../api'; | ||
import { Auth } from '../api/apiFetch'; | ||
|
||
// Send once per minute. | ||
// Send when restored from suspended state | ||
// Send on new compose message | ||
// Send on new narrow event | ||
|
||
export default class ActivityManager { | ||
|
||
auth: Auth; | ||
|
||
constructor(auth: Auth) { | ||
this.auth = auth; | ||
|
||
AppState.addEventListener('change', this.handleAppStateChange); | ||
} | ||
|
||
// componentWillUnmount() { | ||
// AppState.removeEventListener('change', this.handleAppStateChange); | ||
// } | ||
|
||
appActivity() { | ||
throttle(() => focusPing(this.props.auth, true, false), 1000 * 60); | ||
} | ||
|
||
userInputActivity() { | ||
throttle(() => focusPing(this.props.auth, true, false), 1000 * 5); | ||
} | ||
|
||
handleAppStateChange = (currentAppState) => { | ||
if (currentAppState === 'active') { | ||
this.appActivity(); | ||
} | ||
} | ||
} |
This file contains 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