remove CommentSubscription; fix subscribe/unsibscribe method

This commit is contained in:
knst-kotov
2022-06-23 11:39:00 +03:00
parent f92be99bce
commit f93b17cead
6 changed files with 14 additions and 45 deletions

View File

@@ -219,7 +219,7 @@ async def invite_author(_, author_slug, shout):
@mutation.field("removeAuthor")
@login_required
async def invite_author(_, author_slug, shout):
async def remove_author(_, author_slug, shout):
auth = info.context["request"].auth
user_id = auth.user_id
@@ -241,4 +241,4 @@ async def invite_author(_, author_slug, shout):
# TODO: email notify
return {}
return {}

View File

@@ -1,6 +1,5 @@
from orm import Comment, CommentRating
from orm.base import local_session
from orm.shout import ShoutCommentsSubscription
from resolvers.base import mutation, query, subscription
from auth.authenticate import login_required
import asyncio
@@ -41,21 +40,6 @@ class ShoutCommentsStorage:
if comment_result.comment.shout == subs.shout_slug:
subs.queue.put_nowait(comment_result)
def comments_subscribe(user, slug):
ShoutCommentsSubscription.create(
subscriber = user.slug,
shout = slug)
def comments_unsubscribe(user, slug):
with local_session() as session:
sub = session.query(ShoutCommentsSubscription).\
filter(and_(ShoutCommentsSubscription.subscriber == user.slug, ShoutCommentsSubscription.shout == slug)).\
first()
if not sub:
raise Exception("subscription not exist")
session.delete(sub)
session.commit()
@mutation.field("createComment")
@login_required
async def create_comment(_, info, body, shout, replyTo = None):

View File

@@ -35,8 +35,6 @@ async def create_shout(_, info, input):
user.email,
"new shout %s" % (new_shout.slug)
)
await ShoutCommentsStorage.send_shout(new_shout)
return {
"shout" : new_shout
@@ -106,4 +104,4 @@ async def delete_shout(_, info, slug):
shout.deletedAt = datetime.now()
session.commit()
return {}
return {}

View File

@@ -1,13 +1,12 @@
from orm import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay, \
User, Community, Resource, ShoutRatingStorage, ShoutViewStorage, \
Comment, CommentRating, Topic, ShoutCommentsSubscription
Comment, CommentRating, Topic
from orm.community import CommunitySubscription
from orm.base import local_session
from orm.user import UserStorage, AuthorSubscription
from orm.topic import TopicSubscription
from resolvers.base import mutation, query
from resolvers.comments import comments_subscribe, comments_unsubscribe
from auth.authenticate import login_required
from settings import SHOUTS_REPO
@@ -315,18 +314,16 @@ async def shouts_by_communities(_, info, slugs, page, size):
@mutation.field("subscribe")
@login_required
async def subscribe(_, info, subscription, slug):
async def subscribe(_, info, what, slug):
user = info.context["request"].user
try:
if subscription == "AUTHOR":
if what == "AUTHOR":
author_subscribe(user, slug)
elif subscription == "TOPIC":
elif what == "TOPIC":
topic_subscribe(user, slug)
elif subscription == "COMMUNITY":
elif what == "COMMUNITY":
community_subscribe(user, slug)
elif comments_subscription == "COMMENTS":
comments_subscribe(user, slug)
except Exception as e:
return {"error" : e}
@@ -334,18 +331,16 @@ async def subscribe(_, info, subscription, slug):
@mutation.field("unsubscribe")
@login_required
async def unsubscribe(_, info, subscription, slug):
async def unsubscribe(_, info, what, slug):
user = info.context["request"].user
try:
if subscription == "AUTHOR":
if what == "AUTHOR":
author_unsubscribe(user, slug)
elif subscription == "TOPIC":
elif what == "TOPIC":
topic_unsubscribe(user, slug)
elif subscription == "COMMUNITY":
elif what == "COMMUNITY":
community_unsubscribe(user, slug)
elif subscription == "COMMENTS":
comments_unsubscribe(user, slug)
except Exception as e:
return {"error" : e}
@@ -374,4 +369,4 @@ async def rate_shout(_, info, slug, value):
await ShoutRatingStorage.update_rating(rating)
return {"error" : ""}
return {"error" : ""}