remove CommentSubscription; fix subscribe/unsibscribe method
This commit is contained in:
parent
f92be99bce
commit
f93b17cead
|
@ -4,7 +4,7 @@ from orm.user import User, UserRating, UserRole, UserStorage
|
|||
from orm.topic import Topic, TopicSubscription, TopicStorage
|
||||
from orm.notification import Notification
|
||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay,\
|
||||
ShoutRatingStorage, ShoutViewStorage, ShoutCommentsSubscription
|
||||
ShoutRatingStorage, ShoutViewStorage
|
||||
from orm.base import Base, engine, local_session
|
||||
from orm.comment import Comment, CommentRating #, CommentRatingStorage
|
||||
from orm.proposal import Proposal, ProposalRating #, ProposalRatingStorage
|
||||
|
|
|
@ -11,14 +11,6 @@ from functools import reduce
|
|||
|
||||
import asyncio
|
||||
|
||||
class ShoutCommentsSubscription(Base):
|
||||
__tablename__ = "shout_comments_subscription"
|
||||
|
||||
id = None
|
||||
subscriber = Column(ForeignKey('user.slug'), primary_key = True)
|
||||
shout = Column(ForeignKey('shout.slug'), primary_key = True)
|
||||
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||
|
||||
class ShoutAuthor(Base):
|
||||
__tablename__ = "shout_author"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -36,8 +36,6 @@ async def create_shout(_, info, input):
|
|||
"new shout %s" % (new_shout.slug)
|
||||
)
|
||||
|
||||
await ShoutCommentsStorage.send_shout(new_shout)
|
||||
|
||||
return {
|
||||
"shout" : new_shout
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user