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 base.resolvers import mutation
|
||||||
from orm.rbac import Resource
|
from orm.rbac import Resource
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||||
|
from orm.collab import Collab
|
||||||
|
from services.inbox import MessagesStorage
|
||||||
from orm.topic import TopicFollower
|
from orm.topic import TopicFollower
|
||||||
from orm.user import User
|
from orm.user import User
|
||||||
from resolvers.zine.reactions import reactions_follow, reactions_unfollow
|
from resolvers.zine.reactions import reactions_follow, reactions_unfollow
|
||||||
from services.zine.gittask import GitTask
|
from services.zine.gittask import GitTask
|
||||||
|
from resolvers.inbox.chats import create_chat
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("createShout")
|
@mutation.field("createShout")
|
||||||
|
@ -19,9 +22,29 @@ async def create_shout(_, info, inp):
|
||||||
topic_slugs = inp.get("topic_slugs", [])
|
topic_slugs = inp.get("topic_slugs", [])
|
||||||
if topic_slugs:
|
if topic_slugs:
|
||||||
del inp["topic_slugs"]
|
del inp["topic_slugs"]
|
||||||
|
body = inp.get("body")
|
||||||
with local_session() as session:
|
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
|
# NOTE: shout made by one first author
|
||||||
sa = ShoutAuthor.create(shout=new_shout.slug, user=user.slug)
|
sa = ShoutAuthor.create(shout=new_shout.slug, user=user.slug)
|
||||||
|
|
|
@ -94,12 +94,13 @@ type ReactionUpdating {
|
||||||
################################### Inputs ###################################
|
################################### Inputs ###################################
|
||||||
|
|
||||||
input ShoutInput {
|
input ShoutInput {
|
||||||
slug: String!
|
slug: String
|
||||||
body: String!
|
|
||||||
community: String!
|
|
||||||
mainTopic: String
|
|
||||||
topic_slugs: [String]
|
|
||||||
title: String
|
title: String
|
||||||
|
body: String!
|
||||||
|
authors: [String]
|
||||||
|
topics: [String]
|
||||||
|
community: Int
|
||||||
|
mainTopic: String
|
||||||
subtitle: String
|
subtitle: String
|
||||||
versionOf: String
|
versionOf: String
|
||||||
visibleForRoles: [String] # role ids are strings
|
visibleForRoles: [String] # role ids are strings
|
||||||
|
@ -165,8 +166,8 @@ type Mutation {
|
||||||
confirmEmail(token: String!): AuthResult!
|
confirmEmail(token: String!): AuthResult!
|
||||||
|
|
||||||
# shout
|
# shout
|
||||||
createShout(input: ShoutInput!): Result!
|
createShout(inp: ShoutInput!): Result!
|
||||||
updateShout(input: ShoutInput!): Result!
|
updateShout(inp: ShoutInput!): Result!
|
||||||
deleteShout(slug: String!): Result!
|
deleteShout(slug: String!): Result!
|
||||||
|
|
||||||
# user profile
|
# user profile
|
||||||
|
@ -371,14 +372,6 @@ type User {
|
||||||
oid: String
|
oid: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type Collab {
|
|
||||||
authors: [String]!
|
|
||||||
invites: [String]
|
|
||||||
createdAt: DateTime!
|
|
||||||
title: String
|
|
||||||
body: String
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ReactionKind {
|
enum ReactionKind {
|
||||||
LIKE
|
LIKE
|
||||||
DISLIKE
|
DISLIKE
|
||||||
|
@ -524,3 +517,10 @@ type Chat {
|
||||||
unread: Int
|
unread: Int
|
||||||
private: Boolean
|
private: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Collab {
|
||||||
|
authors: [String]!
|
||||||
|
invites: [String]
|
||||||
|
shout: Shout
|
||||||
|
chat: Chat
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user