hotfix-loadchats

This commit is contained in:
tonyrewin 2022-11-27 16:14:17 +03:00
parent 90e8e24743
commit 8377043286
4 changed files with 14 additions and 12 deletions

View File

@ -10,13 +10,13 @@ lang_subject = {
}
async def send_auth_email(user, token, lang="ru"):
async def send_auth_email(user, token, template="email_confirmation", lang="ru"):
try:
to = "%s <%s>" % (user.name, user.email)
if lang not in ['ru', 'en']:
lang = 'ru'
subject = lang_subject.get(lang, lang_subject["en"])
template = "email_confirmation_" + lang
template = template + "_" + lang
payload = {
"from": noreply,
"to": to,

View File

@ -133,7 +133,7 @@ async def register_by_email(_, _info, email: str, password: str = "", name: str
@mutation.field("sendLink")
async def auth_send_link(_, _info, email, lang="ru"):
async def auth_send_link(_, _info, email, lang="ru", template="email_confirmation"):
"""send link with confirm code to email"""
with local_session() as session:
user = session.query(User).filter(User.email == email).first()
@ -141,7 +141,7 @@ async def auth_send_link(_, _info, email, lang="ru"):
raise ObjectNotExist("User not found")
else:
token = await TokenStorage.create_onetime(user)
await send_auth_email(user, token, lang)
await send_auth_email(user, token, lang, template)
return user

View File

@ -5,7 +5,7 @@ from auth.authenticate import login_required
from base.redis import redis
from base.orm import local_session
from base.resolvers import query
from base.exceptions import ObjectNotExist
from base.exceptions import ObjectNotExist, Unauthorized
from orm.user import User
from resolvers.zine.profile import followed_authors
from .unread import get_unread_counter
@ -31,7 +31,10 @@ async def load_messages(chat_id: str, limit: int, offset: int):
async def load_chats(_, info, limit: int = 50, offset: int = 0):
""" load :limit chats of current user with :offset """
user = info.context["request"].user
print('[inbox] load user\'s chats')
if user:
print('[inbox] load user\'s chats %s' % user.slug)
else:
raise Unauthorized("Please login to load chats")
cids = await redis.execute("SMEMBERS", "chats_by_user/" + user.slug)
if cids:
cids = list(cids)[offset:offset + limit]
@ -47,15 +50,14 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0):
c['unread'] = await get_unread_counter(cid, user.slug)
with local_session() as session:
c['members'] = []
for user in c["users"]:
a = session.query(User).where(User.slug == user).first().dict()
for userslug in c["users"]:
a = session.query(User).where(User.slug == userslug).first().dict()
c['members'].append({
"slug": user,
"slug": userslug,
"userpic": a["userpic"],
"name": a["name"],
"lastSeen": a["lastSeen"],
})
del c["users"]
chats.append(c)
return {
"chats": chats,
@ -66,7 +68,7 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0):
@query.field("loadMessagesBy")
@login_required
async def load_messages_by(_, info, by, limit: int = 50, offset: int = 0):
''' load :amolimitunt messages of :chat_id with :offset '''
''' load :limit messages of :chat_id with :offset '''
messages = set([])
by_chat = by.get('chat')
if by_chat:

View File

@ -160,7 +160,7 @@ type Mutation {
# auth
getSession: AuthResult!
registerUser(email: String!, password: String, name: String): AuthResult!
sendLink(email: String!, lang: String): Result!
sendLink(email: String!, lang: String, template: String): Result!
confirmEmail(token: String!): AuthResult!
# shout