reactions-for-slugs
This commit is contained in:
parent
1f40e55f83
commit
fe13488584
|
@ -25,6 +25,7 @@ class Reaction(Base):
|
||||||
return {
|
return {
|
||||||
"viewed": await ViewedStorage.get_reaction(self.id),
|
"viewed": await ViewedStorage.get_reaction(self.id),
|
||||||
"reacted": len(await ReactedStorage.get_reaction(self.id)),
|
"reacted": len(await ReactedStorage.get_reaction(self.id)),
|
||||||
|
# TODO: "replied"
|
||||||
"rating": await ReactedStorage.get_reaction_rating(self.id),
|
"rating": await ReactedStorage.get_reaction_rating(self.id),
|
||||||
"commented": len(await ReactedStorage.get_reaction_comments(self.id))
|
"commented": len(await ReactedStorage.get_reaction_comments(self.id))
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,9 +50,9 @@ def reactions_unfollow(user, slug):
|
||||||
@login_required
|
@login_required
|
||||||
async def create_reaction(_, info, inp):
|
async def create_reaction(_, info, inp):
|
||||||
user = info.context["request"].user
|
user = info.context["request"].user
|
||||||
|
|
||||||
# TODO: filter allowed reaction kinds
|
# TODO: filter allowed reaction kinds
|
||||||
|
|
||||||
reaction = Reaction.create(**inp)
|
reaction = Reaction.create(**inp)
|
||||||
ReactedStorage.increment(reaction.shout, reaction.replyTo)
|
ReactedStorage.increment(reaction.shout, reaction.replyTo)
|
||||||
try:
|
try:
|
||||||
|
@ -116,6 +116,19 @@ async def get_shout_reactions(_, info, slug, page, size):
|
||||||
r.createdBy = await UserStorage.get_user(r.createdBy or 'discours')
|
r.createdBy = await UserStorage.get_user(r.createdBy or 'discours')
|
||||||
return reactions
|
return reactions
|
||||||
|
|
||||||
|
@query.field("reactionsForSlugs")
|
||||||
|
async def get_shout_reactions(_, info, slugs, page, size):
|
||||||
|
offset = page * size
|
||||||
|
reactions = []
|
||||||
|
with local_session() as session:
|
||||||
|
for slug in slugs:
|
||||||
|
reactions += session.query(Reaction).\
|
||||||
|
filter(Reaction.shout == slug).\
|
||||||
|
limit(size).offset(offset).all()
|
||||||
|
for r in reactions:
|
||||||
|
r.createdBy = await UserStorage.get_user(r.createdBy or 'discours')
|
||||||
|
return reactions
|
||||||
|
|
||||||
|
|
||||||
@query.field("reactionsAll")
|
@query.field("reactionsAll")
|
||||||
async def get_all_reactions(_, info, page=1, size=10):
|
async def get_all_reactions(_, info, page=1, size=10):
|
||||||
|
@ -140,4 +153,4 @@ async def get_reactions_by_author(_, info, slug, page=1, size=50):
|
||||||
reactions = session.query(Reaction).filter(Reaction.createdBy == slug).limit(size).offset(offset)
|
reactions = session.query(Reaction).filter(Reaction.createdBy == slug).limit(size).offset(offset)
|
||||||
for r in reactions:
|
for r in reactions:
|
||||||
r.createdBy = await UserStorage.get_user(r.createdBy or 'discours')
|
r.createdBy = await UserStorage.get_user(r.createdBy or 'discours')
|
||||||
return reactions
|
return reactions
|
||||||
|
|
|
@ -242,6 +242,7 @@ type Query {
|
||||||
reactionsAll(page: Int!, size: Int!): [Reaction]!
|
reactionsAll(page: Int!, size: Int!): [Reaction]!
|
||||||
reactionsByAuthor(slug: String!, page: Int!, size: Int!): [Reaction]!
|
reactionsByAuthor(slug: String!, page: Int!, size: Int!): [Reaction]!
|
||||||
reactionsByShout(slug: String!, page: Int!, size: Int!): [Reaction]!
|
reactionsByShout(slug: String!, page: Int!, size: Int!): [Reaction]!
|
||||||
|
reactionsForSlugs(slugs: [String]!, page: Int!, size: Int!): [Reaction]!
|
||||||
|
|
||||||
# collab
|
# collab
|
||||||
inviteAuthor(slug: String!, author: String!): Result!
|
inviteAuthor(slug: String!, author: String!): Result!
|
||||||
|
@ -347,13 +348,13 @@ enum ReactionKind {
|
||||||
|
|
||||||
PROOF
|
PROOF
|
||||||
DISPROOF
|
DISPROOF
|
||||||
|
|
||||||
COMMENT
|
COMMENT
|
||||||
QUOTE
|
QUOTE
|
||||||
|
|
||||||
PROPOSE
|
PROPOSE
|
||||||
ASK
|
ASK
|
||||||
|
|
||||||
ACCEPT
|
ACCEPT
|
||||||
REJECT
|
REJECT
|
||||||
}
|
}
|
||||||
|
@ -379,7 +380,7 @@ type Author {
|
||||||
slug: String!
|
slug: String!
|
||||||
name: String!
|
name: String!
|
||||||
userpic: String
|
userpic: String
|
||||||
caption: String # only for full shout
|
caption: String # only for full shout
|
||||||
bio: String
|
bio: String
|
||||||
links: [String]
|
links: [String]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user