[MM-33600, MM-34679] Apps commands invalidate form cache (#5333)

* invalidate parser form cache on channel navigate and when changing commands

* lint

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
Michael Kochell 2021-08-13 15:57:03 -04:00 committed by GitHub
parent f7eecacccb
commit 6e35286051
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -912,6 +912,9 @@ export class AppCommandParser {
}
setChannelContext = (channelID: string, rootPostID?: string) => {
if (this.channelID !== channelID || this.rootPostID !== rootPostID) {
this.forms = {};
}
this.channelID = channelID;
this.rootPostID = rootPostID;
}
@ -1000,14 +1003,17 @@ export class AppCommandParser {
}
getForm = async (location: string, binding: AppBinding): Promise<{form?: AppForm; error?: string} | undefined> => {
const form = this.forms[location];
const rootID = this.rootPostID || '';
const key = `${this.channelID}-${rootID}-${location}`;
const form = this.forms[key];
if (form) {
return {form};
}
this.forms = {};
const fetched = await this.fetchForm(binding);
if (fetched?.form) {
this.forms[location] = fetched.form;
this.forms[key] = fetched.form;
}
return fetched;
}