From 4a22bf4b2623d334bff87053ca295831fd3fac95 Mon Sep 17 00:00:00 2001 From: Natsumi Date: Fri, 18 Dec 2020 07:19:34 +1300 Subject: [PATCH] Revert, causes update delay on selecting user --- html/src/app.js | 35 ++++++++++++++++++++++++++++++++--- html/src/index.pug | 4 +--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/html/src/app.js b/html/src/app.js index 05746655..7420b655 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -7601,12 +7601,41 @@ import gameLogService from './service/gamelog.js' }; $app.methods.userOnlineFor = function (ctx) { + var timeToText = function (sec) { + var n = Number(sec); + if (isNaN(n)) { + return escapeTag(sec); + } + n = Math.floor(n / 1000); + var arr = []; + if (n < 0) { + n = -n; + } + if (n >= 86400) { + arr.push(`${Math.floor(n / 86400)}d`); + n %= 86400; + } + if (n >= 3600) { + arr.push(`${Math.floor(n / 3600)}h`); + n %= 3600; + } + if (n >= 60) { + arr.push(`${Math.floor(n / 60)}m`); + n %= 60; + } + if (n || + arr.length === 0) { + arr.push(`${n}s`); + } + return arr.join(' '); + }; + if (ctx.ref.state === 'online') { - return ctx.ref.$online_for; + return timeToText(Date.now() - ctx.ref.$online_for) } else if (ctx.ref.$offline_for) { - return ctx.ref.$offline_for; + return timeToText(Date.now() - ctx.ref.$offline_for) } else { - return false; + return '-'; } }; diff --git a/html/src/index.pug b/html/src/index.pug index 5a42b79e..5447e817 100644 --- a/html/src/index.pug +++ b/html/src/index.pug @@ -774,9 +774,7 @@ html .detail span.name(v-if="userDialog.ref.state === 'online'") Online For span.name(v-else) Offline For - span.extra - timer(v-if="userOnlineFor(userDialog)" :epoch="userOnlineFor(userDialog)") - span(v-else) - + span.extra(v-text="userOnlineFor(userDialog)") .x-friend-item .detail span.name Last Login