reaction-fix
This commit is contained in:
parent
cd955ecf8a
commit
3454766063
|
@ -146,8 +146,8 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
|
|||
if publish:
|
||||
if shout.visibility is ShoutVisibility.AUTHORS:
|
||||
shout_dict = shout.dict()
|
||||
shout_dict['visibility'] = ShoutVisibility.COMMUNITY
|
||||
shout_dict['published_at'] = current_time # Set published_at as Unix timestamp
|
||||
shout_dict["visibility"] = ShoutVisibility.COMMUNITY
|
||||
shout_dict["published_at"] = current_time # Set published_at as Unix timestamp
|
||||
Shout.update(shout, shout_dict)
|
||||
session.add(shout)
|
||||
await notify_shout(shout.dict(), "public")
|
||||
|
@ -175,7 +175,7 @@ async def delete_shout(_, info, shout_id):
|
|||
# Replace datetime with Unix timestamp
|
||||
current_time = int(time.time())
|
||||
shout_dict = shout.dict()
|
||||
shout_dict['deleted_at'] = current_time # Set deleted_at as Unix timestamp
|
||||
shout_dict["deleted_at"] = current_time # Set deleted_at as Unix timestamp
|
||||
Shout.update(shout, shout_dict)
|
||||
session.add(shout)
|
||||
session.commit()
|
||||
|
|
|
@ -17,7 +17,7 @@ def add_reaction_stat_columns(q):
|
|||
|
||||
q = q.outerjoin(aliased_reaction, Reaction.id == aliased_reaction.reply_to).add_columns(
|
||||
func.sum(aliased_reaction.id).label("reacted_stat"),
|
||||
func.sum(case((aliased_reaction.body != "", 1), else_=0)).label("commented_stat"),
|
||||
func.sum(case((aliased_reaction.kind == ReactionKind.COMMENT, 1), else_=0)).label("commented_stat"),
|
||||
func.sum(
|
||||
case(
|
||||
(aliased_reaction.kind == ReactionKind.AGREE, 1),
|
||||
|
@ -91,7 +91,7 @@ def is_published_author(session, author_id):
|
|||
return (
|
||||
session.query(Shout)
|
||||
.where(Shout.authors.contains(author_id))
|
||||
.filter(and_(Shout.published_at !="", Shout.deleted_at.is_(None)))
|
||||
.filter(and_(Shout.published_at != "", Shout.deleted_at.is_(None)))
|
||||
.count()
|
||||
> 0
|
||||
)
|
||||
|
@ -216,7 +216,7 @@ async def create_reaction(_, info, reaction):
|
|||
end = int(end)
|
||||
new_body = old_body[:start] + replied_reaction.body + old_body[end:]
|
||||
shout_dict = shout.dict()
|
||||
shout_dict['body'] = new_body
|
||||
shout_dict["body"] = new_body
|
||||
Shout.update(shout, shout_dict)
|
||||
|
||||
session.add(r)
|
||||
|
@ -339,7 +339,7 @@ def apply_reaction_filters(by, q):
|
|||
# NOTE: not using ElasticSearch here
|
||||
by_search = by.get("search", "")
|
||||
if len(by_search) > 2:
|
||||
q = q.filter(Reaction.body.ilike(f'%{by_search}%'))
|
||||
q = q.filter(Reaction.body.ilike(f"%{by_search}%"))
|
||||
|
||||
if by.get("after"):
|
||||
after = int(by["after"])
|
||||
|
@ -440,7 +440,7 @@ async def load_shouts_followed(_, info, limit=50, offset=0) -> List[Shout]:
|
|||
with local_session() as session:
|
||||
author = session.query(Author).filter(Author.user == user_id).first()
|
||||
if author:
|
||||
author_id: int = author.dict()['id']
|
||||
author_id: int = author.dict()["id"]
|
||||
shouts = reacted_shouts_updates(author_id, limit, offset)
|
||||
return shouts
|
||||
else:
|
||||
|
|
|
@ -51,9 +51,11 @@ def apply_filters(q, filters, author_id=None):
|
|||
by_visibility = filters.get("visibility")
|
||||
if by_visibility:
|
||||
visibility = {
|
||||
'public': [ShoutVisibility.PUBLIC,],
|
||||
'community': [ShoutVisibility.PUBLIC, ShoutVisibility.COMMUNITY],
|
||||
'authors': [ShoutVisibility.PUBLIC, ShoutVisibility.COMMUNITY, ShoutVisibility.AUTHORS]
|
||||
"public": [
|
||||
ShoutVisibility.PUBLIC,
|
||||
],
|
||||
"community": [ShoutVisibility.PUBLIC, ShoutVisibility.COMMUNITY],
|
||||
"authors": [ShoutVisibility.PUBLIC, ShoutVisibility.COMMUNITY, ShoutVisibility.AUTHORS],
|
||||
}
|
||||
q = q.filter(Shout.visibility.in_(visibility.get(by_visibility) or []))
|
||||
by_layouts = filters.get("layouts")
|
||||
|
@ -114,7 +116,11 @@ async def get_shout(_, _info, slug=None, shout_id=None):
|
|||
if author.id == author_caption.author:
|
||||
author.caption = author_caption.caption
|
||||
return shout
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
print(e)
|
||||
return None
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user