Fixed an issue where in some scenarios users coming back online wouldn't be counted, incorrectly marking the user as still being offline.

Also changed last seen status to show hours when offline time exceeeds 60 minutes
This commit is contained in:
ArturPhilibin 2020-02-12 00:02:22 +00:00
parent 8ce1306b05
commit 0c0dad087f
2 changed files with 57 additions and 20 deletions

View file

@ -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";

View file

@ -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) {
@ -163,10 +182,12 @@ module.exports = function (namespace) {
const removeGatherer = (gather, user) => {
let gatherLeaver = gather.getGatherer(user);
if (gather.can("removeGatherer")) {
gather.removeGatherer(user);
}
if (user.cooldown) gather.applyCooldown(user);
Event.leaver(gatherLeaver.user);
refreshGather(gather.type);
}