This commit is contained in:
parent
909ddbd79d
commit
caa2dbfdf3
|
@ -1,3 +1,6 @@
|
|||
[0.2.16]
|
||||
- schema: Reaction.range -> Reaction.quote
|
||||
|
||||
[0.2.15]
|
||||
- schema: Shout.created_by removed
|
||||
- schema: Shout.mainTopic removed
|
||||
|
|
|
@ -7,21 +7,23 @@ from services.db import Base
|
|||
|
||||
|
||||
class ReactionKind(Enumeration):
|
||||
# TYPE = <reaction index> # rating diff
|
||||
|
||||
# editor mode
|
||||
AGREE = 1 # +1
|
||||
DISAGREE = 2 # -1
|
||||
PROOF = 3 # +1
|
||||
DISPROOF = 4 # -1
|
||||
ASK = 5 # +0
|
||||
PROPOSE = 6 # +0
|
||||
QUOTE = 7 # +0 bookmark
|
||||
COMMENT = 8 # +0
|
||||
ACCEPT = 9 # +1
|
||||
REJECT = 0 # -1
|
||||
ASK = 3 # +0
|
||||
PROPOSE = 4 # +0
|
||||
PROOF = 5 # +1
|
||||
DISPROOF = 6 # -1
|
||||
ACCEPT = 7 # +1
|
||||
REJECT = 8 # -1
|
||||
|
||||
# public feed
|
||||
QUOTE = 9 # +0 bookmark
|
||||
COMMENT = 0 # +0
|
||||
LIKE = 11 # +1
|
||||
DISLIKE = 12 # -1
|
||||
REMARK = 13 # 0
|
||||
FOOTNOTE = 14 # 0
|
||||
# TYPE = <reaction index> # rating diff
|
||||
|
||||
|
||||
class Reaction(Base):
|
||||
|
@ -35,7 +37,7 @@ class Reaction(Base):
|
|||
deleted_by = Column(ForeignKey("author.id"), nullable=True, index=True)
|
||||
shout = Column(ForeignKey("shout.id"), nullable=False, index=True)
|
||||
reply_to = Column(ForeignKey("reaction.id"), nullable=True)
|
||||
range = Column(String, nullable=True, comment="<start index>:<end>")
|
||||
quote = Column(String, nullable=True, comment="Original quoted text")
|
||||
kind = Column(Enum(ReactionKind), nullable=False)
|
||||
|
||||
oid = Column(String)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "discoursio-core"
|
||||
version = "0.2.15"
|
||||
version = "0.2.16"
|
||||
description = "core module for discours.io"
|
||||
authors = ["discoursio devteam"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -138,14 +138,14 @@ async def get_authors_all(_, _info):
|
|||
|
||||
|
||||
@query.field("getAuthor")
|
||||
async def get_author(_, _info, slug="", user=None, author=None):
|
||||
if slug or user or author:
|
||||
async def get_author(_, _info, slug="", user=None, author_id=None):
|
||||
if slug or user or author_id:
|
||||
if slug:
|
||||
q = select(Author).where(Author.slug == slug)
|
||||
elif user:
|
||||
q = select(Author).where(Author.user == user)
|
||||
elif author:
|
||||
q = select(Author).where(Author.id == author)
|
||||
elif author_id:
|
||||
q = select(Author).where(Author.id == author_id)
|
||||
q = add_author_stat_columns(q)
|
||||
|
||||
authors = get_authors_from_query(q)
|
||||
|
|
|
@ -163,81 +163,82 @@ async def create_reaction(_, info, reaction):
|
|||
with local_session() as session:
|
||||
shout = session.query(Shout).where(Shout.id == reaction["shout"]).one()
|
||||
author = session.query(Author).where(Author.user == user_id).first()
|
||||
reaction["created_by"] = author.id
|
||||
if reaction["kind"] in [ReactionKind.DISLIKE.name, ReactionKind.LIKE.name]:
|
||||
existing_reaction = (
|
||||
session.query(Reaction)
|
||||
.where(
|
||||
and_(
|
||||
Reaction.shout == reaction["shout"],
|
||||
Reaction.created_by == author.id,
|
||||
Reaction.kind == reaction["kind"],
|
||||
Reaction.reply_to == reaction.get("reply_to"),
|
||||
if shout and author:
|
||||
reaction["created_by"] = author.id
|
||||
if reaction["kind"] in [ReactionKind.DISLIKE.name, ReactionKind.LIKE.name]:
|
||||
existing_reaction = (
|
||||
session.query(Reaction)
|
||||
.where(
|
||||
and_(
|
||||
Reaction.shout == reaction["shout"],
|
||||
Reaction.created_by == author.id,
|
||||
Reaction.kind == reaction["kind"],
|
||||
Reaction.reply_to == reaction.get("reply_to"),
|
||||
)
|
||||
)
|
||||
.first()
|
||||
)
|
||||
.first()
|
||||
)
|
||||
|
||||
if existing_reaction is not None:
|
||||
return {"error": "You can't vote twice"}
|
||||
if existing_reaction is not None:
|
||||
return {"error": "You can't vote twice"}
|
||||
|
||||
opposite_reaction_kind = (
|
||||
ReactionKind.DISLIKE if reaction["kind"] == ReactionKind.LIKE.name else ReactionKind.LIKE
|
||||
)
|
||||
opposite_reaction = (
|
||||
session.query(Reaction)
|
||||
.where(
|
||||
and_(
|
||||
Reaction.shout == reaction["shout"],
|
||||
Reaction.created_by == author.id,
|
||||
Reaction.kind == opposite_reaction_kind,
|
||||
Reaction.reply_to == reaction.get("reply_to"),
|
||||
opposite_reaction_kind = (
|
||||
ReactionKind.DISLIKE if reaction["kind"] == ReactionKind.LIKE.name else ReactionKind.LIKE
|
||||
)
|
||||
opposite_reaction = (
|
||||
session.query(Reaction)
|
||||
.where(
|
||||
and_(
|
||||
Reaction.shout == reaction["shout"],
|
||||
Reaction.created_by == author.id,
|
||||
Reaction.kind == opposite_reaction_kind,
|
||||
Reaction.reply_to == reaction.get("reply_to"),
|
||||
)
|
||||
)
|
||||
.first()
|
||||
)
|
||||
.first()
|
||||
)
|
||||
|
||||
if opposite_reaction is not None:
|
||||
session.delete(opposite_reaction)
|
||||
if opposite_reaction is not None:
|
||||
session.delete(opposite_reaction)
|
||||
|
||||
r = Reaction(**reaction)
|
||||
r = Reaction(**reaction)
|
||||
|
||||
# Proposal accepting logix
|
||||
if r.reply_to is not None and r.kind == ReactionKind.ACCEPT and author.id in shout.dict()["authors"]:
|
||||
replied_reaction = session.query(Reaction).where(Reaction.id == r.reply_to).first()
|
||||
if replied_reaction and replied_reaction.kind == ReactionKind.PROPOSE:
|
||||
if replied_reaction.range:
|
||||
old_body = shout.body
|
||||
start, end = replied_reaction.range.split(":")
|
||||
start = int(start)
|
||||
end = int(end)
|
||||
new_body = old_body[:start] + replied_reaction.body + old_body[end:]
|
||||
shout.body = new_body
|
||||
# Proposal accepting logix
|
||||
if r.reply_to is not None and r.kind == ReactionKind.ACCEPT and author.id in shout.dict()["authors"]:
|
||||
replied_reaction = session.query(Reaction).where(Reaction.id == r.reply_to).first()
|
||||
if replied_reaction and replied_reaction.kind == ReactionKind.PROPOSE:
|
||||
if replied_reaction.range:
|
||||
old_body = shout.body
|
||||
start, end = replied_reaction.range.split(":")
|
||||
start = int(start)
|
||||
end = int(end)
|
||||
new_body = old_body[:start] + replied_reaction.body + old_body[end:]
|
||||
shout.body = new_body
|
||||
|
||||
session.add(r)
|
||||
session.commit()
|
||||
rdict = r.dict()
|
||||
rdict["shout"] = shout.dict()
|
||||
rdict["created_by"] = author.dict()
|
||||
session.add(r)
|
||||
session.commit()
|
||||
rdict = r.dict()
|
||||
rdict["shout"] = shout.dict()
|
||||
rdict["created_by"] = author.dict()
|
||||
|
||||
# self-regulation mechanics
|
||||
# self-regulation mechanics
|
||||
|
||||
if check_to_hide(session, r):
|
||||
set_hidden(session, r.shout)
|
||||
elif check_to_publish(session, author.id, r):
|
||||
set_published(session, r.shout)
|
||||
if check_to_hide(session, r):
|
||||
set_hidden(session, r.shout)
|
||||
elif check_to_publish(session, author.id, r):
|
||||
set_published(session, r.shout)
|
||||
|
||||
try:
|
||||
reactions_follow(author.id, reaction["shout"], True)
|
||||
except Exception as e:
|
||||
print(f"[resolvers.reactions] error on reactions auto following: {e}")
|
||||
try:
|
||||
reactions_follow(author.id, reaction["shout"], True)
|
||||
except Exception as e:
|
||||
print(f"[resolvers.reactions] error on reactions auto following: {e}")
|
||||
|
||||
rdict["stat"] = {"commented": 0, "reacted": 0, "rating": 0}
|
||||
rdict["stat"] = {"commented": 0, "reacted": 0, "rating": 0}
|
||||
|
||||
# notifications call
|
||||
await notify_reaction(rdict, "create")
|
||||
# notifications call
|
||||
await notify_reaction(rdict, "create")
|
||||
|
||||
return {"reaction": rdict}
|
||||
return {"reaction": rdict}
|
||||
|
||||
|
||||
@mutation.field("updateReaction")
|
||||
|
|
|
@ -210,7 +210,7 @@ input TopicInput {
|
|||
input ReactionInput {
|
||||
kind: ReactionKind!
|
||||
shout: Int!
|
||||
range: String
|
||||
quote: String
|
||||
body: String
|
||||
reply_to: Int
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user