This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 827
Fix instantly sending RRs #2770
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ce16236
Fix instantly sending RRs
dbkr 61ebf4d
spurious semicolon
dbkr 7e424ce
Fix call to stop()
dbkr b404d21
PR feedback
dbkr 999ebe6
Missed the removes
dbkr ce9f3d8
Rename
dbkr 63d19a8
Rest of the naming changes
dbkr ea01853
Rename
jryans 2d074d0
Rename
jryans 08e21ff
Fix comment
dbkr 374be0b
Rename more things
dbkr 9f4de60
Merge branch 'dbkr/fix_instant_rrs_pt2' of github.com:matrix-org/matr…
dbkr 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 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 |
---|---|---|
|
@@ -34,8 +34,8 @@ const CURRENTLY_PASSIVE_THRESHOLD_MS = 2 * 60 * 1000; | |
* This class watches for user activity (moving the mouse or pressing a key) | ||
* and starts/stops attached timers while the user is active. | ||
* | ||
* There are two classes of 'active' a user can be: 'active' and 'passive': | ||
* see doc on the userCurrently* functions for what these mean. | ||
* There are two classes of 'active': 'active now' and 'active recently' | ||
* see doc on the userActive* functions for what these mean. | ||
*/ | ||
export default class UserActivity { | ||
constructor(windowObj, documentObj) { | ||
|
@@ -44,8 +44,8 @@ export default class UserActivity { | |
|
||
this._attachedTimersActive = []; | ||
this._attachedTimersPassive = []; | ||
this._activeTimeout = new Timer(CURRENTLY_ACTIVE_THRESHOLD_MS); | ||
this._passiveTimeout = new Timer(CURRENTLY_PASSIVE_THRESHOLD_MS); | ||
this._activeNowTimeout = new Timer(CURRENTLY_ACTIVE_THRESHOLD_MS); | ||
this._activeRecentlyTimeout = new Timer(CURRENTLY_PASSIVE_THRESHOLD_MS); | ||
this._onUserActivity = this._onUserActivity.bind(this); | ||
this._onWindowBlurred = this._onWindowBlurred.bind(this); | ||
this._onPageVisibilityChanged = this._onPageVisibilityChanged.bind(this); | ||
|
@@ -61,32 +61,33 @@ export default class UserActivity { | |
} | ||
|
||
/** | ||
* Runs the given timer while the user is 'active', aborting when the user becomes 'passive'. | ||
* See userCurrentlyActive() for what it means for a user to be 'active'. | ||
* Runs the given timer while the user is 'active', aborting when the user is no longer | ||
* considered currently active. | ||
* See userActiveNow() for what it means for a user to be 'active'. | ||
* Can be called multiple times with the same already running timer, which is a NO-OP. | ||
* Can be called before the user becomes active, in which case it is only started | ||
* later on when the user does become active. | ||
* @param {Timer} timer the timer to use | ||
*/ | ||
timeWhileActive(timer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, shouldn't we carry the new naming through to this API as well? We'd then have |
||
this._timeWhile(timer, this._attachedTimersActive); | ||
if (this.userCurrentlyActive()) { | ||
if (this.userActiveNow()) { | ||
timer.start(); | ||
} | ||
} | ||
|
||
/** | ||
* Runs the given timer while the user is 'active' or 'passive', aborting when the user becomes | ||
* inactive. | ||
* See userCurrentlyPassive() for what it means for a user to be 'passive'. | ||
* Runs the given timer while the user is 'active' now or recently, | ||
* aborting when the user becomes inactive. | ||
* See userActiveRecently() for what it means for a user to be 'active recently'. | ||
* Can be called multiple times with the same already running timer, which is a NO-OP. | ||
* Can be called before the user becomes active, in which case it is only started | ||
* later on when the user does become active. | ||
* @param {Timer} timer the timer to use | ||
*/ | ||
timeWhilePassive(timer) { | ||
this._timeWhile(timer, this._attachedTimersPassive); | ||
if (this.userCurrentlyPassive()) { | ||
if (this.userActiveRecently()) { | ||
timer.start(); | ||
} | ||
} | ||
|
@@ -150,33 +151,34 @@ export default class UserActivity { | |
* user's attention at any given moment. | ||
* @returns {boolean} true if user is currently 'active' | ||
*/ | ||
userCurrentlyActive() { | ||
return this._activeTimeout.isRunning(); | ||
userActiveNow() { | ||
return this._activeNowTimeout.isRunning(); | ||
} | ||
|
||
/** | ||
* Return true if the user is currently 'active' or 'passive' | ||
* A user is 'passive' for a longer period of time (~2 mins) after they have been 'active' and | ||
* while the app still has the focus. This is intended to indicate when the app may still have | ||
* the user's attention (or they may have gone to make tea and left the window focused). | ||
* @returns {boolean} true if user is currently 'active' or 'passive' | ||
* Return true if the user is currently active or has been recently | ||
* A user is 'active recently' for a longer period of time (~2 mins) after | ||
* they have been 'active' and while the app still has the focus. This is | ||
* intended to indicate when the app may still have the user's attention | ||
* (or they may have gone to make tea and left the window focused). | ||
* @returns {boolean} true if user has been active recently | ||
*/ | ||
userCurrentlyPassive() { | ||
return this._passiveTimeout.isRunning(); | ||
userActiveRecently() { | ||
return this._activeRecentlyTimeout.isRunning(); | ||
} | ||
|
||
_onPageVisibilityChanged(e) { | ||
if (this._document.visibilityState === "hidden") { | ||
this._activeTimeout.abort(); | ||
this._passiveTimeout.abort(); | ||
this._activeNowTimeout.abort(); | ||
this._activeRecentlyTimeout.abort(); | ||
} else { | ||
this._onUserActivity(e); | ||
} | ||
} | ||
|
||
_onWindowBlurred() { | ||
this._activeTimeout.abort(); | ||
this._passiveTimeout.abort(); | ||
this._activeNowTimeout.abort(); | ||
this._activeRecentlyTimeout.abort(); | ||
} | ||
|
||
_onUserActivity(event) { | ||
|
@@ -193,21 +195,21 @@ export default class UserActivity { | |
} | ||
|
||
dis.dispatch({action: 'user_activity'}); | ||
jryans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!this._activeTimeout.isRunning()) { | ||
this._activeTimeout.start(); | ||
if (!this._activeNowTimeout.isRunning()) { | ||
this._activeNowTimeout.start(); | ||
dis.dispatch({action: 'user_activity_start'}); | ||
|
||
this._runTimersUntilTimeout(this._attachedTimersActive, this._activeTimeout); | ||
this._runTimersUntilTimeout(this._attachedTimersActive, this._activeNowTimeout); | ||
} else { | ||
this._activeTimeout.restart(); | ||
this._activeNowTimeout.restart(); | ||
} | ||
|
||
if (!this._passiveTimeout.isRunning()) { | ||
this._passiveTimeout.start(); | ||
if (!this._activeRecentlyTimeout.isRunning()) { | ||
this._activeRecentlyTimeout.start(); | ||
|
||
this._runTimersUntilTimeout(this._attachedTimersPassive, this._passiveTimeout); | ||
this._runTimersUntilTimeout(this._attachedTimersPassive, this._activeRecentlyTimeout); | ||
} else { | ||
this._passiveTimeout.restart(); | ||
this._activeRecentlyTimeout.restart(); | ||
} | ||
} | ||
|
||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These thresholds should likely also be renamed to match as well.