- ajax(
- "/challenges",
- "GET",
- {uid: this.st.user.id},
- response => {
- // Gather all senders names, and then retrieve full identity:
- // (TODO [perf]: some might be online...)
- let names = {};
- response.challenges.forEach(c => {
- if (c.uid != this.st.user.id)
- names[c.uid] = ""; //unknwon for now
- else if (!!c.target && c.target != this.st.user.id)
- names[c.target] = "";
- });
- const addChallenges = (newChalls) => {
- names[this.st.user.id] = this.st.user.name; //in case of
- this.challenges = this.challenges.concat(
- response.challenges.map(c => {
- const from = {name: names[c.uid], id: c.uid}; //or just name
- const type = this.classifyObject(c);
- const vname = this.getVname(c.vid);
- return Object.assign({},
- {
- type: type,
- vname: vname,
- from: from,
- to: (!!c.target ? names[c.target] : ""),
- },
- c);
- })
- );
- };
- if (Object.keys(names).length > 0)
- {
- ajax("/users",
- "GET",
- { ids: Object.keys(names).join(",") },
- response2 => {
- response2.users.forEach(u => {names[u.id] = u.name});
- addChallenges();
- }
- );
- }
- else
- addChallenges();
- }
- );
+ ajax("/challenges", "GET", { uid: this.st.user.id }, response => {
+ // Gather all senders names, and then retrieve full identity:
+ // (TODO [perf]: some might be online...)
+ let names = {};
+ response.challenges.forEach(c => {
+ if (c.uid != this.st.user.id) names[c.uid] = "";
+ //unknwon for now
+ else if (!!c.target && c.target != this.st.user.id)
+ names[c.target] = "";
+ });
+ const addChallenges = () => {
+ names[this.st.user.id] = this.st.user.name; //in case of
+ this.challenges = this.challenges.concat(
+ response.challenges.map(c => {
+ const from = { name: names[c.uid], id: c.uid }; //or just name
+ const type = this.classifyObject(c);
+ const vname = this.getVname(c.vid);
+ return Object.assign(
+ {},
+ {
+ type: type,
+ vname: vname,
+ from: from,
+ to: c.target ? names[c.target] : ""
+ },
+ c
+ );
+ })
+ );
+ };
+ if (Object.keys(names).length > 0) {
+ ajax(
+ "/users",
+ "GET",
+ { ids: Object.keys(names).join(",") },
+ response2 => {
+ response2.users.forEach(u => {
+ names[u.id] = u.name;
+ });
+ addChallenges();
+ }
+ );
+ } else addChallenges();
+ });