From bd51c90345a9c35d5917b69bd338b37d116cb82d Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 18 Aug 2024 18:19:57 +0300 Subject: [PATCH] fix this https://watchpeopledie.tv/h/meta/post/61549/megathread-for-bugs-and-suggestions/4130729#context --- files/assets/js/comments+post_listing.js | 2 +- files/assets/js/core.js | 14 ++++++++++---- files/classes/user.py | 9 +-------- files/templates/user_listing.html | 4 ++-- files/templates/userpage/banner.html | 8 ++++---- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/files/assets/js/comments+post_listing.js b/files/assets/js/comments+post_listing.js index c82829b08..d71d212f5 100644 --- a/files/assets/js/comments+post_listing.js +++ b/files/assets/js/comments+post_listing.js @@ -124,7 +124,7 @@ document.addEventListener("click", function(e) { popover.getElementsByClassName('pop-coins')[0].innerHTML = author["coins"] popover.getElementsByClassName('pop-marseybux')[0].innerHTML = author["marseybux"] popover.getElementsByClassName('pop-view_more')[0].href = author["url"] - popover.getElementsByClassName('pop-created-date')[0].innerHTML = author["created_date"] + popover.getElementsByClassName('pop-created-date')[0].innerHTML = formatDate(new Date(author["created_utc"]*1000)); popover.getElementsByClassName('pop-id')[0].innerHTML = author["id"] if (author["original_usernames"]) { popover.getElementsByClassName('pop-original-usernames')[0].innerHTML = author["original_usernames"] diff --git a/files/assets/js/core.js b/files/assets/js/core.js index 8e418dbfb..55c3122d3 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -224,15 +224,21 @@ function showmore(t) { t.remove() } +function formatDate(d) { + return d.toLocaleTimeString([], {year: 'numeric', month: 'short', day: 'numeric'}).split(',').slice(0, -1) +} +if (!location.pathname.startsWith('/chat/')) { + for (const e of document.querySelectorAll('[data-date]')) { + e.innerHTML = formatDate(new Date(e.dataset.date*1000)); + }; +} + function formatTime(d) { const options = {year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', timeZoneName: 'short'}; return d.toLocaleTimeString([], options) } - -const timestamps = document.querySelectorAll('[data-time]'); - if (!location.pathname.startsWith('/chat/')) { - for (const e of timestamps) { + for (const e of document.querySelectorAll('[data-time]')) { e.innerHTML = formatTime(new Date(e.dataset.time*1000)); }; } diff --git a/files/classes/user.py b/files/classes/user.py index b6ad83c70..5a1f0b934 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -546,13 +546,6 @@ class User(Base): def created_date(self): return time.strftime("%d %b %Y", time.gmtime(self.created_utc)) - @property - @lazy - def last_active_date(self): - if self.last_active == 0: - return "never" - return time.strftime("%d %b %Y", time.gmtime(self.last_active)) - @property @lazy def is_cakeday(self): @@ -1100,7 +1093,7 @@ class User(Base): 'post_count': commas(self.real_post_count(v)), 'comment_count': commas(self.real_comment_count(v)), 'badges': [[x.path, x.text, x.until] for x in self.ordered_badges(v)], - 'created_date': self.created_date, + 'created_utc': self.created_utc, 'original_usernames': self.original_usernames_popover, } diff --git a/files/templates/user_listing.html b/files/templates/user_listing.html index caa30ba7f..77982f29a 100644 --- a/files/templates/user_listing.html +++ b/files/templates/user_listing.html @@ -26,10 +26,10 @@ {% endif %} -
Joined on
+
Joined on
{% if v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} -
Last active on
+
Last active on
{%- endif %} {% if FEATURES['USERS_PROFILE_BODYTEXT'] and not hide_bios and u.bio_html and can_see(v, u) %} diff --git a/files/templates/userpage/banner.html b/files/templates/userpage/banner.html index a15786c49..b13732c27 100644 --- a/files/templates/userpage/banner.html +++ b/files/templates/userpage/banner.html @@ -115,10 +115,10 @@ {% endif %} - Joined {{u.created_date}} + Joined {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} - last active {{u.last_active_date}} + last active {%- endif %} @@ -425,10 +425,10 @@ marseybux {% endif %} -
Joined {{u.created_date}} +
Joined {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} -
last active {{u.last_active_date}} +
last active {%- endif %}