diff --git a/vocodes/src/App.tsx b/vocodes/src/App.tsx index 819cbd1749..beb9d91ca2 100644 --- a/vocodes/src/App.tsx +++ b/vocodes/src/App.tsx @@ -67,7 +67,7 @@ class App extends React.Component { componentDidMount() { this.querySession(); - setInterval(() => { this.querySession() }, 10000); + setInterval(() => { this.querySession() }, 60000); // TODO: Use websockets, this is dumb setInterval(() => { this.pollJobs() }, 1000); //this.state.videoJobPoller.start(); diff --git a/vocodes/src/session/SessionState.ts b/vocodes/src/session/SessionState.ts index 71d2e3fca0..76774d622c 100644 --- a/vocodes/src/session/SessionState.ts +++ b/vocodes/src/session/SessionState.ts @@ -8,7 +8,7 @@ export interface SessionStateResponse { logged_in: boolean, // Extended user details (only if logged in) - user?: UserInfo, + user: UserInfo | undefined | null, } export interface UserInfo { diff --git a/vocodes/src/session/SessionWrapper.ts b/vocodes/src/session/SessionWrapper.ts index 6ef65966f2..771af23180 100644 --- a/vocodes/src/session/SessionWrapper.ts +++ b/vocodes/src/session/SessionWrapper.ts @@ -51,51 +51,30 @@ export class SessionWrapper { } public canUseTts() : boolean { - if (this.sessionStateResponse === undefined || this.sessionStateResponse.user === undefined) { - return true; // NB: Default true. - } - return this.sessionStateResponse.user.can_use_tts; + return this.sessionStateResponse?.user?.can_use_tts || true; // NB: Default true. } public canUseW2l() : boolean { - if (this.sessionStateResponse === undefined || this.sessionStateResponse.user === undefined) { - return true; // NB: Default true. - } - return this.sessionStateResponse.user.can_use_w2l; + return this.sessionStateResponse?.user?.can_use_w2l || true; // NB: Default true } public canUploadTtsModels() : boolean { - if (this.sessionStateResponse === undefined || this.sessionStateResponse.user === undefined) { - return false; - } - return this.sessionStateResponse.user.can_upload_tts_models; + return this.sessionStateResponse?.user?.can_upload_tts_models || false; } public canUploadW2lTemplates() : boolean { - if (this.sessionStateResponse === undefined || this.sessionStateResponse.user === undefined) { - return false; - } - return this.sessionStateResponse.user.can_upload_w2l_templates; + return this.sessionStateResponse?.user?.can_upload_w2l_templates || false; } public canBanUsers() : boolean { - if (this.sessionStateResponse === undefined || this.sessionStateResponse.user === undefined) { - return false; - } - return this.sessionStateResponse.user.can_ban_users; + return this.sessionStateResponse?.user?.can_ban_users || false; } public canEditOtherUsersData() : boolean { - if (this.sessionStateResponse === undefined || this.sessionStateResponse.user === undefined) { - return false; - } - return this.sessionStateResponse.user.can_edit_other_users_data; + return this.sessionStateResponse?.user?.can_edit_other_users_data || false; } public canApproveW2lTemplates() : boolean { - if (this.sessionStateResponse === undefined || this.sessionStateResponse.user === undefined) { - return false; - } - return this.sessionStateResponse.user.can_approve_w2l_templates; + return this.sessionStateResponse?.user?.can_approve_w2l_templates || false; } }