shout create
This commit is contained in:
parent
31b4f8106c
commit
2e04d2cac5
|
@ -15,7 +15,6 @@ class ShoutTopic(Base):
|
||||||
id = None # type: ignore
|
id = None # type: ignore
|
||||||
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
|
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
|
||||||
topic = Column(ForeignKey("topic.id"), primary_key=True, index=True)
|
topic = Column(ForeignKey("topic.id"), primary_key=True, index=True)
|
||||||
main = Column(Boolean, default=False)
|
|
||||||
|
|
||||||
|
|
||||||
class ShoutReactionsFollower(Base):
|
class ShoutReactionsFollower(Base):
|
||||||
|
|
|
@ -22,58 +22,63 @@ from services.zine.gittask import GitTask
|
||||||
async def create_shout(_, info, inp):
|
async def create_shout(_, info, inp):
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
|
||||||
body = inp.get("body")
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
if body:
|
topics = session.query(Topic).filter(Topic.slug.in_(inp.get('topics', []))).all()
|
||||||
# now we should create a draft shout (can be viewed only by authors)
|
|
||||||
authors = inp.get("authors", [])
|
new_shout = Shout.create(**{
|
||||||
new_shout = Shout.create(**{
|
"title": inp.get("title"),
|
||||||
"title": inp.get("title", body[:12] + '...'),
|
"subtitle": inp.get('subtitle'),
|
||||||
"body": body,
|
"body": inp.get("body"),
|
||||||
"authors": authors,
|
"authors": inp.get("authors", []),
|
||||||
"slug": inp.get("slug"),
|
"slug": inp.get("slug"),
|
||||||
"topics": inp.get("topics", []),
|
"mainTopic": inp.get("mainTopic"),
|
||||||
"mainTopic": inp.get("topics", []).pop(),
|
"visibility": "community",
|
||||||
"visibility": "authors"
|
# "createdBy": auth.user_id
|
||||||
})
|
})
|
||||||
if auth.user_id in authors:
|
|
||||||
authors.remove(auth.user_id)
|
for topic in topics:
|
||||||
# Chat room code, uncomment it
|
t = ShoutTopic.create(topic=topic.id, shout=new_shout.id)
|
||||||
# if authors:
|
session.add(t)
|
||||||
# chat = create_chat(None, info, new_shout.title, members=authors)
|
|
||||||
# # create a cooperative chatroom
|
# if auth.user_id in authors:
|
||||||
# await MessagesStorage.register_chat(chat)
|
# authors.remove(auth.user_id)
|
||||||
# # now we should create a collab
|
# Chat room code, uncomment it
|
||||||
# new_collab = Collab.create({
|
# if authors:
|
||||||
# "shout": new_shout.id,
|
# chat = create_chat(None, info, new_shout.title, members=authors)
|
||||||
# "authors": [auth.user_id, ],
|
# # create a cooperative chatroom
|
||||||
# "invites": authors
|
# await MessagesStorage.register_chat(chat)
|
||||||
# })
|
# # now we should create a collab
|
||||||
# session.add(new_collab)
|
# new_collab = Collab.create({
|
||||||
|
# "shout": new_shout.id,
|
||||||
|
# "authors": [auth.user_id, ],
|
||||||
|
# "invites": authors
|
||||||
|
# })
|
||||||
|
# session.add(new_collab)
|
||||||
|
|
||||||
# NOTE: shout made by one first author
|
# NOTE: shout made by one first author
|
||||||
sa = ShoutAuthor.create(shout=new_shout.id, user=auth.user_id)
|
sa = ShoutAuthor.create(shout=new_shout.id, user=auth.user_id)
|
||||||
session.add(sa)
|
session.add(sa)
|
||||||
|
|
||||||
if "mainTopic" in inp:
|
# if "mainTopic" in inp:
|
||||||
new_shout.topics.append(inp["mainTopic"])
|
# new_shout.topics.append(inp["mainTopic"])
|
||||||
|
|
||||||
session.add(new_shout)
|
session.add(new_shout)
|
||||||
|
|
||||||
reactions_follow(auth.user_id, new_shout.id, True)
|
reactions_follow(auth.user_id, new_shout.id, True)
|
||||||
|
|
||||||
for slug in new_shout.topics:
|
# for slug in new_shout.topics:
|
||||||
topic = session.query(Topic).where(Topic.slug == slug).one()
|
# topic = session.query(Topic).where(Topic.slug == slug).one()
|
||||||
|
#
|
||||||
st = ShoutTopic.create(shout=new_shout.id, topic=topic.id)
|
# st = ShoutTopic.create(shout=new_shout.id, topic=topic.id)
|
||||||
session.add(st)
|
# session.add(st)
|
||||||
tf = session.query(TopicFollower).where(
|
#
|
||||||
and_(TopicFollower.follower == auth.user_id, TopicFollower.topic == topic.id)
|
# tf = session.query(TopicFollower).where(
|
||||||
)
|
# and_(TopicFollower.follower == auth.user_id, TopicFollower.topic == topic.id)
|
||||||
|
# )
|
||||||
if not tf:
|
#
|
||||||
tf = TopicFollower.create(follower=auth.user_id, topic=topic.id, auto=True)
|
# if not tf:
|
||||||
session.add(tf)
|
# tf = TopicFollower.create(follower=auth.user_id, topic=topic.id, auto=True)
|
||||||
|
# session.add(tf)
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
|
@ -142,10 +142,9 @@ def check_to_hide(session, user_id, reaction):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def set_published(session, shout_id, publisher):
|
def set_published(session, shout_id):
|
||||||
s = session.query(Shout).where(Shout.id == shout_id).first()
|
s = session.query(Shout).where(Shout.id == shout_id).first()
|
||||||
s.publishedAt = datetime.now(tz=timezone.utc)
|
s.publishedAt = datetime.now(tz=timezone.utc)
|
||||||
s.publishedBy = publisher
|
|
||||||
s.visibility = text('public')
|
s.visibility = text('public')
|
||||||
session.add(s)
|
session.add(s)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
@ -153,9 +152,7 @@ def set_published(session, shout_id, publisher):
|
||||||
|
|
||||||
def set_hidden(session, shout_id):
|
def set_hidden(session, shout_id):
|
||||||
s = session.query(Shout).where(Shout.id == shout_id).first()
|
s = session.query(Shout).where(Shout.id == shout_id).first()
|
||||||
s.visibility = text('authors')
|
s.visibility = text('community')
|
||||||
s.publishedAt = None # TODO: discuss
|
|
||||||
s.publishedBy = None # TODO: store changes history in git
|
|
||||||
session.add(s)
|
session.add(s)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
@ -227,7 +224,7 @@ async def create_reaction(_, info, reaction):
|
||||||
if check_to_hide(session, auth.user_id, r):
|
if check_to_hide(session, auth.user_id, r):
|
||||||
set_hidden(session, r.shout)
|
set_hidden(session, r.shout)
|
||||||
elif check_to_publish(session, auth.user_id, r):
|
elif check_to_publish(session, auth.user_id, r):
|
||||||
set_published(session, r.shout, r.createdBy)
|
set_published(session, r.shout)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reactions_follow(auth.user_id, reaction["shout"], True)
|
reactions_follow(auth.user_id, reaction["shout"], True)
|
||||||
|
|
|
@ -455,7 +455,6 @@ type Shout {
|
||||||
updatedBy: User
|
updatedBy: User
|
||||||
deletedAt: DateTime
|
deletedAt: DateTime
|
||||||
deletedBy: User
|
deletedBy: User
|
||||||
publishedBy: User
|
|
||||||
publishedAt: DateTime
|
publishedAt: DateTime
|
||||||
media: String # json [ { title pic url body }, .. ]
|
media: String # json [ { title pic url body }, .. ]
|
||||||
stat: Stat
|
stat: Stat
|
||||||
|
@ -501,7 +500,8 @@ type TopicStat {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Topic {
|
type Topic {
|
||||||
slug: String! # ID
|
id: Int!
|
||||||
|
slug: String!
|
||||||
title: String
|
title: String
|
||||||
body: String
|
body: String
|
||||||
pic: String
|
pic: String
|
||||||
|
|
Loading…
Reference in New Issue
Block a user