add tiered pins

remotes/1693176582716663532/tmp_refs/heads/watchparty
Aevann1 2022-10-14 20:28:20 +02:00
parent df1eedc8d9
commit 2411053d55
6 changed files with 59 additions and 24 deletions

View File

@ -38,4 +38,29 @@ if (typeof showNewCommentCounts === 'undefined') {
}
setTimeout(cleanCache, 500)
}
}
function pin_post(t, id) {
t.disabled = true;
t.classList.add("disabled");
post_toast_callback(`/sticky/${id}`,
{
},
(xhr) => {
if(xhr.status == 200) {
t.innerHTML = t.innerHTML.replace(t.textContent, 'Pin permanently')
}
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(() => {
t.disabled = false;
t.classList.remove("disabled");
}, 2000);
}

View File

@ -1205,30 +1205,40 @@ def distinguish_post(post_id, v):
@feature_required('PINS')
def sticky_post(post_id, v):
pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False).count()
if pins >= PIN_LIMIT and v.admin_level < PERMS['BYPASS_PIN_LIMIT']:
abort(403, f"Can't exceed {PIN_LIMIT} pinned posts limit!")
post = get_post(post_id)
if not post.stickied:
pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False).count()
if pins >= PIN_LIMIT:
if v.admin_level >= PERMS['BYPASS_PIN_LIMIT']:
post.stickied = v.username
post.stickied_utc = int(time.time()) + 3600
else: abort(403, f"Can't exceed {PIN_LIMIT} pinned posts limit!")
else: post.stickied = v.username
g.db.add(post)
ma=ModAction(
kind="pin_post",
user_id=v.id,
target_submission_id=post.id
)
g.db.add(ma)
if not post.stickied_utc:
post.stickied_utc = int(time.time()) + 3600
pin_time = 'for 1 hour'
code = 200
else:
post.stickied_utc = None
pin_time = 'permantently'
code = 201
if v.id != post.author_id:
send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has pinned [{post.title}](/post/{post_id})!")
post.stickied = v.username
cache.delete_memoized(frontlist)
return {"message": "Post pinned!"}
g.db.add(post)
ma=ModAction(
kind="pin_post",
user_id=v.id,
target_submission_id=post.id,
_note=pin_time
)
g.db.add(ma)
if v.id != post.author_id:
send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has pinned [{post.title}](/post/{post_id}) {pin_time}!")
cache.delete_memoized(frontlist)
return {"message": f"Post pinned {pin_time}!"}, code
@app.post("/unsticky/<post_id>")
@admin_level_required(PERMS['POST_COMMENT_MODERATION'])

View File

@ -46,7 +46,7 @@
{% endif %}
{% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %}
<a id="pin-{{p.id}}" class="dropdown-item {% if p.stickied %}d-none{% endif %} list-inline-item text-info" role="button" onclick="post_toast(this,'/sticky/{{p.id}}','pin-{{p.id}}','unpin-{{p.id}}','d-none')"><i class="fas fa-thumbtack fa-rotate--45"></i>Pin</a>
<a id="pin-{{p.id}}" class="dropdown-item {% if p.stickied and not p.stickied_utc %}d-none{% endif %} list-inline-item text-info" role="button" onclick="pin_post(this, '{{p.id}}')"><i class="fas fa-thumbtack fa-rotate--45"></i>Pin {% if p.stickied_utc %}permanently{% else %}for 1 hour{% endif %}</a>
<a id="unpin-{{p.id}}" class="dropdown-item {% if not p.stickied %}d-none{% endif %} list-inline-item text-info" role="button" onclick="post_toast(this,'/unsticky/{{p.id}}','pin-{{p.id}}','unpin-{{p.id}}','d-none')"><i class="fas fa-thumbtack fa-rotate--45"></i>Unpin</a>
{% endif %}

View File

@ -23,7 +23,7 @@
<button id="undistinguish2-{{p.id}}" class="{% if not p.distinguish_level %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="post_toast(this,'/distinguish/{{p.id}}','distinguish2-{{p.id}}','undistinguish2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-crown text-center text-primary mr-2"></i>Undistinguish</button>
{% endif %}
{% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %}
<button id="pin2-{{p.id}}" class="{% if p.stickied %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="post_toast(this,'/sticky/{{p.id}}','pin2-{{p.id}}','unpin2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-thumbtack fa-rotate--45 text-center text-primary mr-2"></i>Pin</button>
<button id="pin2-{{p.id}}" class="{% if p.stickied and not p.stickied_utc %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="pin_post(this,'{{p.id}}')" data-bs-dismiss="modal"><i class="fas fa-thumbtack fa-rotate--45 text-center text-primary mr-2"></i>Pin {% if p.stickied_utc %}permanently{% else %}for 1 hour{% endif %}</button>
<button id="unpin2-{{p.id}}" class="{% if not p.stickied %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="post_toast(this,'/unsticky/{{p.id}}','pin2-{{p.id}}','unpin2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-thumbtack fa-rotate--45 text-center text-primary mr-2"></i>Unpin</button>
{% if "/reported/" in request.path %}
<button class="nobackground btn btn-link btn-block btn-lg text-danger text-left" role="button" onclick="post_toast(this,'/remove_post/{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-ban text-center mr-2"></i>Remove</button>

View File

@ -1099,7 +1099,7 @@
{% endif %}
{% if not v or v.highlightcomments %}
<script defer src="{{'js/new_comments_count.js' | asset}}"></script>
<script defer src="{{'js/submission+submission_listing.js' | asset}}"></script>
{% endif %}
<script defer src="{{'js/clipboard.js' | asset}}"></script>

View File

@ -11,7 +11,7 @@
{% endif %}
{% if not v or v.highlightcomments %}
<script defer src="{{'js/new_comments_count.js' | asset}}"></script>
<script defer src="{{'js/submission+submission_listing.js' | asset}}"></script>
{% endif %}
{% include "popover.html" %}