remotes/1693045480750635534/spooky-22
Aevann1 2021-09-23 00:27:09 +02:00
parent 5005e55ca4
commit 235e2926b9
5 changed files with 26 additions and 40 deletions

View File

@ -16,7 +16,6 @@ def send_notification(vid, user, text):
uid = user.id
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
@ -42,8 +41,6 @@ def send_notification(vid, user, text):
def send_follow_notif(vid, user, text):
text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
@ -67,8 +64,6 @@ def send_follow_notif(vid, user, text):
def send_unfollow_notif(vid, user, text):
text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
@ -92,8 +87,6 @@ def send_unfollow_notif(vid, user, text):
def send_block_notif(vid, user, text):
text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
@ -117,8 +110,6 @@ def send_block_notif(vid, user, text):
def send_unblock_notif(vid, user, text):
text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
@ -142,32 +133,9 @@ def send_unblock_notif(vid, user, text):
def send_pm(vid, user, text):
text_html = Renderer().render(mistletoe.Document(text))
text_html = sanitize(text_html, True)
new_comment = Comment(author_id=vid,
parent_submission=None,
level=1,
sentto=user.id
)
g.db.add(new_comment)
g.db.flush()
new_aux = CommentAux(id=new_comment.id, body=text, body_html=text_html)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, user_id=user.id)
g.db.add(notif)
def send_admin(vid, text):
text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
text = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', text)
text_html = Renderer().render(mistletoe.Document(text))

View File

@ -976,7 +976,6 @@ def ban_post(post_id, v):
post.removed_by = v.id
ban_reason=request.values.get("reason", "")
ban_reason = ban_reason.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
ban_reason = CustomRenderer().render(mistletoe.Document(ban_reason))
ban_reason = sanitize(ban_reason)

View File

@ -240,6 +240,7 @@ def edit_post(pid, v):
if body != p.body:
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE):
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})')
body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_html = sanitize(body_md)
@ -788,7 +789,7 @@ def submit_post(v):
# render text
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE):
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})')
body = body.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_html = sanitize(body_md)

View File

@ -101,7 +101,7 @@ def settings_profile_post(v):
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', bio, re.MULTILINE):
if "wikipedia" not in i.group(1): bio = bio.replace(i.group(1), f'![]({i.group(1)})')
bio = bio.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
bio = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', bio)
# check for uploaded image
if request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":

View File

@ -224,8 +224,6 @@ def message2(v, username):
if hasattr(user, 'is_blocked') and user.is_blocked: return {"error": "This user is blocking you."}, 403
message = request.values.get("message", "")[:1000].strip()
message = message.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
# check existing
existing = g.db.query(Comment).join(CommentAux).options(lazyload('*')).filter(Comment.author_id == v.id,
Comment.sentto == user.id,
@ -233,7 +231,27 @@ def message2(v, username):
).options(contains_eager(Comment.comment_aux)).first()
if existing: return redirect('/notifications?messages=true')
send_pm(v.id, user, message)
text = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', message)
text_html = Renderer().render(mistletoe.Document(text))
text_html = sanitize(text_html, True)
new_comment = Comment(author_id=v.id,
parent_submission=None,
level=1,
sentto=user.id
)
g.db.add(new_comment)
g.db.flush()
new_aux = CommentAux(id=new_comment.id, body=text, body_html=text_html)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, user_id=user.id)
g.db.add(notif)
try:
beams_client.publish_to_interests(
@ -264,7 +282,7 @@ def messagereply(v):
id = int(request.values.get("parent_id"))
parent = get_comment(id, v=v)
user = parent.author
message = message.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
message = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', message)
# check existing
existing = g.db.query(Comment).join(CommentAux).options(lazyload('*')).filter(Comment.author_id == v.id,