shout create

This commit is contained in:
bniwredyc 2023-03-27 16:46:14 +02:00
parent 31b4f8106c
commit 2e04d2cac5
4 changed files with 51 additions and 50 deletions

View File

@ -15,7 +15,6 @@ class ShoutTopic(Base):
id = None # type: ignore
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
topic = Column(ForeignKey("topic.id"), primary_key=True, index=True)
main = Column(Boolean, default=False)
class ShoutReactionsFollower(Base):

View File

@ -22,22 +22,26 @@ from services.zine.gittask import GitTask
async def create_shout(_, info, inp):
auth: AuthCredentials = info.context["request"].auth
body = inp.get("body")
with local_session() as session:
if body:
# now we should create a draft shout (can be viewed only by authors)
authors = inp.get("authors", [])
topics = session.query(Topic).filter(Topic.slug.in_(inp.get('topics', []))).all()
new_shout = Shout.create(**{
"title": inp.get("title", body[:12] + '...'),
"body": body,
"authors": authors,
"title": inp.get("title"),
"subtitle": inp.get('subtitle'),
"body": inp.get("body"),
"authors": inp.get("authors", []),
"slug": inp.get("slug"),
"topics": inp.get("topics", []),
"mainTopic": inp.get("topics", []).pop(),
"visibility": "authors"
"mainTopic": inp.get("mainTopic"),
"visibility": "community",
# "createdBy": auth.user_id
})
if auth.user_id in authors:
authors.remove(auth.user_id)
for topic in topics:
t = ShoutTopic.create(topic=topic.id, shout=new_shout.id)
session.add(t)
# if auth.user_id in authors:
# authors.remove(auth.user_id)
# Chat room code, uncomment it
# if authors:
# chat = create_chat(None, info, new_shout.title, members=authors)
@ -55,25 +59,26 @@ async def create_shout(_, info, inp):
sa = ShoutAuthor.create(shout=new_shout.id, user=auth.user_id)
session.add(sa)
if "mainTopic" in inp:
new_shout.topics.append(inp["mainTopic"])
# if "mainTopic" in inp:
# new_shout.topics.append(inp["mainTopic"])
session.add(new_shout)
reactions_follow(auth.user_id, new_shout.id, True)
for slug in new_shout.topics:
topic = session.query(Topic).where(Topic.slug == slug).one()
st = ShoutTopic.create(shout=new_shout.id, topic=topic.id)
session.add(st)
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)
session.add(tf)
# for slug in new_shout.topics:
# topic = session.query(Topic).where(Topic.slug == slug).one()
#
# st = ShoutTopic.create(shout=new_shout.id, topic=topic.id)
# session.add(st)
#
# 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)
# session.add(tf)
session.commit()

View File

@ -142,10 +142,9 @@ def check_to_hide(session, user_id, reaction):
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.publishedAt = datetime.now(tz=timezone.utc)
s.publishedBy = publisher
s.visibility = text('public')
session.add(s)
session.commit()
@ -153,9 +152,7 @@ def set_published(session, shout_id, publisher):
def set_hidden(session, shout_id):
s = session.query(Shout).where(Shout.id == shout_id).first()
s.visibility = text('authors')
s.publishedAt = None # TODO: discuss
s.publishedBy = None # TODO: store changes history in git
s.visibility = text('community')
session.add(s)
session.commit()
@ -227,7 +224,7 @@ async def create_reaction(_, info, reaction):
if check_to_hide(session, auth.user_id, r):
set_hidden(session, r.shout)
elif check_to_publish(session, auth.user_id, r):
set_published(session, r.shout, r.createdBy)
set_published(session, r.shout)
try:
reactions_follow(auth.user_id, reaction["shout"], True)

View File

@ -455,7 +455,6 @@ type Shout {
updatedBy: User
deletedAt: DateTime
deletedBy: User
publishedBy: User
publishedAt: DateTime
media: String # json [ { title pic url body }, .. ]
stat: Stat
@ -501,7 +500,8 @@ type TopicStat {
}
type Topic {
slug: String! # ID
id: Int!
slug: String!
title: String
body: String
pic: String