Reset after 5 min (#4026)
This commit is contained in:
parent
6efe90a5f5
commit
6382fec732
2 changed files with 27 additions and 7 deletions
|
@ -13,6 +13,7 @@ import {isNative} from '#/platform/detection'
|
||||||
import {
|
import {
|
||||||
ACTIVE_POLL_INTERVAL,
|
ACTIVE_POLL_INTERVAL,
|
||||||
BACKGROUND_POLL_INTERVAL,
|
BACKGROUND_POLL_INTERVAL,
|
||||||
|
INACTIVE_TIMEOUT,
|
||||||
} from '#/state/messages/convo/const'
|
} from '#/state/messages/convo/const'
|
||||||
import {
|
import {
|
||||||
ConvoDispatch,
|
ConvoDispatch,
|
||||||
|
@ -79,6 +80,8 @@ export class Convo {
|
||||||
|
|
||||||
private isProcessingPendingMessages = false
|
private isProcessingPendingMessages = false
|
||||||
|
|
||||||
|
private lastActiveTimestamp: number | undefined
|
||||||
|
|
||||||
convoId: string
|
convoId: string
|
||||||
convo: ChatBskyConvoDefs.ConvoView | undefined
|
convo: ChatBskyConvoDefs.ConvoView | undefined
|
||||||
sender: AppBskyActorDefs.ProfileViewBasic | undefined
|
sender: AppBskyActorDefs.ProfileViewBasic | undefined
|
||||||
|
@ -272,8 +275,10 @@ export class Convo {
|
||||||
}
|
}
|
||||||
case ConvoStatus.Backgrounded: {
|
case ConvoStatus.Backgrounded: {
|
||||||
switch (action.event) {
|
switch (action.event) {
|
||||||
// TODO truncate history if needed
|
|
||||||
case ConvoDispatchEvent.Resume: {
|
case ConvoDispatchEvent.Resume: {
|
||||||
|
if (this.wasChatInactive()) {
|
||||||
|
this.reset()
|
||||||
|
} else {
|
||||||
if (this.convo) {
|
if (this.convo) {
|
||||||
this.status = ConvoStatus.Ready
|
this.status = ConvoStatus.Ready
|
||||||
this.refreshConvo()
|
this.refreshConvo()
|
||||||
|
@ -282,6 +287,7 @@ export class Convo {
|
||||||
this.setup()
|
this.setup()
|
||||||
}
|
}
|
||||||
this.requestPollInterval(ACTIVE_POLL_INTERVAL)
|
this.requestPollInterval(ACTIVE_POLL_INTERVAL)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ConvoDispatchEvent.Suspend: {
|
case ConvoDispatchEvent.Suspend: {
|
||||||
|
@ -354,6 +360,7 @@ export class Convo {
|
||||||
logger.DebugContext.convo,
|
logger.DebugContext.convo,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.updateLastActiveTimestamp()
|
||||||
this.commit()
|
this.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,6 +443,18 @@ export class Convo {
|
||||||
DEBUG_ACTIVE_CHAT = undefined
|
DEBUG_ACTIVE_CHAT = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on any state transition, like when the chat is backgrounded. This
|
||||||
|
* value is then checked on background -> foreground transitions.
|
||||||
|
*/
|
||||||
|
private updateLastActiveTimestamp() {
|
||||||
|
this.lastActiveTimestamp = Date.now()
|
||||||
|
}
|
||||||
|
private wasChatInactive() {
|
||||||
|
if (!this.lastActiveTimestamp) return true
|
||||||
|
return Date.now() - this.lastActiveTimestamp > INACTIVE_TIMEOUT
|
||||||
|
}
|
||||||
|
|
||||||
private requestedPollInterval: (() => void) | undefined
|
private requestedPollInterval: (() => void) | undefined
|
||||||
private requestPollInterval(interval: number) {
|
private requestPollInterval(interval: number) {
|
||||||
this.withdrawRequestedPollInterval()
|
this.withdrawRequestedPollInterval()
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
export const ACTIVE_POLL_INTERVAL = 1e3
|
export const ACTIVE_POLL_INTERVAL = 1e3
|
||||||
export const BACKGROUND_POLL_INTERVAL = 5e3
|
export const BACKGROUND_POLL_INTERVAL = 5e3
|
||||||
|
export const INACTIVE_TIMEOUT = 60e3 * 5
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue