mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-13 01:20:41 +00:00
Change how user data is get and subscribed
This commit is contained in:
@ -8,33 +8,20 @@ class App {
|
||||
this.socket.on('PATCH', (patch) => {this.onPatch(patch);});
|
||||
}
|
||||
|
||||
getUser(userId) {
|
||||
getUser(userId, backrefs=false, relationships=false) {
|
||||
if (userId in this.data.promises.getUser) {
|
||||
return this.data.promises.getUser[userId];
|
||||
}
|
||||
|
||||
this.data.promises.getUser[userId] = new Promise((resolve, reject) => {
|
||||
fetch(`/users/${userId}?backrefs=true&relationships=true`, {headers: {Accept: 'application/json'}})
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.status === 403) {this.flash('Forbidden', 'error'); reject(response);}
|
||||
return response.json();
|
||||
},
|
||||
(response) => {
|
||||
this.flash('Something went wrong', 'error');
|
||||
reject(response);
|
||||
}
|
||||
)
|
||||
.then(
|
||||
(user) => {
|
||||
this.data.users[userId] = user;
|
||||
resolve(this.data.users[userId]);
|
||||
},
|
||||
(error) => {
|
||||
console.error(error, 'error');
|
||||
reject(error);
|
||||
}
|
||||
);
|
||||
this.socket.emit('GET /users/<user_id>', userId, backrefs, relationships, (response) => {
|
||||
if (response.status !== 200) {
|
||||
reject(response);
|
||||
return;
|
||||
}
|
||||
this.data.users[userId] = response.body;
|
||||
resolve(this.data.users[userId]);
|
||||
});
|
||||
});
|
||||
|
||||
return this.data.promises.getUser[userId];
|
||||
@ -47,11 +34,11 @@ class App {
|
||||
|
||||
this.data.promises.subscribeUser[userId] = new Promise((resolve, reject) => {
|
||||
this.socket.emit('SUBSCRIBE /users/<user_id>', userId, (response) => {
|
||||
if (response.code === 200) {
|
||||
resolve(response);
|
||||
} else {
|
||||
if (response.status !== 200) {
|
||||
reject(response);
|
||||
return;
|
||||
}
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user