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
|
||||
|
||||
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:
|
||||
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"))
|
||||
avatar_url = None if not photoId else self.config.avatar_base_url + photoId
|
||||
@@ -572,7 +578,7 @@ class AuthProcessors(BaseProcessor):
|
||||
"presence": {},
|
||||
"config": {
|
||||
"server": self.server_config,
|
||||
"user": json.loads(user_data.get("user_config")),
|
||||
"user": updated_user_config,
|
||||
},
|
||||
"token": token,
|
||||
"videoChatHistory": False,
|
||||
|
||||
@@ -127,5 +127,57 @@ class MainProcessors(BaseProcessor):
|
||||
cmd=self.proto.CMD_OK, seq=seq, opcode=self.opcodes.PROFILE, payload=payload
|
||||
)
|
||||
|
||||
# Отправляем
|
||||
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,
|
||||
writer,
|
||||
)
|
||||
case self.opcodes.CONFIG:
|
||||
await self.auth_required(
|
||||
userPhone,
|
||||
self.processors.update_config,
|
||||
payload,
|
||||
seq,
|
||||
writer,
|
||||
userPhone,
|
||||
)
|
||||
case _:
|
||||
self.logger.warning(f"Неизвестный опкод {opcode}")
|
||||
except Exception as e:
|
||||
|
||||
@@ -246,6 +246,15 @@ class OnemeWS:
|
||||
seq,
|
||||
websocket,
|
||||
)
|
||||
case self.opcodes.CONFIG:
|
||||
await self.auth_required(
|
||||
userPhone,
|
||||
self.processors.update_config,
|
||||
payload,
|
||||
seq,
|
||||
websocket,
|
||||
userPhone,
|
||||
)
|
||||
case _:
|
||||
self.logger.warning(f"Неизвестный опкод {opcode}")
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
|
||||
@@ -300,6 +300,12 @@ class AuthProcessors(BaseProcessor):
|
||||
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"))
|
||||
avatar_url = None if not photo_id else self.config.avatar_base_url + str(photo_id)
|
||||
@@ -335,7 +341,7 @@ class AuthProcessors(BaseProcessor):
|
||||
"config": {
|
||||
"hash": "e5903aa8-0000000000000000-80000106-0000000000000001-00000001-0000000000000000-00000000-2-00000001-0000019c9559d057",
|
||||
"server": self.server_config,
|
||||
"user": json.loads(user_data.get("user_config")),
|
||||
"user": updated_user_config,
|
||||
"chatFolders": {
|
||||
"FOLDERS": [],
|
||||
"ALL_FILTER_EXCLUDE": []
|
||||
|
||||
Reference in New Issue
Block a user