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