fix scheme and reactions subscriptions

This commit is contained in:
tonyrewin 2022-10-23 15:48:08 +03:00
parent 4c3439d241
commit 764899d580
4 changed files with 28 additions and 8 deletions

View File

@ -72,11 +72,11 @@ async def confirm_email_handler(request):
token = request.path_params["token"] # one time
request.session["token"] = token
res = await confirm_email(None, {}, token)
# print('[resolvers.auth] confirm_email response: %r' % res)
print('[resolvers.auth] confirm_email request: %r' % request)
if "error" in res:
raise BaseHttpException(res['error'])
else:
response = RedirectResponse(url="https://new.discours.io/confirm")
response = RedirectResponse(url="https://new.discours.io")
response.set_cookie("token", res["token"]) # session token
return response

View File

@ -23,7 +23,7 @@ async def user_subscriptions(slug: str):
"unread": await get_unread_counter(slug), # unread inbox messages counter
"topics": [t.slug for t in await followed_topics(slug)], # followed topics slugs
"authors": [a.slug for a in await followed_authors(slug)], # followed authors slugs
"reactions": len(await ReactedStorage.get_shout(slug)),
"reactions": await ReactedStorage.get_shouts_by_author(slug),
"communities": [c.slug for c in followed_communities(slug)], # communities
}

View File

@ -156,7 +156,7 @@ type Mutation {
refreshSession: AuthResult!
registerUser(email: String!, password: String, name: String): AuthResult!
sendLink(email: String!, lang: String): Result!
confirmEmail(code: String!): AuthResult!
confirmEmail(token: String!): AuthResult!
# shout
createShout(input: ShoutInput!): Result!

View File

@ -24,7 +24,7 @@ def kind_to_rate(kind) -> int:
class ReactedStorage:
reacted = {"shouts": {}, "topics": {}, "reactions": {}}
reacted = {"shouts": {}, "topics": {}, "reactions": {}, "authors": {}}
rating = {"shouts": {}, "topics": {}, "reactions": {}}
reactions = []
to_flush = []
@ -38,6 +38,23 @@ class ReactedStorage:
async with self.lock:
return self.reacted["shouts"].get(shout_slug, [])
@staticmethod
async def get_author(user_slug):
self = ReactedStorage
async with self.lock:
return self.reacted["authors"].get(user_slug, [])
@staticmethod
async def get_shouts_by_author(user_slug):
self = ReactedStorage
async with self.lock:
author_reactions = self.reacted["authors"].get(user_slug, [])
shouts = []
for r in author_reactions:
if r.shout not in shouts:
shouts.append(r.shout)
return shouts
@staticmethod
async def get_topic(topic_slug):
self = ReactedStorage
@ -111,10 +128,13 @@ class ReactedStorage:
async def recount(reactions):
self = ReactedStorage
for r in reactions:
# renew shout counters
# renew reactions by shout
self.reacted["shouts"][r.shout] = self.reacted["shouts"].get(r.shout, [])
self.reacted["shouts"][r.shout].append(r)
# renew topics counters
# renew reactions by author
self.reacted["authors"][r.createdBy] = self.reacted["authors"].get(r.createdBy, [])
self.reacted["authors"][r.createdBy].append(r)
# renew reactions by topic
shout_topics = await TopicStorage.get_topics_by_slugs([r.shout, ])
for t in shout_topics:
self.reacted["topics"][t] = self.reacted["topics"].get(t, [])
@ -122,7 +142,7 @@ class ReactedStorage:
self.rating["topics"][t] = \
self.rating["topics"].get(t, 0) + kind_to_rate(r.kind)
if r.replyTo:
# renew reaction counters
# renew reactions replies
self.reacted["reactions"][r.replyTo] = \
self.reacted["reactions"].get(r.replyTo, [])
self.reacted["reactions"][r.replyTo].append(r)