diff --git a/files/assets/js/chat.js b/files/assets/js/chat.js index 58a459576..f133ce59c 100644 --- a/files/assets/js/chat.js +++ b/files/assets/js/chat.js @@ -80,7 +80,7 @@ socket.on('speak', function(json) { document.getElementsByClassName('userlink')[0].classList.remove('d-none') document.getElementsByClassName('avatar')[0].classList.remove('d-none') document.getElementsByClassName('avatar-pic')[0].src = json['avatar'] - if (json['hat']) document.getElementsByClassName('avatar-hat')[0].src = `/i/hats/${json['hat']}.webp?v=3` + if (json['hat']) document.getElementsByClassName('avatar-hat')[0].src = json['hat']} + '?v=3' document.getElementsByClassName('userlink')[0].href = '/@' + json['username'] document.getElementsByClassName('userlink')[0].style.color = '#' + json['namecolor'] document.getElementsByClassName('time')[0].classList.remove('d-none') diff --git a/files/assets/js/comments+submission_listing.js b/files/assets/js/comments+submission_listing.js index c08cb7251..7586038ea 100644 --- a/files/assets/js/comments+submission_listing.js +++ b/files/assets/js/comments+submission_listing.js @@ -49,7 +49,7 @@ function popclick(e) { popover.getElementsByClassName('pop-banner')[0].src = author["bannerurl"] popover.getElementsByClassName('pop-picture')[0].src = author["profile_url"] - if (author["hat"]) popover.getElementsByClassName('pop-hat')[0].src = `/i/hats/${author['hat']}.webp?v=3` + if (author["hat"]) popover.getElementsByClassName('pop-hat')[0].src = author['hat'] + '?v=3' popover.getElementsByClassName('pop-username')[0].innerHTML = author["username"] if (popover.getElementsByClassName('pop-bio').length > 0) { popover.getElementsByClassName('pop-bio')[0].innerHTML = author["bio_html"] diff --git a/files/classes/user.py b/files/classes/user.py index 71a32ee79..382ec8fd7 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -192,6 +192,13 @@ class User(Base): def equipped_hat_ids(self): return [x.hat_id for x in self.equipped_hats] + @property + @lazy + def equipped_hat(self): + if self.equipped_hats: + return random.choice(self.equipped_hats) + return None + @property @lazy def hat_active(self): @@ -199,10 +206,10 @@ class User(Base): return '' if self.is_cakeday: - return 'Cakeday.webp' + return '/i/hats/Cakeday.webp' - if self.equipped_hats: - return random.choice(self.equipped_hats) + if self.equipped_hat: + return f'/i/hats/{self.equipped_hat.name}.webp' return '' @@ -214,8 +221,8 @@ class User(Base): if self.is_cakeday: return "I've spent another year rotting my brain with dramaposting, please ridicule me 🤓" - if self.equipped_hats: - return self.hat_active.name + ' - ' + self.hat_active.censored_description(v) + if self.equipped_hat: + return self.equipped_hat.name + ' - ' + self.equipped_hat.censored_description(v) return '' @@ -693,7 +700,7 @@ class User(Base): 'url': self.url, 'id': self.id, 'profile_url': self.profile_url, - 'hat': self.hat_active.name, + 'hat': self.hat_active, 'bannerurl': self.banner_url, 'bio_html': self.bio_html_eager, 'coins': self.coins, diff --git a/files/routes/chat.py b/files/routes/chat.py index fe810f507..307b33eb3 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -66,7 +66,7 @@ def speak(data, v): data={ "avatar": v.profile_url, - "hat": v.hat_active.name, + "hat": v.hat_active, "username": v.username, "namecolor": v.namecolor, "text": text, diff --git a/files/templates/chat.html b/files/templates/chat.html index 15efbf817..ba095d38a 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -169,7 +169,7 @@