master
Aevann1 2021-11-22 16:16:58 +02:00
parent 26ffa2ea43
commit 5f6eb77768
8 changed files with 23 additions and 25 deletions

View File

@ -11,15 +11,17 @@ def send_notification(uid, text, autojanny=False):
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
if autojanny: author_id = AUTOJANNY_ID
else: author_id = NOTIFICATIONS_ID
existing = g.db.query(Comment.id).filter(Comment.author_id == author_id, Comment.body_html == text_html, Comment.notifiedto == uid).first()
if existing: return
new_comment = Comment(author_id=author_id,
parent_submission=None,
distinguish_level=6,body=text,
distinguish_level=6,
body_html=text_html,
notifiedto=uid
)

View File

@ -995,15 +995,13 @@ def api_sticky_post(post_id, v):
if post.stickied:
if v.id != post.author_id:
message = f"@{v.username} has pinned your [post](/post/{post_id})!"
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message).first()
if not existing: send_notification(post.author_id, message)
send_notification(post.author_id, message)
g.db.commit()
return {"message": "Post pinned!"}
else:
if v.id != post.author_id:
message = f"@{v.username} has unpinned your [post](/post/{post_id})!"
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message).first()
if not existing: send_notification(post.author_id, message)
send_notification(post.author_id, message)
g.db.commit()
return {"message": "Post unpinned!"}

View File

@ -208,7 +208,7 @@ def api_comment(v):
Comment.deleted_utc == 0,
Comment.parent_comment_id == parent_comment_id,
Comment.parent_submission == parent_submission,
Comment.body == body
Comment.body_html == body_html
).first()
if existing: return {"error": f"You already made that comment: /comment/{existing.id}"}, 409
@ -885,15 +885,13 @@ def toggle_pin_comment(cid, v):
if comment.is_pinned:
if v.id != comment.author_id:
message = f"@{v.username} has pinned your [comment]({comment.permalink})!"
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message).first()
if not existing: send_notification(comment.author_id, message)
send_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment pinned!"}
else:
if v.id != comment.author_id:
message = f"@{v.username} has unpinned your [comment]({comment.permalink})!"
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message).first()
if not existing: send_notification(comment.author_id, message)
send_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment unpinned!"}

View File

@ -350,9 +350,7 @@ def edit_post(pid, v):
notify_users.add(541)
if ('idio3' in f'{body_html}{title}'.lower() or 'idio ' in f'{body_html}{title}'.lower()) and 30 not in notify_users: notify_users.add(30)
for x in notify_users:
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message)
for x in notify_users: send_notification(x, message)
if (title != p.title or body != p.body) and v.id == p.author_id:
@ -544,7 +542,7 @@ def submit_post(v):
url = url.replace("old.reddit.com/gallery", "new.reddit.com/gallery")
url = url.replace("https://mobile.twitter.com", "https://twitter.com").replace("https://m.facebook", "https://facebook").replace("https://m.wikipedia", "https://wikipedia").replace("https://m.youtube", "https://youtube")
if url.startswith("https://streamable.com/") and not url.startswith("https://streamable.com/e/"): url = url.replace("https://streamable.com/", "https://streamable.com/e/")
parsed_url = urlparse(url)

View File

@ -21,7 +21,9 @@ def api_flag_post(pid, v):
for i in re.finditer(':(.{1,30}?):', reason):
if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.webp'):
reason = reason.replace(f':{i.group(1)}:', f'<img loading="lazy" data-bs-toggle="tooltip" title="{i.group(1)}" delay="0" height=20 src="http://{site}/assets/images/emojis/{i.group(1)}.webp">')
reason = reason.replace(f':{i.group(1)}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{i.group(1)}:" title=":{i.group(1)}:" delay="0" height=20 src="http://{site}/assets/images/emojis/{i.group(1)}.webp">')
if len(reason) > 350: return {"error": f"Too long."}
flag = Flag(post_id=post.id,
user_id=v.id,
@ -53,7 +55,9 @@ def api_flag_comment(cid, v):
for i in re.finditer(':(.{1,30}?):', reason):
if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.webp'):
reason = reason.replace(f':{i.group(1)}:', f'<img loading="lazy" data-bs-toggle="tooltip" title="{i.group(1)}" delay="0" height=20 src="http://{site}/assets/images/emojis/{i.group(1)}.webp">')
reason = reason.replace(f':{i.group(1)}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{i.group(1)}:" title=":{i.group(1)}:" delay="0" height=20 src="http://{site}/assets/images/emojis/{i.group(1)}.webp">')
if len(reason) > 350: return {"error": f"Too long."}
flag = CommentFlag(comment_id=comment.id,
user_id=v.id,

View File

@ -244,8 +244,7 @@ def settings_profile_post(v):
for x in notify_users:
message = f"@{v.username} has added you to their friends list!"
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message)
send_notification(x, message)
v.friends = friends[:500]
v.friends_html=friends_html
@ -289,8 +288,7 @@ def settings_profile_post(v):
for x in notify_users:
message = f"@{v.username} has added you to their enemies list!"
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message)
send_notification(x, message)
v.enemies = enemies[:500]
v.enemies_html=enemies_html

View File

@ -848,7 +848,7 @@ def fp(v, fp):
new_alt = Alt(user1=v.id, user2=u.id)
g.db.add(new_alt)
g.db.flush()
print(v.username + ' + ' + u.username)
print('\n\n' + v.username + ' + ' + u.username + '\n\n')
g.db.add(v)
g.db.commit()
return ''

View File

@ -293,7 +293,7 @@
<a href="/views" class="btn btn-secondary">Profile views</a>
{% endif %}
{% if v and v.mute and not u.unmutable %}
{% if u.song and v and v.mute and not u.unmutable %}
<a id="pause1" class="btn btn-secondary" href="javascript:void(0)" onclick="pause()">Pause anthem</a>
<a id="play1" class="btn btn-secondary d-none" href="javascript:void(0)" onclick="play()">Play anthem</a>
{% endif %}
@ -425,7 +425,7 @@
{% endblock %}
{% block mobileUserBanner %}
<div class="container-fluid text-center bg-white d-md-none" style="margin-top:-3px; border-radius:0!important;">
<div class="container-fluid text-center bg-white d-md-none" style="margin-top:-4px;border-radius:0!important;">
<div class="row">
<div class="col px-0">
<a rel="nofollow noopener noreferrer" href="{{u.banner_url}}" {% if not v or v.newtabexternal %}target="_blank"{% endif %}>
@ -525,7 +525,7 @@
<a href="/views" class="btn btn-secondary">Profile views</a>
{% endif %}
{% if v and v.mute and not u.unmutable %}
{% if u.song and v and v.mute and not u.unmutable %}
<a id="pause2" class="btn btn-secondary" href="javascript:void(0)" onclick="pause()">Pause anthem</a>
<a id="play2" class="btn btn-secondary d-none" href="javascript:void(0)" onclick="play()">Play anthem</a>
{% endif %}