Improve naming
This commit is contained in:
@@ -15,10 +15,10 @@ import {isNative} from '#/platform/detection'
|
|||||||
import {
|
import {
|
||||||
ACTIVE_POLL_INTERVAL,
|
ACTIVE_POLL_INTERVAL,
|
||||||
BACKGROUND_POLL_INTERVAL,
|
BACKGROUND_POLL_INTERVAL,
|
||||||
EXPIRED_TIMEOUT,
|
|
||||||
INACTIVE_POLL_INTERVAL,
|
INACTIVE_POLL_INTERVAL,
|
||||||
INACTIVE_TIMEOUT,
|
INACTIVE_TIMEOUT,
|
||||||
NETWORK_FAILURE_STATUSES,
|
NETWORK_FAILURE_STATUSES,
|
||||||
|
STALE_TIMEOUT,
|
||||||
} from '#/state/messages/convo/const'
|
} from '#/state/messages/convo/const'
|
||||||
import {
|
import {
|
||||||
ConvoDispatch,
|
ConvoDispatch,
|
||||||
@@ -76,7 +76,7 @@ export class Convo {
|
|||||||
|
|
||||||
private isProcessingPendingMessages = false
|
private isProcessingPendingMessages = false
|
||||||
|
|
||||||
private lastActiveTimestamp: number | undefined
|
private lastCommitTimestamp: number | undefined
|
||||||
|
|
||||||
private emitter = new EventEmitter<{event: [ConvoEvent]}>()
|
private emitter = new EventEmitter<{event: [ConvoEvent]}>()
|
||||||
|
|
||||||
@@ -104,8 +104,8 @@ export class Convo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private commit() {
|
private commit() {
|
||||||
this.refreshInactiveTimeout()
|
this.refreshInactivityTimer()
|
||||||
this.updateLastActiveTimestamp()
|
this.lastCommitTimestamp = Date.now()
|
||||||
this.snapshot = undefined
|
this.snapshot = undefined
|
||||||
this.subscribers.forEach(subscriber => subscriber())
|
this.subscribers.forEach(subscriber => subscriber())
|
||||||
}
|
}
|
||||||
@@ -282,7 +282,7 @@ export class Convo {
|
|||||||
case ConvoStatus.Backgrounded: {
|
case ConvoStatus.Backgrounded: {
|
||||||
switch (action.event) {
|
switch (action.event) {
|
||||||
case ConvoDispatchEvent.Resume: {
|
case ConvoDispatchEvent.Resume: {
|
||||||
if (this.wasChatInactive()) {
|
if (this.isChatStale()) {
|
||||||
this.reset()
|
this.reset()
|
||||||
} else {
|
} else {
|
||||||
if (this.convo) {
|
if (this.convo) {
|
||||||
@@ -498,7 +498,7 @@ export class Convo {
|
|||||||
* active polling, and sets up a timeout to back-off polling after a period
|
* active polling, and sets up a timeout to back-off polling after a period
|
||||||
* of inactivity.
|
* of inactivity.
|
||||||
*/
|
*/
|
||||||
private refreshInactiveTimeout() {
|
private refreshInactivityTimer() {
|
||||||
// clears either primary or secondary timeout
|
// clears either primary or secondary timeout
|
||||||
if (this.inactiveTimeout) {
|
if (this.inactiveTimeout) {
|
||||||
clearTimeout(this.inactiveTimeout)
|
clearTimeout(this.inactiveTimeout)
|
||||||
@@ -519,16 +519,9 @@ export class Convo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private isChatStale() {
|
||||||
* Called on any commit, like when the chat is backgrounded. This
|
if (!this.lastCommitTimestamp) return true
|
||||||
* value is then checked on background -> foreground transitions.
|
return Date.now() - this.lastCommitTimestamp > STALE_TIMEOUT
|
||||||
*/
|
|
||||||
private updateLastActiveTimestamp() {
|
|
||||||
this.lastActiveTimestamp = Date.now()
|
|
||||||
}
|
|
||||||
private wasChatInactive() {
|
|
||||||
if (!this.lastActiveTimestamp) return true
|
|
||||||
return Date.now() - this.lastActiveTimestamp > EXPIRED_TIMEOUT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private requestedPollInterval: (() => void) | undefined
|
private requestedPollInterval: (() => void) | undefined
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export const INACTIVE_TIMEOUT = 60e3
|
|||||||
/**
|
/**
|
||||||
* Timeout after which we consider the chat stale and in need of a full reset.
|
* Timeout after which we consider the chat stale and in need of a full reset.
|
||||||
*/
|
*/
|
||||||
export const EXPIRED_TIMEOUT = 60e3 * 5
|
export const STALE_TIMEOUT = 60e3 * 5
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retryable error statuses
|
* Retryable error statuses
|
||||||
|
|||||||
Reference in New Issue
Block a user