mirror of
https://github.com/openmax-server/server.git
synced 2026-05-22 19:41:41 +03:00
MAX: Рефактор папок
This commit is contained in:
@@ -13,6 +13,12 @@ class SQLQueries:
|
|||||||
|
|
||||||
INSERT_USER_DATA = """
|
INSERT_USER_DATA = """
|
||||||
INSERT INTO user_data
|
INSERT INTO user_data
|
||||||
(phone, folders, user_config, chat_config)
|
(phone, user_config, chat_config)
|
||||||
VALUES (%s, %s, %s, %s)
|
VALUES (%s, %s, %s)
|
||||||
|
"""
|
||||||
|
|
||||||
|
INSERT_DEFAULT_FOLDER = """
|
||||||
|
INSERT INTO user_folders
|
||||||
|
(id, phone, title, sort_order)
|
||||||
|
VALUES ('all.chat.folder', %s, 'Все', 0)
|
||||||
"""
|
"""
|
||||||
@@ -196,25 +196,6 @@ class Static:
|
|||||||
]},
|
]},
|
||||||
]
|
]
|
||||||
|
|
||||||
### Заглушка для папок
|
|
||||||
ALL_CHAT_FOLDER = [{
|
|
||||||
"id": "all.chat.folder",
|
|
||||||
"title": "Все",
|
|
||||||
"filters": [],
|
|
||||||
"updateTime": 0,
|
|
||||||
"options": [],
|
|
||||||
"sourceId": 1
|
|
||||||
}]
|
|
||||||
|
|
||||||
ALL_CHAT_FOLDER_ORDER = ["all.chat.folder"]
|
|
||||||
|
|
||||||
### Стандартные папки с настройками пользователя
|
|
||||||
USER_FOLDERS = {
|
|
||||||
"folders": [],
|
|
||||||
"foldersOrder": [],
|
|
||||||
"allFilterExcludeFolders": []
|
|
||||||
}
|
|
||||||
|
|
||||||
USER_SETTINGS = {
|
USER_SETTINGS = {
|
||||||
"CHATS_PUSH_NOTIFICATION": "ON",
|
"CHATS_PUSH_NOTIFICATION": "ON",
|
||||||
"PUSH_DETAILS": True,
|
"PUSH_DETAILS": True,
|
||||||
|
|||||||
@@ -403,17 +403,26 @@ class AuthProcessors(BaseProcessor):
|
|||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO user_data
|
INSERT INTO user_data
|
||||||
(phone, folders, user_config, chat_config)
|
(phone, user_config, chat_config)
|
||||||
VALUES (%s, %s, %s, %s)
|
VALUES (%s, %s, %s)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
phone,
|
phone,
|
||||||
json.dumps(self.static.USER_FOLDERS),
|
|
||||||
json.dumps(self.static.USER_SETTINGS),
|
json.dumps(self.static.USER_SETTINGS),
|
||||||
json.dumps({}),
|
json.dumps({}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Добавляем дефолтную папку
|
||||||
|
await cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO user_folders
|
||||||
|
(id, phone, title, sort_order)
|
||||||
|
VALUES ('all.chat.folder', %s, 'Все', 0)
|
||||||
|
""",
|
||||||
|
(phone,),
|
||||||
|
)
|
||||||
|
|
||||||
# Удаляем токен
|
# Удаляем токен
|
||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
"DELETE FROM auth_tokens WHERE token_hash = %s", (hashed_token,)
|
"DELETE FROM auth_tokens WHERE token_hash = %s", (hashed_token,)
|
||||||
|
|||||||
@@ -18,16 +18,31 @@ class FoldersProcessors(BaseProcessor):
|
|||||||
# Ищем папки в бд
|
# Ищем папки в бд
|
||||||
async with self.db_pool.acquire() as conn:
|
async with self.db_pool.acquire() as conn:
|
||||||
async with conn.cursor() as cursor:
|
async with conn.cursor() as cursor:
|
||||||
await cursor.execute("SELECT folders FROM user_data WHERE phone = %s", (int(senderPhone),))
|
await cursor.execute(
|
||||||
result_folders = await cursor.fetchone()
|
"SELECT id, title, filters, options, update_time, source_id "
|
||||||
user_folders = json.loads(result_folders.get("folders"))
|
"FROM user_folders WHERE phone = %s ORDER BY sort_order",
|
||||||
|
(int(senderPhone),)
|
||||||
|
)
|
||||||
|
result_folders = await cursor.fetchall()
|
||||||
|
|
||||||
|
folders = [
|
||||||
|
{
|
||||||
|
"id": folder["id"],
|
||||||
|
"title": folder["title"],
|
||||||
|
"filters": json.loads(folder["filters"]),
|
||||||
|
"updateTime": folder["update_time"],
|
||||||
|
"options": json.loads(folder["options"]),
|
||||||
|
"sourceId": folder["source_id"],
|
||||||
|
}
|
||||||
|
for folder in result_folders
|
||||||
|
]
|
||||||
|
|
||||||
# Создаем данные пакета
|
# Создаем данные пакета
|
||||||
payload = {
|
payload = {
|
||||||
"folderSync": int(time.time() * 1000),
|
"folderSync": int(time.time() * 1000),
|
||||||
"folders": self.static.ALL_CHAT_FOLDER + user_folders.get("folders"),
|
"folders": folders,
|
||||||
"foldersOrder": self.static.ALL_CHAT_FOLDER_ORDER + user_folders.get("foldersOrder"),
|
"foldersOrder": [folder["id"] for folder in result_folders],
|
||||||
"allFilterExcludeFolders": user_folders.get("allFilterExcludeFolders")
|
"allFilterExcludeFolders": []
|
||||||
}
|
}
|
||||||
|
|
||||||
# Собираем пакет
|
# Собираем пакет
|
||||||
|
|||||||
@@ -105,12 +105,17 @@ class TelegramBot:
|
|||||||
self.sql_queries.INSERT_USER_DATA,
|
self.sql_queries.INSERT_USER_DATA,
|
||||||
(
|
(
|
||||||
new_phone, # phone
|
new_phone, # phone
|
||||||
json.dumps(self.static.USER_FOLDERS), # folders
|
|
||||||
json.dumps(self.static.USER_SETTINGS), # user settings
|
json.dumps(self.static.USER_SETTINGS), # user settings
|
||||||
json.dumps({}), # chat_config
|
json.dumps({}), # chat_config
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Добавляем дефолтную папку
|
||||||
|
await cursor.execute(
|
||||||
|
self.sql_queries.INSERT_DEFAULT_FOLDER,
|
||||||
|
(new_phone,),
|
||||||
|
)
|
||||||
|
|
||||||
await message.answer(
|
await message.answer(
|
||||||
self.get_bot_message(
|
self.get_bot_message(
|
||||||
self.msg_types.REGISTRATION_SUCCESS
|
self.msg_types.REGISTRATION_SUCCESS
|
||||||
|
|||||||
13
tables.sql
13
tables.sql
@@ -38,7 +38,6 @@ CREATE TABLE `auth_tokens` (
|
|||||||
|
|
||||||
CREATE TABLE `user_data` (
|
CREATE TABLE `user_data` (
|
||||||
`phone` VARCHAR(20) NOT NULL UNIQUE,
|
`phone` VARCHAR(20) NOT NULL UNIQUE,
|
||||||
`folders` JSON NOT NULL,
|
|
||||||
`user_config` JSON NOT NULL,
|
`user_config` JSON NOT NULL,
|
||||||
`chat_config` JSON NOT NULL,
|
`chat_config` JSON NOT NULL,
|
||||||
PRIMARY KEY (`phone`)
|
PRIMARY KEY (`phone`)
|
||||||
@@ -97,3 +96,15 @@ CREATE TABLE `banners` (
|
|||||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE `user_folders` (
|
||||||
|
`id` VARCHAR(64) NOT NULL,
|
||||||
|
`phone` VARCHAR(20) NOT NULL,
|
||||||
|
`title` VARCHAR(128) NOT NULL,
|
||||||
|
`filters` JSON NOT NULL DEFAULT ('[]'),
|
||||||
|
`options` JSON NOT NULL DEFAULT ('[]'),
|
||||||
|
`source_id` INT NOT NULL DEFAULT 1,
|
||||||
|
`update_time` BIGINT NOT NULL DEFAULT 0,
|
||||||
|
`sort_order` INT NOT NULL DEFAULT 0,
|
||||||
|
PRIMARY KEY (`id`, `phone`)
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user