fix-imports

This commit is contained in:
Tony Rewin 2023-10-05 22:59:50 +03:00
parent f6e3320e18
commit 45d187786b
6 changed files with 35 additions and 10 deletions

View File

@ -3,7 +3,7 @@ aredis~=1.1.8
ariadne>=0.17.0
PyYAML>=5.4
pyjwt>=2.6.0
starlette
starlette @ git+https://github.com/starlette/starlette#main
sqlalchemy>=1.4.41
graphql-core>=3.0.3
gql~=3.4.0

View File

@ -23,7 +23,7 @@ from services.exceptions import (
from services.db import local_session
from services.schema import mutation, query
from orm import Role, User
from resolvers.zine.profile import user_subscriptions
from resolvers.profile import user_subscriptions
from settings import SESSION_TOKEN_HEADER, FRONTEND_URL

View File

@ -9,7 +9,7 @@ from services.db import local_session
from services.schema import mutation
from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.topic import Topic
from resolvers.zine.reactions import reactions_follow, reactions_unfollow
from resolvers.reactions import reactions_follow, reactions_unfollow
@mutation.field("createShout")

View File

@ -8,9 +8,9 @@ from auth.credentials import AuthCredentials
from orm.user import AuthorFollower
from orm.topic import TopicFollower
from orm.shout import ShoutReactionsFollower
from resolvers.zine.profile import author_follow, author_unfollow
from resolvers.zine.reactions import reactions_follow, reactions_unfollow
from resolvers.zine.topics import topic_follow, topic_unfollow
from resolvers.profile import author_follow, author_unfollow
from resolvers.reactions import reactions_follow, reactions_unfollow
from resolvers.topics import topic_follow, topic_unfollow
from services.following import Following, FollowingManager, FollowingResult
from graphql.type import GraphQLResolveInfo
@ -30,7 +30,8 @@ async def follow(_, info, what, slug):
result = FollowingResult("NEW", "topic", slug)
await FollowingManager.push("topic", result)
elif what == "COMMUNITY":
if False: # TODO: use community_follow(auth.user_id, slug):
if False:
# TODO: use community_follow(auth.user_id, slug):
result = FollowingResult("NEW", "community", slug)
await FollowingManager.push("community", result)
elif what == "REACTIONS":

View File

@ -5,7 +5,7 @@ from sqlalchemy.orm import aliased, joinedload
from auth.authenticate import login_required
from auth.credentials import AuthCredentials
from services.orm import local_session
from services.db import local_session
from services.schema import mutation, query
from orm.reaction import Reaction
from orm.shout import ShoutAuthor, ShoutTopic
@ -13,8 +13,8 @@ from orm.topic import Topic
from orm.user import AuthorFollower, Role, User, UserRating, UserRole
# from .community import followed_communities
from resolvers.inbox.unread import get_total_unread_counter
from resolvers.zine.topics import followed_by_user
from services.unread import get_total_unread_counter
from resolvers.topics import followed_by_user
def add_author_stat_columns(q, include_heavy_stat=False):

24
services/unread.py Normal file
View File

@ -0,0 +1,24 @@
from services.redis import redis
import json
async def get_unread_counter(chat_id: str, author_id: int):
try:
unread = await redis.execute(
"LLEN", f"chats/{chat_id.decode('utf-8')}/unread/{author_id}"
)
if unread:
return unread
except Exception:
return 0
async def get_total_unread_counter(author_id: int):
chats = await redis.execute("GET", f"chats_by_author/{author_id}")
unread = 0
if chats:
chats = json.loads(chats)
for chat_id in chats:
n = await get_unread_counter(chat_id.decode("utf-8"), author_id)
unread += n
return unread