mirror of
https://github.com/openmax-server/server.git
synced 2026-05-13 09:15:49 +00:00
Попытка починить историю (спойлер, нихуя не получилось)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import random
|
||||||
import secrets
|
import secrets
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -45,6 +46,8 @@ class Tools:
|
|||||||
],
|
],
|
||||||
"options": options,
|
"options": options,
|
||||||
"accountStatus": accountStatus,
|
"accountStatus": accountStatus,
|
||||||
|
"location": "RU",
|
||||||
|
"registrationTime": int(time.time() * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
if avatarUrl:
|
if avatarUrl:
|
||||||
@@ -371,10 +374,14 @@ class Tools:
|
|||||||
last_message_id = row.get("id") or 0 # последнее id сообщения в чате
|
last_message_id = row.get("id") or 0 # последнее id сообщения в чате
|
||||||
message_time = int(time.time() * 1000) # время отправки сообщения
|
message_time = int(time.time() * 1000) # время отправки сообщения
|
||||||
|
|
||||||
|
# Генерируем ID сообщения
|
||||||
|
message_id = int(time.time() * 1000000) * 1000 + random.randint(100, 999)
|
||||||
|
|
||||||
# Вносим новое сообщение в таблицу
|
# Вносим новое сообщение в таблицу
|
||||||
await cursor.execute(
|
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,
|
chatId,
|
||||||
senderId,
|
senderId,
|
||||||
message_time,
|
message_time,
|
||||||
@@ -386,8 +393,6 @@ class Tools:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
message_id = cursor.lastrowid
|
|
||||||
|
|
||||||
# Возвращаем айдишки
|
# Возвращаем айдишки
|
||||||
return int(message_id), int(last_message_id), message_time
|
return int(message_id), int(last_message_id), message_time
|
||||||
|
|
||||||
@@ -407,22 +412,33 @@ class Tools:
|
|||||||
if not row:
|
if not row:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
# Собираем сообщение
|
|
||||||
message = {
|
message = {
|
||||||
|
"sender": row.get("sender"),
|
||||||
"id": row.get("id")
|
"id": row.get("id")
|
||||||
if protocol_type == "mobile"
|
if protocol_type == "mobile"
|
||||||
else str(row.get("id")),
|
else str(row.get("id")),
|
||||||
"time": int(row.get("time")),
|
"time": int(row.get("time")),
|
||||||
"type": row.get("type"),
|
|
||||||
"sender": row.get("sender"),
|
|
||||||
"cid": int(row.get("cid")),
|
|
||||||
"text": row.get("text"),
|
"text": row.get("text"),
|
||||||
"attaches": json.loads(row.get("attaches")),
|
"type": row.get("type"),
|
||||||
"elements": json.loads(row.get("elements")),
|
"attaches": json.loads(row.get("attaches"))
|
||||||
"reactionInfo": {},
|
|
||||||
"link": {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"))
|
return message, int(row.get("time"))
|
||||||
|
|
||||||
|
|||||||
@@ -60,20 +60,34 @@ class HistoryProcessors(BaseProcessor):
|
|||||||
|
|
||||||
for row in result:
|
for row in result:
|
||||||
# TODO: Сборку тела сообщения нужно вынести в отдельную функцию
|
# TODO: Сборку тела сообщения нужно вынести в отдельную функцию
|
||||||
messages.append({
|
message = {
|
||||||
"id": row.get("id") if self.type == 'mobile' else str(row.get('id')),
|
|
||||||
"time": int(row.get("time")),
|
|
||||||
"type": row.get("type"),
|
|
||||||
"sender": row.get("sender"),
|
"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"),
|
"text": row.get("text"),
|
||||||
"attaches": json.loads(row.get("attaches")),
|
"type": row.get("type"),
|
||||||
"elements": json.loads(row.get("elements")),
|
"attaches": json.loads(row.get("attaches"))
|
||||||
"reactionInfo": {},
|
}
|
||||||
"link": {},
|
|
||||||
#"options": 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
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:
|
if forward > 0:
|
||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
"SELECT * FROM messages WHERE chat_id = %s AND time > %s ORDER BY time ASC LIMIT %s",
|
"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()
|
result = await cursor.fetchall()
|
||||||
|
|
||||||
for row in result:
|
for row in result:
|
||||||
messages.append({
|
# TODO: Сборку тела сообщения нужно вынести в отдельную функцию
|
||||||
"id": row.get("id") if self.type == 'mobile' else str(row.get('id')),
|
message = {
|
||||||
"time": int(row.get("time")),
|
|
||||||
"type": row.get("type"),
|
|
||||||
"sender": row.get("sender"),
|
"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"),
|
"text": row.get("text"),
|
||||||
"attaches": json.loads(row.get("attaches")),
|
"type": row.get("type"),
|
||||||
"elements": json.loads(row.get("elements")),
|
"attaches": json.loads(row.get("attaches"))
|
||||||
"reactionInfo": {},
|
}
|
||||||
"link": {}
|
|
||||||
#"options": 1,
|
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"])
|
messages.sort(key=lambda x: x["time"])
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ CREATE TABLE `chats` (
|
|||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE `messages` (
|
CREATE TABLE `messages` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT,
|
`id` BIGINT NOT NULL,
|
||||||
`chat_id` INT NOT NULL,
|
`chat_id` INT NOT NULL,
|
||||||
`sender` INT NOT NULL,
|
`sender` INT NOT NULL,
|
||||||
`time` VARCHAR(32) NOT NULL,
|
`time` VARCHAR(32) NOT NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user