remove CommentsStorage
This commit is contained in:
parent
f36db24bad
commit
ddacbbb0d5
|
@ -5,41 +5,6 @@ from auth.authenticate import login_required
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class CommentResult:
|
|
||||||
def __init__(self, status, comment):
|
|
||||||
self.status = status
|
|
||||||
self.comment = comment
|
|
||||||
|
|
||||||
class ShoutCommentsSubscription:
|
|
||||||
queue = asyncio.Queue()
|
|
||||||
|
|
||||||
def __init__(self, shout_slug):
|
|
||||||
self.shout_slug = shout_slug
|
|
||||||
|
|
||||||
class ShoutCommentsStorage:
|
|
||||||
lock = asyncio.Lock()
|
|
||||||
subscriptions = []
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
async def register_subscription(subs):
|
|
||||||
self = ShoutCommentsStorage
|
|
||||||
async with self.lock:
|
|
||||||
self.subscriptions.append(subs)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
async def del_subscription(subs):
|
|
||||||
self = ShoutCommentsStorage
|
|
||||||
async with self.lock:
|
|
||||||
self.subscriptions.remove(subs)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
async def put(comment_result):
|
|
||||||
self = ShoutCommentsStorage
|
|
||||||
async with self.lock:
|
|
||||||
for subs in self.subscriptions:
|
|
||||||
if comment_result.comment.shout == subs.shout_slug:
|
|
||||||
subs.queue.put_nowait(comment_result)
|
|
||||||
|
|
||||||
@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):
|
||||||
|
@ -53,9 +18,6 @@ async def create_comment(_, info, body, shout, replyTo = None):
|
||||||
replyTo = replyTo
|
replyTo = replyTo
|
||||||
)
|
)
|
||||||
|
|
||||||
result = CommentResult("NEW", comment)
|
|
||||||
await ShoutCommentsStorage.put(result)
|
|
||||||
|
|
||||||
return {"comment": comment}
|
return {"comment": comment}
|
||||||
|
|
||||||
@mutation.field("updateComment")
|
@mutation.field("updateComment")
|
||||||
|
@ -76,9 +38,6 @@ async def update_comment(_, info, id, body):
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
result = CommentResult("UPDATED", comment)
|
|
||||||
await ShoutCommentsStorage.put(result)
|
|
||||||
|
|
||||||
return {"comment": comment}
|
return {"comment": comment}
|
||||||
|
|
||||||
@mutation.field("deleteComment")
|
@mutation.field("deleteComment")
|
||||||
|
@ -97,9 +56,6 @@ async def delete_comment(_, info, id):
|
||||||
comment.deletedAt = datetime.now()
|
comment.deletedAt = datetime.now()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
result = CommentResult("DELETED", comment)
|
|
||||||
await ShoutCommentsStorage.put(result)
|
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@mutation.field("rateComment")
|
@mutation.field("rateComment")
|
||||||
|
@ -125,7 +81,4 @@ async def rate_comment(_, info, id, value):
|
||||||
createdBy = user_id,
|
createdBy = user_id,
|
||||||
value = value)
|
value = value)
|
||||||
|
|
||||||
result = CommentResult("UPDATED_RATING", comment)
|
|
||||||
await ShoutCommentsStorage.put(result)
|
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user