From 4553d8aee0760f9cbf3d19c43fd56cb891813a3a Mon Sep 17 00:00:00 2001 From: ArturPhilibin Date: Thu, 10 Jan 2019 17:15:14 +0000 Subject: [PATCH] Styled gatherer names with italics if they are no longer on the gather (#127) page. Displays a somewhat inaccurate (but in the afk gatherers favour) idle timer in the gatherer info panel. --- app/javascripts/components/gather.js | 17 ++++++++++++++++- app/stylesheets/app.css | 4 ++++ lib/gather/controller.js | 22 +++++++++++++--------- lib/gather/gather.js | 13 ++++++++++++- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/javascripts/components/gather.js b/app/javascripts/components/gather.js index ba17f98..9620b25 100644 --- a/app/javascripts/components/gather.js +++ b/app/javascripts/components/gather.js @@ -873,14 +873,28 @@ const GathererListItem = React.createClass({ ] } + + const lastSeenInMinutes = (gatherer) => { + return parseInt((Date.now() - gatherer.user.lastSeen) / (1000 * 60)); + }; + + let idleStatus; + if (!gatherer.user.online) { + const mins = lastSeenInMinutes(gatherer); + idleStatus = [ +
Last Seen
, +
{mins} mins ago
+ ] + } let tabColor = gatherer.team !== "lobby" ? `panel-${gatherer.team}` : "panel-info"; + let onlineStatus = gatherer.user.online ? "" : "font-italic" return (

- {country} {gatherer.user.username} + {country} {gatherer.user.username} @@ -894,6 +908,7 @@ const GathererListItem = React.createClass({ className={this.collapseState()} >
+ {idleStatus}
Skill Level
{skill}
Team
diff --git a/app/stylesheets/app.css b/app/stylesheets/app.css index dd2014f..76b0642 100644 --- a/app/stylesheets/app.css +++ b/app/stylesheets/app.css @@ -6,6 +6,10 @@ html, body { margin-top: 1em; } +.font-italic { + font-style: italic; +} + /*Chat*/ .wordwrap { diff --git a/lib/gather/controller.js b/lib/gather/controller.js index c7c1f7f..169c881 100644 --- a/lib/gather/controller.js +++ b/lib/gather/controller.js @@ -26,15 +26,17 @@ const Event = mongoose.model("Event"); const _ = require("lodash"); const winston = require("winston"); -const emitGather = (socket, gather) => { - socket.emit("gather:refresh", { - gather: gather ? gather.toJson() : null, - type: gather ? gather.type : null, - maps: Map.list, - }); -} - module.exports = function (namespace) { + const emitGather = (socket, gather) => { + const onlineIds = Object.values(namespace.sockets).map(s => s._user.id); + + socket.emit("gather:refresh", { + gather: gather ? gather.toJson(onlineIds) : null, + type: gather ? gather.type : null, + maps: Map.list, + }); + } + const refreshArchive = () => { ArchivedGather.recent((error, recentGathers) => { if (error) return winston.error(error); @@ -78,8 +80,10 @@ module.exports = function (namespace) { gatherManager.onArchiveUpdate(refreshArchive); gatherRefreshers[type] = _.debounce(function () { + const onlineIds = Object.values(namespace.sockets).map(s => s._user.id); + namespace.emit("gather:refresh", { - gather: gatherManager.current ? gatherManager.current.toJson() : null, + gather: gatherManager.current ? gatherManager.current.toJson(onlineIds) : null, type: gatherManager.current ? gatherManager.current.type : null, maps: Map.list, }); diff --git a/lib/gather/gather.js b/lib/gather/gather.js index b8bad0b..8b6352f 100644 --- a/lib/gather/gather.js +++ b/lib/gather/gather.js @@ -337,7 +337,18 @@ Gather.prototype.electionStartTime = function () { null : this.election.startTime.toISOString(); }; -Gather.prototype.toJson = function () { +Gather.prototype.toJson = function (onlineIds) { + if (onlineIds) { + const now = Date.now(); + for (var gatherer of this.gatherers) { + if (gatherer.user.online) { + gatherer.user.lastSeen = now; + } + + gatherer.user.online = onlineIds.indexOf(gatherer.id) !== -1; + } + } + return { name: this.name, description: this.description,