mirror of
https://github.com/openmax-server/server.git
synced 2026-05-22 19:41:41 +03:00
MAX: обновление настроек приватности
This commit is contained in:
@@ -503,3 +503,17 @@ class Tools:
|
|||||||
|
|
||||||
# Возвращаем
|
# Возвращаем
|
||||||
return unique_id
|
return unique_id
|
||||||
|
|
||||||
|
async def update_user_config(self, cursor, phone, user_settings, default_settings):
|
||||||
|
"""Функция для обновления юзер конфига из бд в случае его изменения"""
|
||||||
|
|
||||||
|
user_config = json.loads(user_settings)
|
||||||
|
updated_config = {**default_settings, **user_config}
|
||||||
|
|
||||||
|
if updated_config != user_config:
|
||||||
|
await cursor.execute(
|
||||||
|
"UPDATE user_data SET user_config = %s WHERE phone = %s",
|
||||||
|
(json.dumps(updated_config), phone),
|
||||||
|
)
|
||||||
|
|
||||||
|
return updated_config
|
||||||
|
|||||||
@@ -530,6 +530,12 @@ class AuthProcessors(BaseProcessor):
|
|||||||
for chat in user_chats:
|
for chat in user_chats:
|
||||||
chats.append(chat.get("chat_id"))
|
chats.append(chat.get("chat_id"))
|
||||||
|
|
||||||
|
# Обновляем юзер конфиг
|
||||||
|
updated_user_config = await self.tools.update_user_config(
|
||||||
|
cursor, token_data.get("phone"),
|
||||||
|
user_data.get("user_config"), self.static.USER_SETTINGS
|
||||||
|
)
|
||||||
|
|
||||||
# Аватарка с биографией
|
# Аватарка с биографией
|
||||||
photoId = None if not user.get("avatar_id") else int(user.get("avatar_id"))
|
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 + photoId
|
||||||
@@ -572,7 +578,7 @@ class AuthProcessors(BaseProcessor):
|
|||||||
"presence": {},
|
"presence": {},
|
||||||
"config": {
|
"config": {
|
||||||
"server": self.server_config,
|
"server": self.server_config,
|
||||||
"user": json.loads(user_data.get("user_config")),
|
"user": updated_user_config,
|
||||||
},
|
},
|
||||||
"token": token,
|
"token": token,
|
||||||
"videoChatHistory": False,
|
"videoChatHistory": False,
|
||||||
|
|||||||
@@ -129,3 +129,55 @@ class MainProcessors(BaseProcessor):
|
|||||||
|
|
||||||
# Отправляем
|
# Отправляем
|
||||||
await self._send(writer, response)
|
await self._send(writer, response)
|
||||||
|
|
||||||
|
async def update_config(self, payload, seq, writer, userPhone):
|
||||||
|
"""
|
||||||
|
Обработчик 22 опкода (config)
|
||||||
|
Он отвечает за обновление настроек приватности
|
||||||
|
и пуш токена для пушей
|
||||||
|
"""
|
||||||
|
# Пейлоад, который отдадим клиенту
|
||||||
|
# а отдавать его нужно только при изменении настроек приватности
|
||||||
|
result_payload = None
|
||||||
|
|
||||||
|
if payload.get("pushToken") and payload.get("pushOptions"):
|
||||||
|
# TODO: Когда сядем за пуши, сделать тут обновление пуш токена
|
||||||
|
pass
|
||||||
|
elif payload.get("settings") and payload.get("settings").get("user"):
|
||||||
|
"""Обновление настроек приватности"""
|
||||||
|
new_settings = payload.get("settings").get("user")
|
||||||
|
|
||||||
|
async with self.db_pool.acquire() as conn:
|
||||||
|
async with conn.cursor() as cursor:
|
||||||
|
# Получаем текущий конфиг
|
||||||
|
await cursor.execute(
|
||||||
|
"SELECT user_config FROM user_data WHERE phone = %s", (userPhone,)
|
||||||
|
)
|
||||||
|
row = await cursor.fetchone()
|
||||||
|
|
||||||
|
if row:
|
||||||
|
current_config = json.loads(row.get("user_config"))
|
||||||
|
|
||||||
|
# Обновляем настройки
|
||||||
|
for key, value in new_settings.items():
|
||||||
|
if key in current_config:
|
||||||
|
current_config[key] = value
|
||||||
|
|
||||||
|
# Сохраняем обновлённый конфиг
|
||||||
|
await cursor.execute(
|
||||||
|
"UPDATE user_data SET user_config = %s WHERE phone = %s",
|
||||||
|
(json.dumps(current_config), userPhone)
|
||||||
|
)
|
||||||
|
|
||||||
|
result_payload = {
|
||||||
|
"user": current_config,
|
||||||
|
"hash": "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Собираем пакет
|
||||||
|
response = self.proto.pack_packet(
|
||||||
|
cmd=self.proto.CMD_OK, seq=seq, opcode=self.opcodes.CONFIG, payload=result_payload
|
||||||
|
)
|
||||||
|
|
||||||
|
# Отправляем
|
||||||
|
await self._send(writer, response)
|
||||||
@@ -272,6 +272,15 @@ class OnemeMobile:
|
|||||||
seq,
|
seq,
|
||||||
writer,
|
writer,
|
||||||
)
|
)
|
||||||
|
case self.opcodes.CONFIG:
|
||||||
|
await self.auth_required(
|
||||||
|
userPhone,
|
||||||
|
self.processors.update_config,
|
||||||
|
payload,
|
||||||
|
seq,
|
||||||
|
writer,
|
||||||
|
userPhone,
|
||||||
|
)
|
||||||
case _:
|
case _:
|
||||||
self.logger.warning(f"Неизвестный опкод {opcode}")
|
self.logger.warning(f"Неизвестный опкод {opcode}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -246,6 +246,15 @@ class OnemeWS:
|
|||||||
seq,
|
seq,
|
||||||
websocket,
|
websocket,
|
||||||
)
|
)
|
||||||
|
case self.opcodes.CONFIG:
|
||||||
|
await self.auth_required(
|
||||||
|
userPhone,
|
||||||
|
self.processors.update_config,
|
||||||
|
payload,
|
||||||
|
seq,
|
||||||
|
websocket,
|
||||||
|
userPhone,
|
||||||
|
)
|
||||||
case _:
|
case _:
|
||||||
self.logger.warning(f"Неизвестный опкод {opcode}")
|
self.logger.warning(f"Неизвестный опкод {opcode}")
|
||||||
except websockets.exceptions.ConnectionClosed:
|
except websockets.exceptions.ConnectionClosed:
|
||||||
|
|||||||
@@ -300,6 +300,12 @@ class AuthProcessors(BaseProcessor):
|
|||||||
chat.get("chat_id")
|
chat.get("chat_id")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Обновляем юзер конфиг
|
||||||
|
updated_user_config = await self.tools.update_user_config(
|
||||||
|
cursor, token_data.get("phone"),
|
||||||
|
user_data.get("user_config"), self.static.USER_SETTINGS
|
||||||
|
)
|
||||||
|
|
||||||
# Аватарка с биографией
|
# Аватарка с биографией
|
||||||
photo_id = None if not user.get("avatar_id") else int(user.get("avatar_id"))
|
photo_id = None if not user.get("avatar_id") else int(user.get("avatar_id"))
|
||||||
avatar_url = None if not photo_id else self.config.avatar_base_url + str(photo_id)
|
avatar_url = None if not photo_id else self.config.avatar_base_url + str(photo_id)
|
||||||
@@ -335,7 +341,7 @@ class AuthProcessors(BaseProcessor):
|
|||||||
"config": {
|
"config": {
|
||||||
"hash": "e5903aa8-0000000000000000-80000106-0000000000000001-00000001-0000000000000000-00000000-2-00000001-0000019c9559d057",
|
"hash": "e5903aa8-0000000000000000-80000106-0000000000000001-00000001-0000000000000000-00000000-2-00000001-0000019c9559d057",
|
||||||
"server": self.server_config,
|
"server": self.server_config,
|
||||||
"user": json.loads(user_data.get("user_config")),
|
"user": updated_user_config,
|
||||||
"chatFolders": {
|
"chatFolders": {
|
||||||
"FOLDERS": [],
|
"FOLDERS": [],
|
||||||
"ALL_FILTER_EXCLUDE": []
|
"ALL_FILTER_EXCLUDE": []
|
||||||
|
|||||||
Reference in New Issue
Block a user