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.topic import Topic, TopicSubscription, TopicStorage
|
||||||
from orm.notification import Notification
|
from orm.notification import Notification
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay,\
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay,\
|
||||||
ShoutRatingStorage, ShoutViewStorage, ShoutCommentsSubscription
|
ShoutRatingStorage, ShoutViewStorage
|
||||||
from orm.base import Base, engine, local_session
|
from orm.base import Base, engine, local_session
|
||||||
from orm.comment import Comment, CommentRating #, CommentRatingStorage
|
from orm.comment import Comment, CommentRating #, CommentRatingStorage
|
||||||
from orm.proposal import Proposal, ProposalRating #, ProposalRatingStorage
|
from orm.proposal import Proposal, ProposalRating #, ProposalRatingStorage
|
||||||
|
|
|
@ -11,14 +11,6 @@ from functools import reduce
|
||||||
|
|
||||||
import asyncio
|
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):
|
class ShoutAuthor(Base):
|
||||||
__tablename__ = "shout_author"
|
__tablename__ = "shout_author"
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ async def invite_author(_, author_slug, shout):
|
||||||
|
|
||||||
@mutation.field("removeAuthor")
|
@mutation.field("removeAuthor")
|
||||||
@login_required
|
@login_required
|
||||||
async def invite_author(_, author_slug, shout):
|
async def remove_author(_, author_slug, shout):
|
||||||
auth = info.context["request"].auth
|
auth = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from orm import Comment, CommentRating
|
from orm import Comment, CommentRating
|
||||||
from orm.base import local_session
|
from orm.base import local_session
|
||||||
from orm.shout import ShoutCommentsSubscription
|
|
||||||
from resolvers.base import mutation, query, subscription
|
from resolvers.base import mutation, query, subscription
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -41,21 +40,6 @@ class ShoutCommentsStorage:
|
||||||
if comment_result.comment.shout == subs.shout_slug:
|
if comment_result.comment.shout == subs.shout_slug:
|
||||||
subs.queue.put_nowait(comment_result)
|
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")
|
@mutation.field("createComment")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_comment(_, info, body, shout, replyTo = None):
|
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)
|
"new shout %s" % (new_shout.slug)
|
||||||
)
|
)
|
||||||
|
|
||||||
await ShoutCommentsStorage.send_shout(new_shout)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"shout" : new_shout
|
"shout" : new_shout
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
from orm import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay, \
|
from orm import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay, \
|
||||||
User, Community, Resource, ShoutRatingStorage, ShoutViewStorage, \
|
User, Community, Resource, ShoutRatingStorage, ShoutViewStorage, \
|
||||||
Comment, CommentRating, Topic, ShoutCommentsSubscription
|
Comment, CommentRating, Topic
|
||||||
from orm.community import CommunitySubscription
|
from orm.community import CommunitySubscription
|
||||||
from orm.base import local_session
|
from orm.base import local_session
|
||||||
from orm.user import UserStorage, AuthorSubscription
|
from orm.user import UserStorage, AuthorSubscription
|
||||||
from orm.topic import TopicSubscription
|
from orm.topic import TopicSubscription
|
||||||
|
|
||||||
from resolvers.base import mutation, query
|
from resolvers.base import mutation, query
|
||||||
from resolvers.comments import comments_subscribe, comments_unsubscribe
|
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
from settings import SHOUTS_REPO
|
from settings import SHOUTS_REPO
|
||||||
|
|
||||||
|
@ -315,18 +314,16 @@ async def shouts_by_communities(_, info, slugs, page, size):
|
||||||
|
|
||||||
@mutation.field("subscribe")
|
@mutation.field("subscribe")
|
||||||
@login_required
|
@login_required
|
||||||
async def subscribe(_, info, subscription, slug):
|
async def subscribe(_, info, what, slug):
|
||||||
user = info.context["request"].user
|
user = info.context["request"].user
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if subscription == "AUTHOR":
|
if what == "AUTHOR":
|
||||||
author_subscribe(user, slug)
|
author_subscribe(user, slug)
|
||||||
elif subscription == "TOPIC":
|
elif what == "TOPIC":
|
||||||
topic_subscribe(user, slug)
|
topic_subscribe(user, slug)
|
||||||
elif subscription == "COMMUNITY":
|
elif what == "COMMUNITY":
|
||||||
community_subscribe(user, slug)
|
community_subscribe(user, slug)
|
||||||
elif comments_subscription == "COMMENTS":
|
|
||||||
comments_subscribe(user, slug)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"error" : e}
|
return {"error" : e}
|
||||||
|
|
||||||
|
@ -334,18 +331,16 @@ async def subscribe(_, info, subscription, slug):
|
||||||
|
|
||||||
@mutation.field("unsubscribe")
|
@mutation.field("unsubscribe")
|
||||||
@login_required
|
@login_required
|
||||||
async def unsubscribe(_, info, subscription, slug):
|
async def unsubscribe(_, info, what, slug):
|
||||||
user = info.context["request"].user
|
user = info.context["request"].user
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if subscription == "AUTHOR":
|
if what == "AUTHOR":
|
||||||
author_unsubscribe(user, slug)
|
author_unsubscribe(user, slug)
|
||||||
elif subscription == "TOPIC":
|
elif what == "TOPIC":
|
||||||
topic_unsubscribe(user, slug)
|
topic_unsubscribe(user, slug)
|
||||||
elif subscription == "COMMUNITY":
|
elif what == "COMMUNITY":
|
||||||
community_unsubscribe(user, slug)
|
community_unsubscribe(user, slug)
|
||||||
elif subscription == "COMMENTS":
|
|
||||||
comments_unsubscribe(user, slug)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"error" : e}
|
return {"error" : e}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user