mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { CommunityHandshakeState, CommunityHandshakeStateType } from 'database'
|
|
import { FEDERATION_AUTHENTICATION_TIMEOUT_MS } from 'shared'
|
|
|
|
export class CommunityHandshakeStateLogic {
|
|
public constructor(private self: CommunityHandshakeState) {}
|
|
|
|
/**
|
|
* Check for expired state and if not, check timeout and update (write into db) to expired state
|
|
* @returns true if the community handshake state is expired
|
|
*/
|
|
public async isTimeoutUpdate(): Promise<boolean> {
|
|
const timeout = this.isTimeout()
|
|
if (timeout && this.self.status !== CommunityHandshakeStateType.EXPIRED) {
|
|
this.self.status = CommunityHandshakeStateType.EXPIRED
|
|
await this.self.save()
|
|
}
|
|
return timeout
|
|
}
|
|
|
|
public isTimeout(): boolean {
|
|
if (this.self.status === CommunityHandshakeStateType.EXPIRED) {
|
|
return true
|
|
}
|
|
if ((Date.now() - this.self.updatedAt.getTime()) > FEDERATION_AUTHENTICATION_TIMEOUT_MS) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
public isFailed(): boolean {
|
|
return this.self.status === CommunityHandshakeStateType.FAILED
|
|
}
|
|
}
|