follow-if-liked-fix
All checks were successful
Deploy on push / deploy (push) Successful in 25s

This commit is contained in:
Untone 2024-04-09 14:03:50 +03:00
parent 5e8c1ac30b
commit 1769b0925b
3 changed files with 39 additions and 22 deletions

View File

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

View File

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

View File

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