- case "challenge": //after "askchallenge"
- case "newchallenge": {
- // NOTE about next condition: see "askchallenge" case.
- const chall = data.data;
- if (
- !chall.to ||
- (this.people[chall.from].id > 0 &&
- (chall.from == this.st.user.sid || chall.to == this.st.user.name))
- ) {
- let newChall = Object.assign({}, chall);
- newChall.type = this.classifyObject(chall);
- newChall.randomness = chall.randomness;
- newChall.added = Date.now();
- let fromValues = Object.assign({}, this.people[chall.from]);
- delete fromValues["pages"]; //irrelevant in this context
- newChall.from = Object.assign({ sid: chall.from }, fromValues);
- newChall.vname = this.getVname(newChall.vid);
- this.challenges.push(newChall);
- if (
- (newChall.type == "live" && this.cdisplay == "corr") ||
- (newChall.type == "corr" && this.cdisplay == "live")
- ) {
- document
- .getElementById("btnC" + newChall.type)
- .classList.add("somethingnew");
- }
- }
+ case "challenges": //after "askchallenges"
+ data.data.forEach(this.addChallenge);
+ break;
+ case "newchallenge":
+ this.addChallenge(data.data);