add tiered pins
parent
df1eedc8d9
commit
2411053d55
|
@ -39,3 +39,28 @@ if (typeof showNewCommentCounts === 'undefined') {
|
||||||
|
|
||||||
setTimeout(cleanCache, 500)
|
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);
|
||||||
|
}
|
|
@ -1205,30 +1205,40 @@ def distinguish_post(post_id, v):
|
||||||
@feature_required('PINS')
|
@feature_required('PINS')
|
||||||
def sticky_post(post_id, v):
|
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)
|
post = get_post(post_id)
|
||||||
if not post.stickied:
|
|
||||||
pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False).count()
|
if not post.stickied_utc:
|
||||||
if pins >= PIN_LIMIT:
|
|
||||||
if v.admin_level >= PERMS['BYPASS_PIN_LIMIT']:
|
|
||||||
post.stickied = v.username
|
|
||||||
post.stickied_utc = int(time.time()) + 3600
|
post.stickied_utc = int(time.time()) + 3600
|
||||||
else: abort(403, f"Can't exceed {PIN_LIMIT} pinned posts limit!")
|
pin_time = 'for 1 hour'
|
||||||
else: post.stickied = v.username
|
code = 200
|
||||||
|
else:
|
||||||
|
post.stickied_utc = None
|
||||||
|
pin_time = 'permantently'
|
||||||
|
code = 201
|
||||||
|
|
||||||
|
post.stickied = v.username
|
||||||
|
|
||||||
g.db.add(post)
|
g.db.add(post)
|
||||||
|
|
||||||
ma=ModAction(
|
ma=ModAction(
|
||||||
kind="pin_post",
|
kind="pin_post",
|
||||||
user_id=v.id,
|
user_id=v.id,
|
||||||
target_submission_id=post.id
|
target_submission_id=post.id,
|
||||||
|
_note=pin_time
|
||||||
)
|
)
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
if v.id != post.author_id:
|
if v.id != post.author_id:
|
||||||
send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has pinned [{post.title}](/post/{post_id})!")
|
send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has pinned [{post.title}](/post/{post_id}) {pin_time}!")
|
||||||
|
|
||||||
cache.delete_memoized(frontlist)
|
cache.delete_memoized(frontlist)
|
||||||
return {"message": "Post pinned!"}
|
|
||||||
|
return {"message": f"Post pinned {pin_time}!"}, code
|
||||||
|
|
||||||
@app.post("/unsticky/<post_id>")
|
@app.post("/unsticky/<post_id>")
|
||||||
@admin_level_required(PERMS['POST_COMMENT_MODERATION'])
|
@admin_level_required(PERMS['POST_COMMENT_MODERATION'])
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %}
|
{% 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>
|
<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 %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
<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 %}
|
{% endif %}
|
||||||
{% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %}
|
{% 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>
|
<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 %}
|
{% 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>
|
<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>
|
||||||
|
|
|
@ -1099,7 +1099,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if not v or v.highlightcomments %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
<script defer src="{{'js/clipboard.js' | asset}}"></script>
|
<script defer src="{{'js/clipboard.js' | asset}}"></script>
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if not v or v.highlightcomments %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
{% include "popover.html" %}
|
{% include "popover.html" %}
|
||||||
|
|
Loading…
Reference in New Issue