From 87cfc1932e3df318b14bc58e9d24137fa6b0cf0c Mon Sep 17 00:00:00 2001 From: Alexey Polyakov Date: Sun, 10 May 2026 19:04:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=87=D0=B8=D0=BD=D0=B8=D1=82=D1=8C=20=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D1=8E=20(=D1=81=D0=BF=D0=BE=D0=B9?= =?UTF-8?q?=D0=BB=D0=B5=D1=80,=20=D0=BD=D0=B8=D1=85=D1=83=D1=8F=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B8=D0=BB=D0=BE=D1=81?= =?UTF-8?q?=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/tools.py | 38 ++++++++++++----- src/oneme/processors/history.py | 74 +++++++++++++++++++++++---------- tables.sql | 2 +- 3 files changed, 80 insertions(+), 34 deletions(-) diff --git a/src/common/tools.py b/src/common/tools.py index 06ff4a2..af3e9d3 100644 --- a/src/common/tools.py +++ b/src/common/tools.py @@ -1,4 +1,5 @@ import json +import random import secrets import time @@ -45,6 +46,8 @@ class Tools: ], "options": options, "accountStatus": accountStatus, + "location": "RU", + "registrationTime": int(time.time() * 1000) } if avatarUrl: @@ -371,10 +374,14 @@ class Tools: last_message_id = row.get("id") or 0 # последнее id сообщения в чате message_time = int(time.time() * 1000) # время отправки сообщения + # Генерируем ID сообщения + message_id = int(time.time() * 1000000) * 1000 + random.randint(100, 999) + # Вносим новое сообщение в таблицу await cursor.execute( - "INSERT INTO `messages` (chat_id, sender, time, text, attaches, cid, elements, type) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", + "INSERT INTO `messages` (id, chat_id, sender, time, text, attaches, cid, elements, type) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", ( + message_id, chatId, senderId, message_time, @@ -386,8 +393,6 @@ class Tools: ), ) - message_id = cursor.lastrowid - # Возвращаем айдишки return int(message_id), int(last_message_id), message_time @@ -407,22 +412,33 @@ class Tools: if not row: return None, None - # Собираем сообщение message = { + "sender": row.get("sender"), "id": row.get("id") if protocol_type == "mobile" else str(row.get("id")), "time": int(row.get("time")), - "type": row.get("type"), - "sender": row.get("sender"), - "cid": int(row.get("cid")), "text": row.get("text"), - "attaches": json.loads(row.get("attaches")), - "elements": json.loads(row.get("elements")), - "reactionInfo": {}, - "link": {} + "type": row.get("type"), + "attaches": json.loads(row.get("attaches")) } + elements = json.loads(row.get("elements")) + link = {} + reaction_info = {} + + if elements: + message["elements"] = elements + + if link: + message["link"] = link + + if reaction_info: + message["reactionInfo"] = reaction_info + + if protocol_type == "web": + message["cid"] = int(row.get("cid")) + # Возвращаем return message, int(row.get("time")) diff --git a/src/oneme/processors/history.py b/src/oneme/processors/history.py index 15deab8..8b5db5b 100644 --- a/src/oneme/processors/history.py +++ b/src/oneme/processors/history.py @@ -60,20 +60,34 @@ class HistoryProcessors(BaseProcessor): for row in result: # TODO: Сборку тела сообщения нужно вынести в отдельную функцию - messages.append({ - "id": row.get("id") if self.type == 'mobile' else str(row.get('id')), - "time": int(row.get("time")), - "type": row.get("type"), + message = { "sender": row.get("sender"), - "cid": int(row.get("cid")), + "id": row.get("id") + if self.type == "mobile" + else str(row.get("id")), + "time": int(row.get("time")), "text": row.get("text"), - "attaches": json.loads(row.get("attaches")), - "elements": json.loads(row.get("elements")), - "reactionInfo": {}, - "link": {}, - #"options": 1, - }) + "type": row.get("type"), + "attaches": json.loads(row.get("attaches")) + } + elements = json.loads(row.get("elements")) + link = {} + reaction_info = {} + + if elements: + message["elements"] = elements + + if link: + message["link"] = link + + if reaction_info: + message["reactionInfo"] = reaction_info + + if self.type == "web": + message["cid"] = int(row.get("cid")) + + messages.append(message) if forward > 0: await cursor.execute( "SELECT * FROM messages WHERE chat_id = %s AND time > %s ORDER BY time ASC LIMIT %s", @@ -83,19 +97,35 @@ class HistoryProcessors(BaseProcessor): result = await cursor.fetchall() for row in result: - messages.append({ - "id": row.get("id") if self.type == 'mobile' else str(row.get('id')), - "time": int(row.get("time")), - "type": row.get("type"), + # TODO: Сборку тела сообщения нужно вынести в отдельную функцию + message = { "sender": row.get("sender"), - "cid": int(row.get("cid")), + "id": row.get("id") + if self.type == "mobile" + else str(row.get("id")), + "time": int(row.get("time")), "text": row.get("text"), - "attaches": json.loads(row.get("attaches")), - "elements": json.loads(row.get("elements")), - "reactionInfo": {}, - "link": {} - #"options": 1, - }) + "type": row.get("type"), + "attaches": json.loads(row.get("attaches")) + } + + elements = json.loads(row.get("elements")) + link = {} + reaction_info = {} + + if elements: + message["elements"] = elements + + if link: + message["link"] = link + + if reaction_info: + message["reactionInfo"] = reaction_info + + if self.type == "web": + message["cid"] = int(row.get("cid")) + + messages.append(message) # Сортируем сообщения по времени messages.sort(key=lambda x: x["time"]) diff --git a/tables.sql b/tables.sql index 8c2c62a..5cb7a6a 100644 --- a/tables.sql +++ b/tables.sql @@ -51,7 +51,7 @@ CREATE TABLE `chats` ( ); CREATE TABLE `messages` ( - `id` INT NOT NULL AUTO_INCREMENT, + `id` BIGINT NOT NULL, `chat_id` INT NOT NULL, `sender` INT NOT NULL, `time` VARCHAR(32) NOT NULL,