From c0e23840b5e1ebddd84393b002d45585e04564d2 Mon Sep 17 00:00:00 2001 From: Alexey Polyakov Date: Thu, 14 May 2026 17:30:57 +0300 Subject: [PATCH] maybe fixes --- src/common/sqlite.py | 3 +++ src/common/tools.py | 42 +++++++++++++++++++--------------- src/oneme/controller.py | 5 +++- src/oneme/processors/auth.py | 10 ++++---- src/oneme/processors/main.py | 2 +- src/oneme/processors/search.py | 4 ++-- src/tamtam/controller.py | 5 +++- src/tamtam/processors/auth.py | 8 +++---- 8 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/common/sqlite.py b/src/common/sqlite.py index 71ef9e6..8cc26c0 100644 --- a/src/common/sqlite.py +++ b/src/common/sqlite.py @@ -49,6 +49,9 @@ class SQLiteConnectionCompat: async def __aexit__(self, exc_type, exc, tb): return False + async def commit(self): + await self.connection.commit() + def cursor(self): return SQLiteCursorCompat(self.connection) diff --git a/src/common/tools.py b/src/common/tools.py index 6eb956d..9177dd8 100644 --- a/src/common/tools.py +++ b/src/common/tools.py @@ -39,17 +39,17 @@ class Tools: def generate_profile( self, - id=1, - phone=70000000000, + id=None, + phone=None, avatarUrl=None, photoId=None, - updateTime=0, - firstName="Test", - lastName="Account", - options=[], + updateTime=None, + firstName=None, + lastName=None, + options=None, description=None, - accountStatus=0, - profileOptions=[], + accountStatus=None, + profileOptions=None, includeProfileOptions=True, username=None, @@ -108,31 +108,32 @@ class Tools: def generate_profile_tt( self, - id=1, - phone=70000000000, + id=None, + phone=None, avatarUrl=None, photoId=None, - updateTime=0, - firstName="Test", - lastName="Account", - options=[], + updateTime=None, + firstName=None, + lastName=None, + options=None, description=None, username=None, custom_firstname=None, - custom_lastname=None + custom_lastname=None, + blocked=None ): # Так как TT не поддерживает фамилию, и если нам ее не передали в функцию # то используем только имя, чтобы избежать None в фамилии if firstName and lastName: - name = f"{firstName} {lastName}", + name = f"{firstName} {lastName}" else: name = firstName # Используем такой же костыль, как и выше - if custom_firstname: - custom_name = custom_firstname - elif custom_firstname and custom_lastname: + if custom_firstname and custom_lastname: custom_name = f"{custom_firstname} {custom_lastname}" + elif custom_firstname: + custom_name = custom_firstname else: custom_name = None @@ -163,6 +164,9 @@ class Tools: {"name": custom_name, "type": "CUSTOM"} ) + if blocked: + contact["status"] = "BLOCKED" + return contact def generate_chat( diff --git a/src/oneme/controller.py b/src/oneme/controller.py index 2dffbba..15581a3 100644 --- a/src/oneme/controller.py +++ b/src/oneme/controller.py @@ -22,6 +22,7 @@ class OnemeController(ControllerBase): # Выбираем протокол в зависимости от типа подключения proto = self.proto_web if is_web else self.proto_tcp + packet = None # Не отправляем событие самому себе if writer == eventData.get("writer"): @@ -94,7 +95,9 @@ class OnemeController(ControllerBase): cmd=0, seq=1, opcode=self.opcodes.NOTIF_PRESENCE, payload=payload ) - # Отправляем пакет + if not packet: + return + if is_web: await writer.send(packet) else: diff --git a/src/oneme/processors/auth.py b/src/oneme/processors/auth.py index da646c1..3013b8d 100644 --- a/src/oneme/processors/auth.py +++ b/src/oneme/processors/auth.py @@ -297,7 +297,7 @@ class AuthProcessors(BaseProcessor): photoId = ( None if not account.get("avatar_id") else int(account.get("avatar_id")) ) - avatar_url = None if not photoId else self.config.avatar_base_url + photoId + avatar_url = None if not photoId else self.config.avatar_base_url + str(photoId) description = ( None if not account.get("description") else account.get("description") ) @@ -521,7 +521,7 @@ class AuthProcessors(BaseProcessor): await self._send_error( seq, self.opcodes.LOGIN, self.error_types.INVALID_PAYLOAD, writer ) - return + return None, None, None # Чаты, где состоит пользователь chats = [] @@ -545,7 +545,7 @@ class AuthProcessors(BaseProcessor): await self._send_error( seq, self.opcodes.LOGIN, self.error_types.INVALID_TOKEN, writer ) - return + return None, None, None # Ищем аккаунт пользователя в бд await cursor.execute( @@ -563,7 +563,7 @@ class AuthProcessors(BaseProcessor): # Ищем все чаты, где состоит пользователь await cursor.execute( "SELECT * FROM chat_participants WHERE user_id = %s", - (user.get("id")), + (user.get("id"),), ) user_chats = await cursor.fetchall() @@ -578,7 +578,7 @@ class AuthProcessors(BaseProcessor): # Аватарка с биографией photoId = None if not user.get("avatar_id") else int(user.get("avatar_id")) - avatar_url = None if not photoId else self.config.avatar_base_url + photoId + avatar_url = None if not photoId else self.config.avatar_base_url + str(photoId) description = None if not user.get("description") else user.get("description") if self._check_legacy_version(appVersion): diff --git a/src/oneme/processors/main.py b/src/oneme/processors/main.py index 92ec267..eaf1f2c 100644 --- a/src/oneme/processors/main.py +++ b/src/oneme/processors/main.py @@ -153,7 +153,7 @@ class MainProcessors(BaseProcessor): # Аватарка с биографией photoId = None if not user.get("avatar_id") else int(user.get("avatar_id")) - avatar_url = None if not photoId else self.config.avatar_base_url + photoId + avatar_url = None if not photoId else self.config.avatar_base_url + str(photoId) description = None if not user.get("description") else user.get("description") # Генерируем профиль diff --git a/src/oneme/processors/search.py b/src/oneme/processors/search.py index 75534f2..f66ea91 100644 --- a/src/oneme/processors/search.py +++ b/src/oneme/processors/search.py @@ -36,7 +36,7 @@ class SearchProcessors(BaseProcessor): if user: # Аватарка с биографией photoId = None if not user.get("avatar_id") else int(user.get("avatar_id")) - avatar_url = None if not photoId else self.config.avatar_base_url + photoId + avatar_url = None if not photoId else self.config.avatar_base_url + str(photoId) description = None if not user.get("description") else user.get("description") # Получаем данные контакта @@ -129,7 +129,7 @@ class SearchProcessors(BaseProcessor): # Аватарка с биографией photoId = None if not user.get("avatar_id") else int(user.get("avatar_id")) - avatar_url = None if not photoId else self.config.avatar_base_url + photoId + avatar_url = None if not photoId else self.config.avatar_base_url + str(photoId) description = None if not user.get("description") else user.get("description") # Получаем данные контакта diff --git a/src/tamtam/controller.py b/src/tamtam/controller.py index aa3e43c..d9c3620 100644 --- a/src/tamtam/controller.py +++ b/src/tamtam/controller.py @@ -22,6 +22,7 @@ class TTController(ControllerBase): # Выбираем протокол в зависимости от типа подключения proto = self.proto_web if is_web else self.proto_tcp + packet = None # Не отправляем событие самому себе if writer == eventData.get("writer"): @@ -94,7 +95,9 @@ class TTController(ControllerBase): cmd=0, seq=1, opcode=self.opcodes.NOTIF_PRESENCE, payload=payload ) - # Отправляем пакет + if not packet: + return + if is_web: await writer.send(packet) else: diff --git a/src/tamtam/processors/auth.py b/src/tamtam/processors/auth.py index f54c01c..8e533d2 100644 --- a/src/tamtam/processors/auth.py +++ b/src/tamtam/processors/auth.py @@ -443,7 +443,7 @@ class AuthProcessors(BaseProcessor): self.logger.error(f"Возникли ошибки при валидации пакета: {e}") await self._send_error(seq, self.opcodes.LOGIN, self.error_types.INVALID_PAYLOAD, writer) - return + return None, None, None # Чаты, где состоит пользователь chats = [] @@ -464,7 +464,7 @@ class AuthProcessors(BaseProcessor): if token_data is None: await self._send_error(seq, self.opcodes.LOGIN, self.error_types.INVALID_TOKEN, writer) - return + return None, None, None # Ищем аккаунт пользователя в бд await cursor.execute("SELECT * FROM users WHERE phone = %s", (token_data.get("phone"),)) @@ -476,8 +476,8 @@ class AuthProcessors(BaseProcessor): # Ищем все чаты, где состоит пользователь await cursor.execute( - "SELECT * FROM chat_participants WHERE user_id = %s", - (user.get('id')) + "SELECT * FROM chat_participants WHERE user_id = %s", + (user.get('id'),) ) user_chats = await cursor.fetchall()