Merge branch 'create-shout-fix' into 'main'

create shout fix

See merge request discoursio/discoursio-api!7
This commit is contained in:
Igor 2023-01-24 09:56:41 +00:00
commit a5947f0962
2 changed files with 23 additions and 24 deletions

View File

@ -641,7 +641,7 @@
"sasha-skochilenko": "sasha-skochilenko", "sasha-skochilenko": "sasha-skochilenko",
"satira": "satiric", "satira": "satiric",
"saund-art": "sound-art", "saund-art": "sound-art",
"schaste": "hapiness", "schaste": "happiness",
"school": "school", "school": "school",
"science": "science", "science": "science",
"sculpture": "sculpture", "sculpture": "sculpture",

View File

@ -22,45 +22,47 @@ from orm.draft import DraftCollab
async def create_shout(_, info, inp): async def create_shout(_, info, inp):
auth: AuthCredentials = info.context["request"].auth auth: AuthCredentials = info.context["request"].auth
topic_slugs = inp.get("topic_slugs", [])
if topic_slugs:
del inp["topic_slugs"]
body = inp.get("body") body = inp.get("body")
with local_session() as session: with local_session() as session:
if body: if body:
# now we should create a draft shout (can be viewed only by authors) # now we should create a draft shout (can be viewed only by authors)
authors = inp.get("authors", []) authors = inp.get("authors", [])
new_shout = Shout.create({ new_shout = Shout.create(**{
"title": inp.get("title", body[:12] + '...'), "title": inp.get("title", body[:12] + '...'),
"body": body, "body": body,
"authors": authors, "authors": authors,
"slug": inp.get("slug"),
"topics": inp.get("topics", []), "topics": inp.get("topics", []),
"mainTopic": inp.get("topics", []).pop(), "mainTopic": inp.get("topics", []).pop(),
"visibility": "authors" "visibility": "authors"
}) })
authors.remove(auth.user_id) if auth.user_id in authors:
if authors: authors.remove(auth.user_id)
chat = create_chat(None, info, new_shout.title, members=authors) # Chat room code, uncomment it
# create a cooperative chatroom # if authors:
await MessagesStorage.register_chat(chat) # chat = create_chat(None, info, new_shout.title, members=authors)
# now we should create a collab # # create a cooperative chatroom
new_collab = Collab.create({ # await MessagesStorage.register_chat(chat)
"shout": new_shout.id, # # now we should create a collab
"authors": [auth.user_id, ], # new_collab = Collab.create({
"invites": authors # "shout": new_shout.id,
}) # "authors": [auth.user_id, ],
session.add(new_collab) # "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)
reactions_follow(auth.user_id, new_shout.slug, True)
if "mainTopic" in inp: if "mainTopic" in inp:
topic_slugs.append(inp["mainTopic"]) new_shout.topics.append(inp["mainTopic"])
for slug in topic_slugs: 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() 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)
@ -73,9 +75,6 @@ async def create_shout(_, info, inp):
tf = TopicFollower.create(follower=auth.user_id, topic=topic.id, auto=True) tf = TopicFollower.create(follower=auth.user_id, topic=topic.id, auto=True)
session.add(tf) session.add(tf)
new_shout.topic_slugs = topic_slugs
session.add(new_shout)
session.commit() session.commit()
# TODO # TODO