From 548f2613c727f0d9d060f97adf150a330f10e438 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Tue, 25 Oct 2022 17:48:10 -0500 Subject: [PATCH] pinprovements --- files/assets/js/pinpost.js | 21 ++++++++++++--------- files/helpers/const.py | 1 + files/routes/admin.py | 11 +++++------ files/routes/awards.py | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/files/assets/js/pinpost.js b/files/assets/js/pinpost.js index b99f450ae..32c36ab6d 100644 --- a/files/assets/js/pinpost.js +++ b/files/assets/js/pinpost.js @@ -5,16 +5,19 @@ function pinPost(t, id) { { }, (xhr) => { - if(xhr.status == 200) { - t.innerHTML = t.innerHTML.replace(t.textContent, 'Pin permanently') + if (xhr.status >= 200 && xhr.status < 300) { + response = JSON.parse(xhr.response); + length = response["length"]; + if (length == "permanently") { + t.innerHTML = t.innerHTML.replace(t.textContent, 'Pin for 1 hour'); + t.classList.add('d-none'); + } else { + t.innerHTML = t.innerHTML.replace(t.textContent, 'Pin permanently'); + } + t.nextElementSibling.classList.remove('d-none'); + t.disabled = false; + t.classList.remove("disabled"); } - else if(xhr.status == 201) { - t.innerHTML = t.innerHTML.replace(t.textContent, 'Pin for 1 hour') - t.classList.add('d-none') - } - t.nextElementSibling.classList.remove('d-none') - t.disabled = false; - t.classList.remove("disabled"); } ); setTimeout(() => { diff --git a/files/helpers/const.py b/files/helpers/const.py index e8600701c..6664be6ce 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -152,6 +152,7 @@ AGENDAPOSTER_MSG_HTML = """

Hi ") @admin_level_required(PERMS['POST_COMMENT_MODERATION']) def unsticky_post(post_id, v): - post = get_post(post_id) if post.stickied: - if post.stickied.endswith('(pin award)'): abort(403, "Can't unpin award pins!") + if post.stickied.endswith(PIN_AWARD_TEXT): abort(403, "Can't unpin award pins!") if post.author_id == LAWLZ_ID and post.stickied_utc and SITE_NAME == 'rDrama': abort(403, "Can't unpin lawlzposts!") post.stickied = None @@ -1302,7 +1301,7 @@ def unsticky_comment(cid, v): comment = get_comment(cid, v=v) if comment.stickied: - if comment.stickied.endswith("(pin award)"): abort(403, "Can't unpin award pins!") + if comment.stickied.endswith(PIN_AWARD_TEXT): abort(403, "Can't unpin award pins!") comment.stickied = None g.db.add(comment) diff --git a/files/routes/awards.py b/files/routes/awards.py index eac872875..b3ad38ee9 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -224,7 +224,7 @@ def award_thing(v, thing_type, id): if thing.stickied and thing.stickied_utc: thing.stickied_utc += 3600 else: - thing.stickied = f'{v.username} (pin award)' + thing.stickied = f'{v.username}{PIN_AWARD_TEXT}' if thing_type == 'comment': thing.stickied_utc = int(time.time()) + 3600*6 else: