mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-25 22:01:00 +00:00
Merge branch 'master' into bugfix/lebra_leave_join_spam_crash
This commit is contained in:
commit
f18718a686
2 changed files with 56 additions and 20 deletions
|
@ -920,16 +920,32 @@ const GathererListItem = React.createClass({
|
|||
}
|
||||
|
||||
const lastSeenInMinutes = (gatherer) => {
|
||||
return parseInt((Date.now() - gatherer.user.lastSeen) / (1000 * 60));
|
||||
const now = Date.now();
|
||||
const minutesSinceLastSeen = (now - gatherer.user.lastSeen) / 60000;
|
||||
|
||||
if (minutesSinceLastSeen < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return parseInt(minutesSinceLastSeen || 0);
|
||||
};
|
||||
|
||||
let idleStatus;
|
||||
if (!gatherer.user.online) {
|
||||
const mins = lastSeenInMinutes(gatherer);
|
||||
idleStatus = [
|
||||
<dt>Last Seen</dt>,
|
||||
<dd>{mins} mins ago</dd>
|
||||
]
|
||||
|
||||
if (mins > 60) {
|
||||
const hours = Math.round(mins / 6) / 10;
|
||||
idleStatus = [
|
||||
<dt>Last Seen</dt>,
|
||||
<dd>{hours} hours ago</dd>
|
||||
]
|
||||
} else{
|
||||
idleStatus = [
|
||||
<dt>Last Seen</dt>,
|
||||
<dd>{mins} mins ago</dd>
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
let tabColor = gatherer.team !== "lobby" ? `panel-${gatherer.team}` : "panel-info";
|
||||
|
|
|
@ -35,20 +35,6 @@ module.exports = function (namespace) {
|
|||
});
|
||||
};
|
||||
|
||||
const updateGathererLastSeenStatuses = () => {
|
||||
const onlineIds = Object.values(namespace.sockets).map(s => s._user.id);
|
||||
const now = Date.now();
|
||||
GatherPool.forEach((gatherManager, type) => {
|
||||
for (var gatherer of gatherManager.current.gatherers) {
|
||||
if (gatherer.user.online) {
|
||||
gatherer.user.lastSeen = now;
|
||||
}
|
||||
|
||||
gatherer.user.online = onlineIds.indexOf(gatherer.id) !== -1;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const refreshArchive = () => {
|
||||
ArchivedGather.recent((error, recentGathers) => {
|
||||
if (error) return winston.error(error);
|
||||
|
@ -70,6 +56,29 @@ module.exports = function (namespace) {
|
|||
}
|
||||
}
|
||||
|
||||
const updateUserAsOnlineInGather = (userId) => {
|
||||
return GatherPool.forEach((gatherManager, type) => {
|
||||
for (var gatherer of gatherManager.current.gatherers) {
|
||||
if (gatherer.user.id == userId && !gatherer.user.online) {
|
||||
gatherer.user.online = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const refreshGathersWhereUserWentOffline = (userId) => {
|
||||
return GatherPool.forEach((gatherManager, type) => {
|
||||
for (var gatherer of gatherManager.current.gatherers) {
|
||||
if (gatherer.user.id == userId && gatherer.user.online) {
|
||||
gatherer.user.online = false;
|
||||
gatherer.user.lastSeen = Date.now();
|
||||
|
||||
refreshGather(type);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const gatherRefreshers = {}; // Stores debounced procedures to refresh gathers
|
||||
|
||||
GatherPool.forEach((gatherManager, type) => {
|
||||
|
@ -117,6 +126,10 @@ module.exports = function (namespace) {
|
|||
}
|
||||
|
||||
namespace.on("connection", function (socket) {
|
||||
const connectedUserId = socket._user && socket._user.id;
|
||||
|
||||
updateUserAsOnlineInGather(connectedUserId);
|
||||
|
||||
ArchivedGather.recent((error, recentGathers) => {
|
||||
if (error) return winston.error(error);
|
||||
socket.emit("gather:archive:refresh", {
|
||||
|
@ -126,7 +139,13 @@ module.exports = function (namespace) {
|
|||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
updateGathererLastSeenStatuses();
|
||||
const onlineIds = Object.values(namespace.sockets).map(s => s._user.id);
|
||||
|
||||
// need to check if this disconnect actually meant user went offline
|
||||
// they could have another tab open...
|
||||
if (onlineIds.indexOf(connectedUserId) === -1) {
|
||||
refreshGathersWhereUserWentOffline(connectedUserId);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("gather:join", function (data) {
|
||||
|
@ -173,6 +192,7 @@ module.exports = function (namespace) {
|
|||
gather.removeGatherer(user);
|
||||
}
|
||||
if (user.cooldown) gather.applyCooldown(user);
|
||||
|
||||
Event.leaver(gatherLeaver.user);
|
||||
refreshGather(gather.type);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue