fix scheme and reactions subscriptions
This commit is contained in:
parent
4c3439d241
commit
764899d580
|
@ -72,11 +72,11 @@ async def confirm_email_handler(request):
|
||||||
token = request.path_params["token"] # one time
|
token = request.path_params["token"] # one time
|
||||||
request.session["token"] = token
|
request.session["token"] = token
|
||||||
res = await confirm_email(None, {}, 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:
|
if "error" in res:
|
||||||
raise BaseHttpException(res['error'])
|
raise BaseHttpException(res['error'])
|
||||||
else:
|
else:
|
||||||
response = RedirectResponse(url="https://new.discours.io/confirm")
|
response = RedirectResponse(url="https://new.discours.io")
|
||||||
response.set_cookie("token", res["token"]) # session token
|
response.set_cookie("token", res["token"]) # session token
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ async def user_subscriptions(slug: str):
|
||||||
"unread": await get_unread_counter(slug), # unread inbox messages counter
|
"unread": await get_unread_counter(slug), # unread inbox messages counter
|
||||||
"topics": [t.slug for t in await followed_topics(slug)], # followed topics slugs
|
"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
|
"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
|
"communities": [c.slug for c in followed_communities(slug)], # communities
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ type Mutation {
|
||||||
refreshSession: AuthResult!
|
refreshSession: AuthResult!
|
||||||
registerUser(email: String!, password: String, name: String): AuthResult!
|
registerUser(email: String!, password: String, name: String): AuthResult!
|
||||||
sendLink(email: String!, lang: String): Result!
|
sendLink(email: String!, lang: String): Result!
|
||||||
confirmEmail(code: String!): AuthResult!
|
confirmEmail(token: String!): AuthResult!
|
||||||
|
|
||||||
# shout
|
# shout
|
||||||
createShout(input: ShoutInput!): Result!
|
createShout(input: ShoutInput!): Result!
|
||||||
|
|
|
@ -24,7 +24,7 @@ def kind_to_rate(kind) -> int:
|
||||||
|
|
||||||
|
|
||||||
class ReactedStorage:
|
class ReactedStorage:
|
||||||
reacted = {"shouts": {}, "topics": {}, "reactions": {}}
|
reacted = {"shouts": {}, "topics": {}, "reactions": {}, "authors": {}}
|
||||||
rating = {"shouts": {}, "topics": {}, "reactions": {}}
|
rating = {"shouts": {}, "topics": {}, "reactions": {}}
|
||||||
reactions = []
|
reactions = []
|
||||||
to_flush = []
|
to_flush = []
|
||||||
|
@ -38,6 +38,23 @@ class ReactedStorage:
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
return self.reacted["shouts"].get(shout_slug, [])
|
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
|
@staticmethod
|
||||||
async def get_topic(topic_slug):
|
async def get_topic(topic_slug):
|
||||||
self = ReactedStorage
|
self = ReactedStorage
|
||||||
|
@ -111,10 +128,13 @@ class ReactedStorage:
|
||||||
async def recount(reactions):
|
async def recount(reactions):
|
||||||
self = ReactedStorage
|
self = ReactedStorage
|
||||||
for r in reactions:
|
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] = self.reacted["shouts"].get(r.shout, [])
|
||||||
self.reacted["shouts"][r.shout].append(r)
|
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, ])
|
shout_topics = await TopicStorage.get_topics_by_slugs([r.shout, ])
|
||||||
for t in shout_topics:
|
for t in shout_topics:
|
||||||
self.reacted["topics"][t] = self.reacted["topics"].get(t, [])
|
self.reacted["topics"][t] = self.reacted["topics"].get(t, [])
|
||||||
|
@ -122,7 +142,7 @@ class ReactedStorage:
|
||||||
self.rating["topics"][t] = \
|
self.rating["topics"][t] = \
|
||||||
self.rating["topics"].get(t, 0) + kind_to_rate(r.kind)
|
self.rating["topics"].get(t, 0) + kind_to_rate(r.kind)
|
||||||
if r.replyTo:
|
if r.replyTo:
|
||||||
# renew reaction counters
|
# renew reactions replies
|
||||||
self.reacted["reactions"][r.replyTo] = \
|
self.reacted["reactions"][r.replyTo] = \
|
||||||
self.reacted["reactions"].get(r.replyTo, [])
|
self.reacted["reactions"].get(r.replyTo, [])
|
||||||
self.reacted["reactions"][r.replyTo].append(r)
|
self.reacted["reactions"][r.replyTo].append(r)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user