From 1769b0925b0b8ef67576976805bc119c567d3b5a Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 9 Apr 2024 14:03:50 +0300 Subject: [PATCH] follow-if-liked-fix --- orm/rating.py | 27 +++++++++++++++++++-------- orm/reaction.py | 6 ++++-- resolvers/reaction.py | 28 ++++++++++++++++------------ 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/orm/rating.py b/orm/rating.py index eebaad90..9cff6ad7 100644 --- a/orm/rating.py +++ b/orm/rating.py @@ -1,20 +1,31 @@ from orm.reaction import ReactionKind + +PROPOSAL_REACTIONS = [ + ReactionKind.ACCEPT.value, + ReactionKind.REJECT.value, + ReactionKind.AGREE.value, + ReactionKind.DISAGREE.value, + ReactionKind.ASK.value, + ReactionKind.PROPOSE.value, +] + +PROOF_REACTIONS = [ + ReactionKind.PROOF.value, + ReactionKind.DISPROOF.value +] + RATING_REACTIONS = [ ReactionKind.LIKE.value, - ReactionKind.ACCEPT.value, - ReactionKind.AGREE.value, - ReactionKind.DISLIKE.value, - ReactionKind.REJECT.value, - ReactionKind.DISAGREE.value, + ReactionKind.DISLIKE.value ] def is_negative(x): return x in [ - ReactionKind.ACCEPT.value, - ReactionKind.LIKE.value, - ReactionKind.PROOF.value, + ReactionKind.DISLIKE.value, + ReactionKind.DISPROOF.value, + ReactionKind.REJECT.value, ] diff --git a/orm/reaction.py b/orm/reaction.py index cfcc008c..e1e9d694 100644 --- a/orm/reaction.py +++ b/orm/reaction.py @@ -14,11 +14,13 @@ class ReactionKind(Enumeration): DISAGREE = 'DISAGREE' # -1 ASK = 'ASK' # +0 PROPOSE = 'PROPOSE' # +0 - PROOF = 'PROOF' # +1 - DISPROOF = 'DISPROOF' # -1 ACCEPT = 'ACCEPT' # +1 REJECT = 'REJECT' # -1 + # expert mode + PROOF = 'PROOF' # +1 + DISPROOF = 'DISPROOF' # -1 + # public feed QUOTE = 'QUOTE' # +0 TODO: use to bookmark in collection COMMENT = 'COMMENT' # +0 diff --git a/resolvers/reaction.py b/resolvers/reaction.py index a2a3af3e..c7425ab2 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -6,7 +6,7 @@ from sqlalchemy.orm import aliased, joinedload from sqlalchemy.sql import union from orm.author import Author -from orm.rating import RATING_REACTIONS, is_negative, is_positive +from orm.rating import PROPOSAL_REACTIONS, RATING_REACTIONS, is_negative, is_positive from orm.reaction import Reaction, ReactionKind from orm.shout import Shout from resolvers.editor import handle_proposing @@ -124,19 +124,25 @@ async def _create_reaction(session, shout, author, reaction): # collaborative editing if ( rdict.get('reply_to') - and r.kind in RATING_REACTIONS + and r.kind in PROPOSAL_REACTIONS and author.id in shout.authors ): handle_proposing(session, r, shout) - # self-regultaion mechanics - if check_to_unfeature(session, author.id, r): - set_unfeatured(session, shout.id) - elif check_to_feature(session, author.id, r): - await set_featured(session, shout.id) + if r.kind in RATING_REACTIONS: + # self-regultaion mechanics + if check_to_unfeature(session, author.id, r): + set_unfeatured(session, shout.id) + elif check_to_feature(session, author.id, r): + await set_featured(session, shout.id) - # reactions auto-following - reactions_follow(author.id, reaction['shout'], True) + # follow if liked + if r.kind == ReactionKind.LIKE.value: + try: + # reactions auto-following + reactions_follow(author.id, reaction['shout'], True) + except Exception: + pass rdict['shout'] = shout.dict() rdict['created_by'] = author.dict() @@ -208,9 +214,7 @@ async def create_reaction(_, info, reaction): return {'error': 'cannot create reaction without a kind'} if kind in RATING_REACTIONS: - error_result = prepare_new_rating( - reaction, shout_id, session, author - ) + error_result = prepare_new_rating(reaction, shout_id, session, author) if error_result: return error_result