Added invite gathers and enabled notifications

This commit is contained in:
Chris Blanchard 2016-04-17 15:37:50 +01:00
parent 361978bc8e
commit 277dde3ddb
10 changed files with 116 additions and 6 deletions

View file

@ -5,3 +5,21 @@ const App = require("javascripts/components/main");
module.exports = function (mount) { module.exports = function (mount) {
ReactDOM.render(<App />, mount); ReactDOM.render(<App />, mount);
}; };
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-top-center",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}

View file

@ -208,6 +208,8 @@ const GatherPage = React.createClass({
} }
}); });
socket.on("notify", data => toastr[data.type](data.message));
socket.on('event:append', data => { socket.on('event:append', data => {
let events = self.state.events; let events = self.state.events;
events.unshift(data); events.unshift(data);

View file

@ -50,15 +50,17 @@ exports.config = {
npm: { npm: {
enabled: true, enabled: true,
styles: { styles: {
"bootstrap-solarized": ["bootstrap-solarized-dark.css"] "bootstrap-solarized": ["bootstrap-solarized-dark.css"],
"toastr": ["build/toastr.min.css"]
}, },
whitelist: ["react", "react-dom", "jquery", "lodash", whitelist: ["react", "react-dom", "jquery", "lodash",
"react-autolink", "react-dom", "react-emoji", "howler", "react-autolink", "react-dom", "react-emoji", "howler",
"bootstrap", "perfect-scrollbar", "moment"], "bootstrap", "perfect-scrollbar", "moment", "toastr"],
globals: { globals: {
"_": "lodash", "_": "lodash",
"jQuery": "jquery", "jQuery": "jquery",
"$": "jquery" "$": "jquery",
"toastr": "toastr"
} }
}, },

View file

@ -29,6 +29,15 @@ EnslClient.prototype.getUserById = function (options, callback) {
}, callback); }, callback);
}; };
EnslClient.prototype.getTeamById = function (options, callback) {
const id = options.id;
const url = `${this.baseUrl}api/v1/teams/${id}`;
return request({
url: url,
json: true
}, callback);
};
EnslClient.prototype.getServers = function (callback) { EnslClient.prototype.getServers = function (callback) {
const url = this.baseUrl + "api/v1/servers"; const url = this.baseUrl + "api/v1/servers";
return request({ return request({

View file

@ -120,9 +120,18 @@ module.exports = function (namespace) {
const gatherManager = GatherPool.get(data.type); const gatherManager = GatherPool.get(data.type);
if (!gatherManager) return; if (!gatherManager) return;
const gather = gatherManager.current; const gather = gatherManager.current;
if (gather.can("addGatherer")) gather.addGatherer(socket._user); if (gather.can("addGatherer")) {
Event.joiner(socket._user); gather.addGatherer(socket._user);
refreshGather(data.type); if (gather.containsUser(socket._user)) {
Event.joiner(socket._user);
} else {
socket.emit("notify", {
type: "error",
message: "Unable to add you to the gather"
});
}
refreshGather(data.type);
}
}); });
socket.on("gather:refresh", function (data) { socket.on("gather:refresh", function (data) {

View file

@ -49,6 +49,10 @@ function Gather (options) {
timer: null timer: null
}; };
if (typeof options.membershipTest === 'function') {
this.membershipTest = options.membershipTest.bind(this);
}
this.initState(); this.initState();
} }
@ -80,6 +84,7 @@ StateMachine.create({
// Gathering State // Gathering State
onbeforeaddGatherer: function (event, from, to, user) { onbeforeaddGatherer: function (event, from, to, user) {
if (this.needsToCoolOff(user)) return false; if (this.needsToCoolOff(user)) return false;
if (this.failsTest(user)) return false;
this.addUser(user); this.addUser(user);
if (!this.lobbyFull()) return false; if (!this.lobbyFull()) return false;
}, },
@ -400,4 +405,9 @@ Gather.prototype.needsToCoolOff = function (user) {
} }
}; };
Gather.prototype.failsTest = function (user) {
if (!this.membershipTest) return false;
return !this.membershipTest(user);
}
module.exports = Gather; module.exports = Gather;

View file

@ -11,6 +11,7 @@ const Gather = require("./gather");
const winston = require("winston"); const winston = require("winston");
const mongoose = require("mongoose"); const mongoose = require("mongoose");
const ArchivedGather = mongoose.model("ArchivedGather"); const ArchivedGather = mongoose.model("ArchivedGather");
const InvitationalGather = require("./invitational_gather");
let gatherCallbacks = {}; let gatherCallbacks = {};
let archiveUpdatedCallback = () => {}; let archiveUpdatedCallback = () => {};
@ -21,6 +22,15 @@ const GATHER_CONFIGS = [
name: "Classic Gather", name: "Classic Gather",
description: "No Requirements" description: "No Requirements"
}, },
{
type: "invitational",
name: "Invitational Gather",
description: "Join on ensl.org/teams/949",
// Grant invite if on list
membershipTest: function (user) {
return InvitationalGather.list.some(m => m.id === user.id);
}
},
{ {
type: "casual", type: "casual",
name: "Casual Gather", name: "Casual Gather",

View file

@ -0,0 +1,32 @@
"use strict";
const winston = require("winston");
const env = process.env.NODE_ENV || "development";
const client = require("../ensl/client")();
const REFRESH_INTERVAL = 1000 * 60; // Check every minute
const invitationalTeamId = env === "production" ? 949 : 866;
function InvitationalGather () {
}
InvitationalGather.list = [];
InvitationalGather.updateList = function () {
client.getTeamById({
id: invitationalTeamId
}, (error, result) => {
if (error) {
winston.error("Unable to download team list")
winston.error(error);
return;
};
InvitationalGather.list = result.body.members;
});
};
InvitationalGather.updateList();
setInterval(InvitationalGather.updateList, REFRESH_INTERVAL);
module.exports = InvitationalGather;

View file

@ -63,6 +63,7 @@
"socket.io": "~1.3.7", "socket.io": "~1.3.7",
"steam": "~1.1.0", "steam": "~1.1.0",
"steamidconvert": "~0.2.4", "steamidconvert": "~0.2.4",
"toastr": "^2.1.2",
"uglify-js-brunch": ">= 1.0 < 1.8", "uglify-js-brunch": ">= 1.0 < 1.8",
"winston": "~1.0.1" "winston": "~1.0.1"
}, },

View file

@ -31,6 +31,23 @@ describe("Gather Model:", function () {
}); });
}); });
describe("membership", () => {
it ("does not allow user to join if membership criteria not met", () => {
gather = Gather({
membershipTest: function (user) { return false }
});
gather.addGatherer(user);
assert.equal(gather.gatherers.length, 0);
});
it ("does not allow user to join if membership criteria met", () => {
gather = Gather({
membershipTest: function (user) { return true }
});
gather.addGatherer(user);
assert.equal(gather.gatherers.length, 1);
});
});
describe("removeUser", function () { describe("removeUser", function () {
it ("removes gatherer altogether", function () { it ("removes gatherer altogether", function () {
gather.addUser(user); gather.addUser(user);