From 17330c073b817490b16dbc5fd4a822b859c68048 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 1 Mar 2023 00:56:46 +0200 Subject: [PATCH] fix emojis in polls --- files/classes/comment.py | 4 ++-- files/classes/polls.py | 2 -- files/classes/submission.py | 4 ++-- files/helpers/actions.py | 7 ++++--- migrations/20230228-position-options.sql | 8 -------- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index aadf8f4d4..48e728203 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -295,8 +295,8 @@ class Comment(Base): elif o.exclusive: s = '&&' else: s = '$$' - if f'{s}{o.body}{s}' in body: - body = body.replace(f'{s}{o.body}{s}', option_body) + if f'{s}{o.body_html}{s}' in body: + body = body.replace(f'{s}{o.body_html}{s}', option_body) elif not o.created_utc or o.created_utc < 1677622270: body += option_body diff --git a/files/classes/polls.py b/files/classes/polls.py index 3578b4219..154cf4fc3 100644 --- a/files/classes/polls.py +++ b/files/classes/polls.py @@ -12,7 +12,6 @@ class SubmissionOption(Base): id = Column(Integer, primary_key=True) parent_id = Column(Integer, ForeignKey("submissions.id")) - body = Column(Text) body_html = Column(Text) exclusive = Column(Integer) created_utc = Column(Integer) @@ -68,7 +67,6 @@ class CommentOption(Base): id = Column(Integer, primary_key=True) parent_id = Column(Integer, ForeignKey("comments.id")) - body = Column(Text) body_html = Column(Text) exclusive = Column(Integer) created_utc = Column(Integer) diff --git a/files/classes/submission.py b/files/classes/submission.py index 50622a2b0..dbfddf0e8 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -324,8 +324,8 @@ class Submission(Base): elif o.exclusive: s = '&&' else: s = '$$' - if f'{s}{o.body}{s}' in body: - body = body.replace(f'{s}{o.body}{s}', option_body) + if f'{s}{o.body_html}{s}' in body: + body = body.replace(f'{s}{o.body_html}{s}', option_body) elif not o.created_utc or o.created_utc < 1677622270: body += option_body diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 2822e84e1..4f423bce0 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -500,18 +500,19 @@ def process_poll_options(v:User, target:Union[Submission, Comment]): else: cls = CommentOption + body_html=filter_emojis_only(body) + g.db.flush() existing = g.db.query(cls).filter_by( parent_id=target.id, - body=body, + body_html=body_html, exclusive=exclusive, ).one_or_none() if not existing: option = cls( parent_id=target.id, - body=body, - body_html=filter_emojis_only(body), + body_html=body_html, exclusive=exclusive, ) g.db.add(option) diff --git a/migrations/20230228-position-options.sql b/migrations/20230228-position-options.sql index ed2c6031c..3b0d9d3d8 100644 --- a/migrations/20230228-position-options.sql +++ b/migrations/20230228-position-options.sql @@ -1,11 +1,3 @@ -alter table submission_options add column body character varying(500); -update submission_options set body=body_html; -alter table submission_options alter column body set not null; - -alter table comment_options add column body character varying(500); -update comment_options set body=body_html; -alter table comment_options alter column body set not null; - alter table submission_options rename column submission_id to parent_id; alter table comment_options rename column comment_id to parent_id;