fix-auth
This commit is contained in:
@@ -2,21 +2,21 @@ from base.redis import redis
|
||||
import json
|
||||
|
||||
|
||||
async def get_unread_counter(chat_id: str, user_slug: str):
|
||||
async def get_unread_counter(chat_id: str, user_id: int):
|
||||
try:
|
||||
unread = await redis.execute("LLEN", f"chats/{chat_id}/unread/{user_slug}")
|
||||
unread = await redis.execute("LLEN", f"chats/{chat_id.decode('utf-8')}/unread/{user_id}")
|
||||
if unread:
|
||||
return unread
|
||||
except Exception:
|
||||
return 0
|
||||
|
||||
|
||||
async def get_total_unread_counter(user_slug: str):
|
||||
chats = await redis.execute("GET", f"chats_by_user/{user_slug}")
|
||||
async def get_total_unread_counter(user_id: int):
|
||||
chats = await redis.execute("GET", f"chats_by_user/{str(user_id)}")
|
||||
unread = 0
|
||||
if chats:
|
||||
chats = json.loads(chats)
|
||||
for chat_id in chats:
|
||||
n = await get_unread_counter(chat_id.decode('utf-8'), user_slug)
|
||||
n = await get_unread_counter(chat_id.decode('utf-8'), user_id)
|
||||
unread += n
|
||||
return unread
|
||||
|
@@ -163,14 +163,20 @@ async def get_user_roles(slug):
|
||||
@mutation.field("updateProfile")
|
||||
@login_required
|
||||
async def update_profile(_, info, profile):
|
||||
print('[zine] update_profile')
|
||||
print(profile)
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
with local_session() as session:
|
||||
user = session.query(User).filter(User.id == user_id).first()
|
||||
if user:
|
||||
User.update(user, **profile)
|
||||
session.add(user)
|
||||
session.commit()
|
||||
session.query(User).filter(User.id == user_id).update({
|
||||
"name": profile['name'],
|
||||
"slug": profile['slug'],
|
||||
"bio": profile['bio'],
|
||||
"userpic": profile['userpic'],
|
||||
"about": profile['about'],
|
||||
"links": profile['links']
|
||||
})
|
||||
session.commit()
|
||||
return {}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user