Skip to content

Commit

Permalink
Merge branch 'main' into 4191-fix-amendment-display
Browse files Browse the repository at this point in the history
  • Loading branch information
Elblinator authored Nov 18, 2024
2 parents 789b2d4 + 05b33aa commit 98f5ae2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/src/app/site/services/auth-check.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class AuthCheckService {
if (typeof info === `string`) {
meetingIdString = this.osRouter.getMeetingId(info);
}
if (Number.isNaN(Number(meetingIdString))) {
if (Number.isNaN(Number(meetingIdString)) || +meetingIdString <= 0) {
return false;
}
await this.fetchMeetingIfNotExists(+meetingIdString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { SUBSCRIPTION_SUFFIX } from '../model-request.service';
})
export class AutoupdateCommunicationService {
private autoupdateDataObservable: Observable<AutoupdateReceiveDataContent>;
private openResolvers = new Map<string, (value: number | PromiseLike<number>) => void>();
private openResolvers = new Map<string, ((value: number | PromiseLike<number>) => void)[]>();
private endpointName: string;
private autoupdateEndpointStatus: 'healthy' | 'unhealthy' = `healthy`;
private unhealtyTimeout: any;
Expand Down Expand Up @@ -130,7 +130,11 @@ export class AutoupdateCommunicationService {
public open(streamId: Id | null, description: string, request: ModelRequest, params = {}): Promise<Id> {
return new Promise((resolve, reject) => {
const requestHash = djb2hash(JSON.stringify(request));
this.openResolvers.set(requestHash, resolve);
if (this.openResolvers.has(requestHash)) {
this.openResolvers.get(requestHash).push(resolve);
} else {
this.openResolvers.set(requestHash, [resolve]);
}
this.sharedWorker
.sendMessage(`autoupdate`, {
action: `open`,
Expand Down Expand Up @@ -298,7 +302,7 @@ export class AutoupdateCommunicationService {
return;
}

this.openResolvers.get(data.content.requestHash)(data.content?.streamId);
this.openResolvers.get(data.content.requestHash).forEach(r => r(data.content?.streamId));
this.openResolvers.delete(data.content.requestHash);
}

Expand Down
20 changes: 15 additions & 5 deletions client/src/app/site/services/autoupdate/autoupdate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class AutoupdateService {
private _activeRequestObjects: AutoupdateSubscriptionMap = {};
private _mutex = new Mutex();
private _currentQueryParams: QueryParams | null = null;
private _resolveDataReceived: ((value: ModelData) => void)[] = [];
private _resolveDataReceived: { [key: number]: ((value: ModelData) => void)[] } = [];

public constructor(
private httpEndpointService: HttpStreamEndpointService,
Expand Down Expand Up @@ -224,8 +224,13 @@ export class AutoupdateService {
);

let rejectReceivedData: any;
let resolveIdx: number;
const receivedData = new Promise<ModelData>((resolve, reject) => {
this._resolveDataReceived[id] = resolve;
if (this._resolveDataReceived[id]) {
resolveIdx = this._resolveDataReceived[id].push(resolve) - 1;
} else {
this._resolveDataReceived[id] = [resolve];
}
rejectReceivedData = reject;
});
receivedData.catch((e: Error) => {
Expand All @@ -238,9 +243,9 @@ export class AutoupdateService {
close: (): void => {
this.communication.close(id);
delete this._activeRequestObjects[id];
if (this._resolveDataReceived[id]) {
if (this._resolveDataReceived[id] && this._resolveDataReceived[id][resolveIdx]) {
rejectReceivedData(new Error(`Connection canceled`));
delete this._resolveDataReceived[id];
delete this._resolveDataReceived[id][resolveIdx];
}

console.debug(`[autoupdate] stream closed:`, description);
Expand Down Expand Up @@ -323,7 +328,12 @@ export class AutoupdateService {
this.communication.cleanupCollections(requestId, deletedModels);

if (this._resolveDataReceived[requestId]) {
this._resolveDataReceived[requestId](modelData);
for (let i = 0; i < this._resolveDataReceived[requestId].length; i++) {
if (this._resolveDataReceived[requestId][i]) {
this._resolveDataReceived[requestId][i](modelData);
delete this._resolveDataReceived[requestId][i];
}
}
delete this._resolveDataReceived[requestId];
}
}
Expand Down

0 comments on commit 98f5ae2

Please sign in to comment.