- this.sendSomethingTo(chall.to, "challenge", {chall:chall}, !!warnDisconnected);
+ const isSent = this.sendSomethingTo(chall.to, "challenge",
+ {chall:chall}, !!warnDisconnected);
+ if (!isSent)
+ return;
+ // Remove old challenge if any (only one at a time):
+ const cIdx = this.challenges.findIndex(c =>
+ c.from.sid == this.st.user.sid && c.type == ctype);
+ if (cIdx >= 0)
+ {
+ // Delete current challenge (will be replaced now)
+ this.sendSomethingTo(this.challenges[cIdx].to,
+ "deletechallenge", {cid:this.challenges[cIdx].id});
+ if (ctype == "corr")
+ {
+ ajax(
+ "/challenges",
+ "DELETE",
+ {id: this.challenges[cIdx].id}
+ );
+ }
+ this.challenges.splice(cIdx, 1);
+ }
+ // Add new challenge: