mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 21:53:07 -04:00
[nextgen/cardstack] use component listener to handle timeout (avoids desync issues)
This commit is contained in:
parent
c5d49cf0f7
commit
7c4e952b2f
2 changed files with 8 additions and 35 deletions
|
@ -29,6 +29,7 @@ module.exports = {
|
||||||
pageNumberGenerator: (pg)=>{
|
pageNumberGenerator: (pg)=>{
|
||||||
return `Test ${pg.index}`
|
return `Test ${pg.index}`
|
||||||
},
|
},
|
||||||
|
expires: 10000,
|
||||||
interactive: {
|
interactive: {
|
||||||
always_active_button: {
|
always_active_button: {
|
||||||
type: InteractiveComponentTypes.BUTTON,
|
type: InteractiveComponentTypes.BUTTON,
|
||||||
|
|
|
@ -63,6 +63,7 @@ class DynamicCardStack {
|
||||||
this.ephemeral = options.ephemeral || false;
|
this.ephemeral = options.ephemeral || false;
|
||||||
|
|
||||||
this.rootIndex = this.index;
|
this.rootIndex = this.index;
|
||||||
|
this.killed = false;
|
||||||
|
|
||||||
this.stackCache = {};
|
this.stackCache = {};
|
||||||
this.pageState = [];
|
this.pageState = [];
|
||||||
|
@ -70,11 +71,6 @@ class DynamicCardStack {
|
||||||
|
|
||||||
this.currentComponentsBatch = {};
|
this.currentComponentsBatch = {};
|
||||||
|
|
||||||
/*
|
|
||||||
this.lastInteraction = Date.now();
|
|
||||||
this.spawned = 0;
|
|
||||||
*/
|
|
||||||
|
|
||||||
return this._spawn();
|
return this._spawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +78,10 @@ class DynamicCardStack {
|
||||||
* Kills the dynamic card stack.
|
* Kills the dynamic card stack.
|
||||||
*/
|
*/
|
||||||
async kill(clearComponents) {
|
async kill(clearComponents) {
|
||||||
clearTimeout(this.timeout);
|
|
||||||
|
|
||||||
this.listener.clear();
|
this.listener.clear();
|
||||||
if (clearComponents) await this._edit(this.getCurrentCard(), [])
|
if (clearComponents && !this.killed) await this._edit(this.getCurrentCard(), [])
|
||||||
|
|
||||||
|
this.killed = true;
|
||||||
|
|
||||||
// Remove reference to free the cardstack for GC
|
// Remove reference to free the cardstack for GC
|
||||||
activeStacks.delete(this.context.message || this.context.interaction);
|
activeStacks.delete(this.context.message || this.context.interaction);
|
||||||
|
@ -115,29 +111,6 @@ class DynamicCardStack {
|
||||||
activeStacks.set(this.context.message || this.context.interaction, this);
|
activeStacks.set(this.context.message || this.context.interaction, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a timeout for the paginator.
|
|
||||||
* TODO: make this work properly
|
|
||||||
* @returns {number} Timeout
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_createTimeout() {
|
|
||||||
return setTimeout(async () => {
|
|
||||||
/*
|
|
||||||
// This currently isn't doable with our Components listener.
|
|
||||||
if(this.spawned - this.lastInteraction <= this.expires){
|
|
||||||
clearTimeout(this.timeout)
|
|
||||||
this.spawned = Date.now();
|
|
||||||
// New expiry time is 30 seconds
|
|
||||||
this.expires = 30*1000;
|
|
||||||
this.timeout = this._createTimeout();
|
|
||||||
} else {
|
|
||||||
this.kill(true);
|
|
||||||
}*/
|
|
||||||
await this.kill(true);
|
|
||||||
}, this.expires)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new cardstack in the given channel
|
* Creates a new cardstack in the given channel
|
||||||
* @private
|
* @private
|
||||||
|
@ -156,13 +129,12 @@ class DynamicCardStack {
|
||||||
onError: (e) => {
|
onError: (e) => {
|
||||||
console.error("Component Handler Exception:")
|
console.error("Component Handler Exception:")
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
},
|
||||||
|
onTimeout: (e)=> {
|
||||||
|
this.kill(true);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.timeout = this._createTimeout()
|
|
||||||
|
|
||||||
//this.spawned = Date.now()
|
|
||||||
|
|
||||||
if (createMessage) return this._edit({
|
if (createMessage) return this._edit({
|
||||||
...this.getCurrentCard(),
|
...this.getCurrentCard(),
|
||||||
components: this.listener
|
components: this.listener
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue