Починил немного сокет тамтама
This commit is contained in:
parent
a45f99424c
commit
c2194f6aa9
|
|
@ -47,6 +47,38 @@ class Tools:
|
||||||
else:
|
else:
|
||||||
return contact
|
return contact
|
||||||
|
|
||||||
|
def generate_profile_tt(
|
||||||
|
self, id=1, phone=70000000000, avatarUrl=None,
|
||||||
|
photoId=None, updateTime=0,
|
||||||
|
firstName="Test", lastName="Account", options=[],
|
||||||
|
description=None, username=None
|
||||||
|
):
|
||||||
|
contact = {
|
||||||
|
"id": id,
|
||||||
|
"updateTime": updateTime,
|
||||||
|
"phone": phone,
|
||||||
|
"names": [
|
||||||
|
{
|
||||||
|
"name": f"{firstName} {lastName}",
|
||||||
|
"type": "TT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"options": options
|
||||||
|
}
|
||||||
|
|
||||||
|
if avatarUrl:
|
||||||
|
contact["photoId"] = photoId
|
||||||
|
contact["baseUrl"] = avatarUrl
|
||||||
|
contact["baseRawUrl"] = avatarUrl
|
||||||
|
|
||||||
|
if description:
|
||||||
|
contact["description"] = description
|
||||||
|
|
||||||
|
if username:
|
||||||
|
contact["link"] = "https://tamtam.chat/" + username
|
||||||
|
|
||||||
|
return contact
|
||||||
|
|
||||||
def generate_chat(self, id, owner, type, participants, lastMessage, lastEventTime):
|
def generate_chat(self, id, owner, type, participants, lastMessage, lastEventTime):
|
||||||
"""Генерация чата"""
|
"""Генерация чата"""
|
||||||
# Генерируем список участников
|
# Генерируем список участников
|
||||||
|
|
|
||||||
|
|
@ -160,12 +160,6 @@ class Processors:
|
||||||
# Обновляем состояние токена
|
# Обновляем состояние токена
|
||||||
await cursor.execute("UPDATE auth_tokens set state = %s WHERE token_hash = %s", ("verified", hashed_token,))
|
await cursor.execute("UPDATE auth_tokens set state = %s WHERE token_hash = %s", ("verified", hashed_token,))
|
||||||
|
|
||||||
# # Создаем сессию
|
|
||||||
# await cursor.execute(
|
|
||||||
# "INSERT INTO tokens (phone, token_hash, device_type, device_name, location, time) VALUES (%s, %s, %s, %s, %s, %s)",
|
|
||||||
# (stored_token.get("phone"), hashed_login, deviceType, deviceName, "Epstein Island", int(time.time()),)
|
|
||||||
# )
|
|
||||||
|
|
||||||
# Генерируем профиль
|
# Генерируем профиль
|
||||||
# Аватарка с биографией
|
# Аватарка с биографией
|
||||||
photoId = None if not account.get("avatar_id") else int(account.get("avatar_id"))
|
photoId = None if not account.get("avatar_id") else int(account.get("avatar_id"))
|
||||||
|
|
@ -174,7 +168,7 @@ class Processors:
|
||||||
|
|
||||||
# Собираем данные пакета
|
# Собираем данные пакета
|
||||||
payload = {
|
payload = {
|
||||||
"profile": self.tools.generate_profile(
|
"profile": self.tools.generate_profile_tt(
|
||||||
id=account.get("id"),
|
id=account.get("id"),
|
||||||
phone=int(account.get("phone")),
|
phone=int(account.get("phone")),
|
||||||
avatarUrl=avatar_url,
|
avatarUrl=avatar_url,
|
||||||
|
|
@ -184,12 +178,8 @@ class Processors:
|
||||||
lastName=account.get("lastname"),
|
lastName=account.get("lastname"),
|
||||||
options=json.loads(account.get("options")),
|
options=json.loads(account.get("options")),
|
||||||
description=description,
|
description=description,
|
||||||
accountStatus=int(account.get("accountstatus")),
|
username=account.get("username")
|
||||||
profileOptions=json.loads(account.get("profileoptions")),
|
),
|
||||||
includeProfileOptions=False,
|
|
||||||
username=account.get("username"),
|
|
||||||
type="TT"
|
|
||||||
).get("contact"),
|
|
||||||
"tokenAttrs": {
|
"tokenAttrs": {
|
||||||
"AUTH": {
|
"AUTH": {
|
||||||
"token": token
|
"token": token
|
||||||
|
|
@ -239,6 +229,7 @@ class Processors:
|
||||||
await self._send_error(seq, self.proto.VERIFY_CODE, self.error_types.INVALID_TOKEN, writer)
|
await self._send_error(seq, self.proto.VERIFY_CODE, self.error_types.INVALID_TOKEN, writer)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Если авторизация только началась - отдаем ошибку
|
||||||
if stored_token.get("state") == "started":
|
if stored_token.get("state") == "started":
|
||||||
await self._send_error(seq, self.proto.VERIFY_CODE, self.error_types.INVALID_TOKEN, writer)
|
await self._send_error(seq, self.proto.VERIFY_CODE, self.error_types.INVALID_TOKEN, writer)
|
||||||
return
|
return
|
||||||
|
|
@ -247,7 +238,7 @@ class Processors:
|
||||||
await cursor.execute("SELECT * FROM users WHERE phone = %s", (stored_token.get("phone"),))
|
await cursor.execute("SELECT * FROM users WHERE phone = %s", (stored_token.get("phone"),))
|
||||||
account = await cursor.fetchone()
|
account = await cursor.fetchone()
|
||||||
|
|
||||||
# Обновляем состояние токена
|
# Удаляем токен
|
||||||
await cursor.execute("DELETE FROM auth_tokens WHERE token_hash = %s", (hashed_token,))
|
await cursor.execute("DELETE FROM auth_tokens WHERE token_hash = %s", (hashed_token,))
|
||||||
|
|
||||||
# Создаем сессию
|
# Создаем сессию
|
||||||
|
|
@ -263,8 +254,8 @@ class Processors:
|
||||||
|
|
||||||
# Собираем данные пакета
|
# Собираем данные пакета
|
||||||
payload = {
|
payload = {
|
||||||
"userToken": "0",
|
"userToken": "0", # Пока как заглушка
|
||||||
"profile": self.tools.generate_profile(
|
"profile": self.tools.generate_profile_tt(
|
||||||
id=account.get("id"),
|
id=account.get("id"),
|
||||||
phone=int(account.get("phone")),
|
phone=int(account.get("phone")),
|
||||||
avatarUrl=avatar_url,
|
avatarUrl=avatar_url,
|
||||||
|
|
@ -274,18 +265,16 @@ class Processors:
|
||||||
lastName=account.get("lastname"),
|
lastName=account.get("lastname"),
|
||||||
options=json.loads(account.get("options")),
|
options=json.loads(account.get("options")),
|
||||||
description=description,
|
description=description,
|
||||||
accountStatus=int(account.get("accountstatus")),
|
username=account.get("username")
|
||||||
profileOptions=json.loads(account.get("profileoptions")),
|
),
|
||||||
includeProfileOptions=False,
|
|
||||||
username=account.get("username"),
|
|
||||||
type="TT"
|
|
||||||
).get("contact"),
|
|
||||||
"tokenType": "LOGIN",
|
"tokenType": "LOGIN",
|
||||||
"token": login
|
"token": login
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Создаем пакет
|
||||||
packet = self.proto.pack_packet(
|
packet = self.proto.pack_packet(
|
||||||
cmd=self.proto.CMD_OK, seq=seq, opcode=self.proto.FINAL_AUTH, payload=payload
|
cmd=self.proto.CMD_OK, seq=seq, opcode=self.proto.FINAL_AUTH, payload=payload
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Отправялем
|
||||||
await self._send(writer, packet)
|
await self._send(writer, packet)
|
||||||
Loading…
Reference in New Issue