Skip to content

Commit bfb3439

Browse files
committed
fix: websocket subscriptions, release v0.10.1
1 parent 69b0e41 commit bfb3439

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

abrechnung/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Abrechnung - feature complete payment management and bookkeeping."""
22

3-
__version__ = "0.10.0"
3+
__version__ = "0.10.1"
44

55
MAJOR_VERSION = __version__.split(".")[0]
66
MINOR_VERSION = __version__.split(".")[1]

debian/changelog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
abrechnung (0.10.1) stable; urgency=medium
2+
3+
* Abrechnung release 0.10.1
4+
5+
-- Michael Loipführer <[email protected]> Sun, 1 Jan 2022 18:00:00 +0100
6+
17
abrechnung (0.10.0) stable; urgency=medium
28

39
* Abrechnung release 0.10.0

frontend/assets/locales/en/translation.json

-10
This file was deleted.

frontend/libs/api/src/lib/api.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,26 @@ export class Api {
5656
private accessToken: string | null = null;
5757
private backendVersion: string | null = null;
5858

59+
private authenticatedResolveCallbacks: Array<() => void> = [];
60+
5961
constructor(private connectionStatusProvider: IConnectionStatusProvider) {}
6062

6163
public resetAuthState = () => {
6264
this.sessionToken = null;
6365
// this.accessToken = null; // we do not null the access token s.t. we can perform remaining requests
6466
};
6567

68+
private notifyAuthenticatedWaiters = () => {
69+
for (const cb of this.authenticatedResolveCallbacks) {
70+
cb();
71+
}
72+
};
73+
6674
public init = async (baseApiUrl: string, sessionToken?: string) => {
6775
this.baseApiUrl = baseApiUrl;
6876

6977
if (sessionToken) {
70-
this.sessionToken = sessionToken;
78+
this.setSessionToken(sessionToken);
7179
}
7280
await this.checkBackendVersion();
7381
};
@@ -89,6 +97,16 @@ export class Api {
8997
}
9098
};
9199

100+
public waitUntilAuthenticated = async (): Promise<void> => {
101+
return new Promise<void>((resolve) => {
102+
if (this.sessionToken !== null) {
103+
resolve();
104+
} else {
105+
this.authenticatedResolveCallbacks.push(resolve);
106+
}
107+
});
108+
};
109+
92110
public getAccessToken = (): string | null => {
93111
return this.accessToken;
94112
};
@@ -103,6 +121,7 @@ export class Api {
103121

104122
public setSessionToken = (token: string) => {
105123
this.sessionToken = token;
124+
this.notifyAuthenticatedWaiters();
106125
};
107126

108127
public getSessionToken = (): string | null => {

frontend/libs/api/src/lib/websocket.ts

+4
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ export class AbrechnungWebSocket {
158158
this.init();
159159
};
160160

161+
public waitUntilAuthenticated = async () => {
162+
await this.api.waitUntilAuthenticated();
163+
};
164+
161165
private onmessage = (evt: MessageEvent) => {
162166
let msg;
163167
try {

frontend/libs/redux/src/lib/subscriptions/subscriptionSlice.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const subscribe = createAsyncThunk<
99
>(
1010
"subscribe",
1111
async ({ subscription, websocket }) => {
12+
await websocket.waitUntilAuthenticated();
1213
websocket.sendSubscriptionRequest(
1314
subscription.type,
1415
subscription.type === "group" ? subscription.userId : subscription.groupId

0 commit comments

Comments
 (0)