- loadNewchallVariant: async function(cb) {
- const vname = this.getVname(this.newchallenge.vid);
- const vModule = await import("@/variants/" + vname + ".js");
- this.newchallenge.V = vModule.VariantRules;
- this.newchallenge.vname = vname;
- if (!!cb)
- cb();
+ addChallenge: function(chall) {
+ // NOTE about next condition: see "askchallenges" case.
+ 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);
+ // TODO: remove patch on next line (options || "{}")
+ newChall.options = JSON.parse(chall.options || "{}");
+ 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);
+ this.setVname(newChall);
+ 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");
+ }
+ if (!!chall.to && chall.to == this.st.user.name) {
+ notify(
+ "New challenge",
+ // fromValues.name should exist since the player is online, but
+ // let's consider there is some chance that the challenge arrives
+ // right after we connected and before receiving the poll result:
+ { body: "from " + (fromValues.name || "@nonymous") }
+ );
+ }
+ }
+ },
+ loadNewchallVariant: async function(cb, vname) {
+ vname = vname || this.setVname(this.newchallenge);
+ await import("@/variants/" + vname + ".js")
+ .then((vModule) => {
+ window.V = vModule[vname + "Rules"];
+ this.newchallenge.V = window.V;
+ if (!!cb) cb();
+ });