This commit is contained in:
parent
5e8c1ac30b
commit
1769b0925b
|
@ -1,20 +1,31 @@
|
||||||
from orm.reaction import ReactionKind
|
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 = [
|
RATING_REACTIONS = [
|
||||||
ReactionKind.LIKE.value,
|
ReactionKind.LIKE.value,
|
||||||
ReactionKind.ACCEPT.value,
|
ReactionKind.DISLIKE.value
|
||||||
ReactionKind.AGREE.value,
|
|
||||||
ReactionKind.DISLIKE.value,
|
|
||||||
ReactionKind.REJECT.value,
|
|
||||||
ReactionKind.DISAGREE.value,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def is_negative(x):
|
def is_negative(x):
|
||||||
return x in [
|
return x in [
|
||||||
ReactionKind.ACCEPT.value,
|
ReactionKind.DISLIKE.value,
|
||||||
ReactionKind.LIKE.value,
|
ReactionKind.DISPROOF.value,
|
||||||
ReactionKind.PROOF.value,
|
ReactionKind.REJECT.value,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,13 @@ class ReactionKind(Enumeration):
|
||||||
DISAGREE = 'DISAGREE' # -1
|
DISAGREE = 'DISAGREE' # -1
|
||||||
ASK = 'ASK' # +0
|
ASK = 'ASK' # +0
|
||||||
PROPOSE = 'PROPOSE' # +0
|
PROPOSE = 'PROPOSE' # +0
|
||||||
PROOF = 'PROOF' # +1
|
|
||||||
DISPROOF = 'DISPROOF' # -1
|
|
||||||
ACCEPT = 'ACCEPT' # +1
|
ACCEPT = 'ACCEPT' # +1
|
||||||
REJECT = 'REJECT' # -1
|
REJECT = 'REJECT' # -1
|
||||||
|
|
||||||
|
# expert mode
|
||||||
|
PROOF = 'PROOF' # +1
|
||||||
|
DISPROOF = 'DISPROOF' # -1
|
||||||
|
|
||||||
# public feed
|
# public feed
|
||||||
QUOTE = 'QUOTE' # +0 TODO: use to bookmark in collection
|
QUOTE = 'QUOTE' # +0 TODO: use to bookmark in collection
|
||||||
COMMENT = 'COMMENT' # +0
|
COMMENT = 'COMMENT' # +0
|
||||||
|
|
|
@ -6,7 +6,7 @@ from sqlalchemy.orm import aliased, joinedload
|
||||||
from sqlalchemy.sql import union
|
from sqlalchemy.sql import union
|
||||||
|
|
||||||
from orm.author import Author
|
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.reaction import Reaction, ReactionKind
|
||||||
from orm.shout import Shout
|
from orm.shout import Shout
|
||||||
from resolvers.editor import handle_proposing
|
from resolvers.editor import handle_proposing
|
||||||
|
@ -124,19 +124,25 @@ async def _create_reaction(session, shout, author, reaction):
|
||||||
# collaborative editing
|
# collaborative editing
|
||||||
if (
|
if (
|
||||||
rdict.get('reply_to')
|
rdict.get('reply_to')
|
||||||
and r.kind in RATING_REACTIONS
|
and r.kind in PROPOSAL_REACTIONS
|
||||||
and author.id in shout.authors
|
and author.id in shout.authors
|
||||||
):
|
):
|
||||||
handle_proposing(session, r, shout)
|
handle_proposing(session, r, shout)
|
||||||
|
|
||||||
# self-regultaion mechanics
|
if r.kind in RATING_REACTIONS:
|
||||||
if check_to_unfeature(session, author.id, r):
|
# self-regultaion mechanics
|
||||||
set_unfeatured(session, shout.id)
|
if check_to_unfeature(session, author.id, r):
|
||||||
elif check_to_feature(session, author.id, r):
|
set_unfeatured(session, shout.id)
|
||||||
await set_featured(session, shout.id)
|
elif check_to_feature(session, author.id, r):
|
||||||
|
await set_featured(session, shout.id)
|
||||||
|
|
||||||
# reactions auto-following
|
# follow if liked
|
||||||
reactions_follow(author.id, reaction['shout'], True)
|
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['shout'] = shout.dict()
|
||||||
rdict['created_by'] = author.dict()
|
rdict['created_by'] = author.dict()
|
||||||
|
@ -208,9 +214,7 @@ async def create_reaction(_, info, reaction):
|
||||||
return {'error': 'cannot create reaction without a kind'}
|
return {'error': 'cannot create reaction without a kind'}
|
||||||
|
|
||||||
if kind in RATING_REACTIONS:
|
if kind in RATING_REACTIONS:
|
||||||
error_result = prepare_new_rating(
|
error_result = prepare_new_rating(reaction, shout_id, session, author)
|
||||||
reaction, shout_id, session, author
|
|
||||||
)
|
|
||||||
if error_result:
|
if error_result:
|
||||||
return error_result
|
return error_result
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user