create-shout-handling
This commit is contained in:
parent
8216dd0d4e
commit
4eb98e7d0c
|
@ -5,10 +5,13 @@ from base.orm import local_session
|
|||
from base.resolvers import mutation
|
||||
from orm.rbac import Resource
|
||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||
from orm.collab import Collab
|
||||
from services.inbox import MessagesStorage
|
||||
from orm.topic import TopicFollower
|
||||
from orm.user import User
|
||||
from resolvers.zine.reactions import reactions_follow, reactions_unfollow
|
||||
from services.zine.gittask import GitTask
|
||||
from resolvers.inbox.chats import create_chat
|
||||
|
||||
|
||||
@mutation.field("createShout")
|
||||
|
@ -19,9 +22,29 @@ async def create_shout(_, info, inp):
|
|||
topic_slugs = inp.get("topic_slugs", [])
|
||||
if topic_slugs:
|
||||
del inp["topic_slugs"]
|
||||
|
||||
body = inp.get("body")
|
||||
with local_session() as session:
|
||||
new_shout = Shout.create(**inp)
|
||||
if body:
|
||||
# now we should create a draft shout (can be viewed only by authors)
|
||||
authors = inp.get("authors", [])
|
||||
new_shout = Shout.create({
|
||||
"title": inp.get("title", body[:12] + '...'),
|
||||
"body": body,
|
||||
"authors": authors
|
||||
})
|
||||
authors.remove(user.slug)
|
||||
if authors:
|
||||
chat = create_chat(None, info, new_shout.title, members=authors)
|
||||
# create a cooperative chatroom
|
||||
MessagesStorage.register_chat(chat)
|
||||
# now we should create a collab
|
||||
new_collab = Collab.create({
|
||||
"shout": new_shout.id,
|
||||
"authors": [user.slug, ],
|
||||
"invites": authors
|
||||
})
|
||||
session.add(new_collab)
|
||||
session.commit()
|
||||
|
||||
# NOTE: shout made by one first author
|
||||
sa = ShoutAuthor.create(shout=new_shout.slug, user=user.slug)
|
||||
|
|
|
@ -94,12 +94,13 @@ type ReactionUpdating {
|
|||
################################### Inputs ###################################
|
||||
|
||||
input ShoutInput {
|
||||
slug: String!
|
||||
body: String!
|
||||
community: String!
|
||||
mainTopic: String
|
||||
topic_slugs: [String]
|
||||
slug: String
|
||||
title: String
|
||||
body: String!
|
||||
authors: [String]
|
||||
topics: [String]
|
||||
community: Int
|
||||
mainTopic: String
|
||||
subtitle: String
|
||||
versionOf: String
|
||||
visibleForRoles: [String] # role ids are strings
|
||||
|
@ -165,8 +166,8 @@ type Mutation {
|
|||
confirmEmail(token: String!): AuthResult!
|
||||
|
||||
# shout
|
||||
createShout(input: ShoutInput!): Result!
|
||||
updateShout(input: ShoutInput!): Result!
|
||||
createShout(inp: ShoutInput!): Result!
|
||||
updateShout(inp: ShoutInput!): Result!
|
||||
deleteShout(slug: String!): Result!
|
||||
|
||||
# user profile
|
||||
|
@ -371,14 +372,6 @@ type User {
|
|||
oid: String
|
||||
}
|
||||
|
||||
type Collab {
|
||||
authors: [String]!
|
||||
invites: [String]
|
||||
createdAt: DateTime!
|
||||
title: String
|
||||
body: String
|
||||
}
|
||||
|
||||
enum ReactionKind {
|
||||
LIKE
|
||||
DISLIKE
|
||||
|
@ -524,3 +517,10 @@ type Chat {
|
|||
unread: Int
|
||||
private: Boolean
|
||||
}
|
||||
|
||||
type Collab {
|
||||
authors: [String]!
|
||||
invites: [String]
|
||||
shout: Shout
|
||||
chat: Chat
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user