Skip to content

Commit

Permalink
Wait until operator is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Elblinator committed Oct 21, 2024
1 parent d09d31c commit 158b006
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class VotingBannerService {
}

private updateBanner(polls: ViewPoll[], voted: { [key: Id]: Id[] }): void {
if (this.activeMeeting.meetingId && !this.operator.isAnonymous) {
if (this.activeMeeting.meetingId && !this.operator.isAnonymous && this.operator.readyDeferred.wasResolved) {
const checkUsers = [this.operator.user, ...(this.operator.user.vote_delegations_from() || [])];
this.pollsToVote = polls.filter(
poll => checkUsers.some(user => this.votingService.canVote(poll, user)) && voted[poll.id] !== undefined
Expand Down
25 changes: 16 additions & 9 deletions client/src/app/site/services/operator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,19 @@ export class OperatorService {
}

public get isAnyManager(): boolean {
return this.isSuperAdmin || this.isOrgaManager || this.isCommitteeManager;
return this.isSuperAdmin || this.isOrgaManager || this.readyDeferred.wasResolved
? this.isCommitteeManager
: false;
}

public get knowsMultipleMeetings(): boolean {
return (
this.isAnyManager ||
(this.isAnonymous ? this.defaultAnonUser.hasMultipleMeetings : this.user.hasMultipleMeetings)
(this.isAnonymous
? this.defaultAnonUser.hasMultipleMeetings
: this.readyDeferred.wasResolved
? this.user?.hasMultipleMeetings
: false)
);
}

Expand Down Expand Up @@ -164,7 +170,7 @@ export class OperatorService {
}

public get ready(): Deferred<void> {
return this._readyDeferred;
return this.readyDeferred;
}

/**
Expand Down Expand Up @@ -227,7 +233,7 @@ export class OperatorService {
// State management
private _ready = false;

private _readyDeferred: Deferred<void> = new Deferred();
public readyDeferred: Deferred<void> = new Deferred();

private _groupsLoaded = false;
private _groupsLoadedDeferred: Deferred<void> = new Deferred();
Expand Down Expand Up @@ -436,7 +442,7 @@ export class OperatorService {
this._permissions !== undefined;
}
if (this.isAuthenticated) {
isReady = isReady && this._OML !== undefined && this._CML !== undefined;
isReady = isReady && this._OML !== undefined && this._CML !== undefined && this._userSubject !== undefined;
}
// TODO: for developing some checks
// console.log(
Expand All @@ -457,22 +463,23 @@ export class OperatorService {
// );
if (isReady) {
this._ready = true;
this._readyDeferred.resolve();
this.readyDeferred.resolve();
this._operatorReadySubject.next(true);
}
}

private setNotReady(): void {
this._ready = false;
this._operatorReadySubject.next(false);
if (this._readyDeferred.wasResolved) {
if (this.readyDeferred.wasResolved) {
console.log(`operator: not ready`);
this._readyDeferred = new Deferred();
this._readyDeferred.then(() => console.log(`operator is ready!`));
this.readyDeferred = new Deferred();
this.readyDeferred.then(() => console.log(`operator is ready!`));
}
}

private resetOperatorData(): void {
this._userSubject.next(undefined);
this._meetingIds = undefined;
this._groupIds = undefined;
this._permissions = undefined;
Expand Down

0 comments on commit 158b006

Please sign in to comment.