fix emojis in polls

pull/136/head
Aevann 2023-03-01 00:56:46 +02:00
parent 089bac8dc6
commit 17330c073b
5 changed files with 8 additions and 17 deletions

View File

@ -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

View File

@ -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)

View File

@ -324,8 +324,8 @@ class Submission(Base):
elif o.exclusive: s = '&amp;&amp;'
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

View File

@ -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)

View File

@ -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;