unify get_user event via socketio

This commit is contained in:
Patrick Jentsch
2023-07-24 10:02:35 +02:00
parent 87e2c2b484
commit 656eef17db
3 changed files with 11 additions and 14 deletions

View File

@ -8,19 +8,19 @@ class App {
this.socket.on('PATCH', (patch) => {this.onPatch(patch);});
}
getUser(userId, backrefs=true, relationships=true) {
getUser(userId) {
if (userId in this.data.promises.getUser) {
return this.data.promises.getUser[userId];
}
this.data.promises.getUser[userId] = new Promise((resolve, reject) => {
this.socket.emit('GET /users/<user_id>', userId, backrefs, relationships, (response) => {
if (response.status !== 200) {
reject(response);
return;
this.socket.emit('GET /users/<user_id>', userId, (response) => {
if (response.status === 200) {
this.data.users[userId] = response.body;
resolve(this.data.users[userId]);
} else {
reject(`[${response.status}] ${response.statusText}`);
}
this.data.users[userId] = response.body;
resolve(this.data.users[userId]);
});
});