Merge branch 'main' of https://github.com/Discours/discours-backend into main
This commit is contained in:
commit
ccb7e61170
|
@ -83,6 +83,7 @@ def topics(export_topics, topics_by_slug, topics_by_oid, cats_data, tags_data):
|
||||||
if len(sys.argv) > 2: limit = int(sys.argv[2])
|
if len(sys.argv) > 2: limit = int(sys.argv[2])
|
||||||
print('migrating %d topics...' % limit)
|
print('migrating %d topics...' % limit)
|
||||||
counter = 0
|
counter = 0
|
||||||
|
topics_by_title = {}
|
||||||
for tag in tags_data:
|
for tag in tags_data:
|
||||||
old_id = tag["createdBy"]
|
old_id = tag["createdBy"]
|
||||||
tag["createdBy"] = user_id_map.get(old_id, 0)
|
tag["createdBy"] = user_id_map.get(old_id, 0)
|
||||||
|
|
|
@ -417,15 +417,17 @@ class HTML2Text(HTMLParser.HTMLParser):
|
||||||
self.o('`') # NOTE: same as <code>
|
self.o('`') # NOTE: same as <code>
|
||||||
self.span_hightlight = True
|
self.span_hightlight = True
|
||||||
elif attrs['class'] == 'lead':
|
elif attrs['class'] == 'lead':
|
||||||
self.o('==') # NOTE: but CriticMarkup uses {== ==}
|
if self.span_lead == False:
|
||||||
self.span_lead = True
|
self.o('==\n') # NOTE: but CriticMarkup uses {== ==}
|
||||||
|
self.span_lead = True
|
||||||
else:
|
else:
|
||||||
if self.span_hightlight:
|
if self.span_hightlight:
|
||||||
self.o('`')
|
self.o('`')
|
||||||
self.span_hightlight = False
|
self.span_hightlight = False
|
||||||
elif self.span_lead:
|
elif self.span_lead:
|
||||||
self.o('==')
|
if self.span_lead == True:
|
||||||
self.span_lead = False
|
self.o('\n==')
|
||||||
|
self.span_lead = False
|
||||||
|
|
||||||
if tag in ['p', 'div']:
|
if tag in ['p', 'div']:
|
||||||
if self.google_doc:
|
if self.google_doc:
|
||||||
|
|
0
migration/content/.gitkeep
Normal file
0
migration/content/.gitkeep
Normal file
0
migration/content/article/.gitkeep
Normal file
0
migration/content/article/.gitkeep
Normal file
0
migration/content/image/.gitkeep
Normal file
0
migration/content/image/.gitkeep
Normal file
0
migration/content/music/.gitkeep
Normal file
0
migration/content/music/.gitkeep
Normal file
0
migration/content/prose/.gitkeep
Normal file
0
migration/content/prose/.gitkeep
Normal file
0
migration/content/video/.gitkeep
Normal file
0
migration/content/video/.gitkeep
Normal file
|
@ -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
|
ShoutRatingStorage, ShoutViewStorage, ShoutCommentsSubscription
|
||||||
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,6 +11,14 @@ 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"
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,61 @@
|
||||||
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
|
||||||
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)
|
||||||
|
|
||||||
|
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):
|
||||||
|
@ -18,6 +69,9 @@ 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")
|
||||||
|
@ -38,6 +92,9 @@ 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")
|
||||||
|
@ -56,6 +113,9 @@ 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")
|
||||||
|
@ -81,4 +141,7 @@ 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 {}
|
||||||
|
|
|
@ -35,6 +35,8 @@ async def create_shout(_, info, input):
|
||||||
user.email,
|
user.email,
|
||||||
"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
|
||||||
|
@ -104,4 +106,4 @@ async def delete_shout(_, info, slug):
|
||||||
shout.deletedAt = datetime.now()
|
shout.deletedAt = datetime.now()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
return {}
|
return {}
|
|
@ -1,12 +1,13 @@
|
||||||
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
|
Comment, CommentRating, Topic, ShoutCommentsSubscription
|
||||||
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
|
||||||
|
|
||||||
|
@ -314,16 +315,18 @@ async def shouts_by_communities(_, info, slugs, page, size):
|
||||||
|
|
||||||
@mutation.field("subscribe")
|
@mutation.field("subscribe")
|
||||||
@login_required
|
@login_required
|
||||||
async def subscribe(_, info, what, slug):
|
async def subscribe(_, info, subscription, slug):
|
||||||
user = info.context["request"].user
|
user = info.context["request"].user
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if what == "AUTHOR":
|
if subscription == "AUTHOR":
|
||||||
author_subscribe(user, slug)
|
author_subscribe(user, slug)
|
||||||
elif what == "TOPIC":
|
elif subscription == "TOPIC":
|
||||||
topic_subscribe(user, slug)
|
topic_subscribe(user, slug)
|
||||||
elif what == "COMMUNITY":
|
elif subscription == "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}
|
||||||
|
|
||||||
|
@ -331,16 +334,18 @@ async def subscribe(_, info, what, slug):
|
||||||
|
|
||||||
@mutation.field("unsubscribe")
|
@mutation.field("unsubscribe")
|
||||||
@login_required
|
@login_required
|
||||||
async def unsubscribe(_, info, what, slug):
|
async def unsubscribe(_, info, subscription, slug):
|
||||||
user = info.context["request"].user
|
user = info.context["request"].user
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if what == "AUTHOR":
|
if subscription == "AUTHOR":
|
||||||
author_unsubscribe(user, slug)
|
author_unsubscribe(user, slug)
|
||||||
elif what == "TOPIC":
|
elif subscription == "TOPIC":
|
||||||
topic_unsubscribe(user, slug)
|
topic_unsubscribe(user, slug)
|
||||||
elif what == "COMMUNITY":
|
elif subscription == "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}
|
||||||
|
|
||||||
|
@ -369,4 +374,4 @@ async def rate_shout(_, info, slug, value):
|
||||||
|
|
||||||
await ShoutRatingStorage.update_rating(rating)
|
await ShoutRatingStorage.update_rating(rating)
|
||||||
|
|
||||||
return {"error" : ""}
|
return {"error" : ""}
|
Loading…
Reference in New Issue
Block a user