mirror of
https://github.com/openmax-server/server.git
synced 2026-05-23 03:51:43 +03:00
MAX: заглушка для баннеров, правка пакета со списком жалоб, отдача контактов и прочие улучшения
This commit is contained in:
@@ -18,6 +18,10 @@ class OnemeController(ControllerBase):
|
||||
eventType = eventData.get("eventType")
|
||||
writer = client.get("writer")
|
||||
|
||||
# Не отправляем событие самому себе
|
||||
if writer == eventData.get("writer"):
|
||||
return
|
||||
|
||||
# Обрабатываем событие
|
||||
if eventType == "new_msg":
|
||||
# Данные сообщения
|
||||
@@ -72,9 +76,8 @@ class OnemeController(ControllerBase):
|
||||
)
|
||||
|
||||
# Отправляем пакет
|
||||
if writer != eventData.get("writer"):
|
||||
writer.write(packet)
|
||||
await writer.drain()
|
||||
writer.write(packet)
|
||||
await writer.drain()
|
||||
|
||||
def launch(self, api):
|
||||
async def _start_all():
|
||||
|
||||
@@ -30,6 +30,27 @@ class AuthProcessors(BaseProcessor):
|
||||
self.server_config = OnemeConfig().SERVER_CONFIG
|
||||
self.telegram_bot = telegram_bot
|
||||
|
||||
async def _send_banners(self, writer):
|
||||
"""Функция отправки баннеров клиенту"""
|
||||
payload = {
|
||||
"showTime": 86400000, # Сколько будет показываться баннер, тут сутки в миллисекундах
|
||||
# можно в будущем переделать, и сделать выбор в конфигурации
|
||||
# думаю, было бы прикольно
|
||||
"updateTime": int(time.time() * 1000),
|
||||
"banners": [
|
||||
# TODO: разобраться как работают баннеры и их реализовать
|
||||
# думаю админам инстансов было бы прикольно, и нам
|
||||
]
|
||||
}
|
||||
|
||||
# Собираем пакет
|
||||
packet = self.proto.pack_packet(
|
||||
cmd=0, opcode=self.opcodes.NOTIF_BANNERS, payload=payload
|
||||
)
|
||||
|
||||
# Отправляет
|
||||
await self._send(writer, packet)
|
||||
|
||||
async def auth_request(self, payload, seq, writer):
|
||||
"""Обработчик запроса кода"""
|
||||
try:
|
||||
@@ -356,12 +377,11 @@ class AuthProcessors(BaseProcessor):
|
||||
await cursor.execute(
|
||||
"""
|
||||
INSERT INTO user_data
|
||||
(phone, contacts, folders, user_config, chat_config)
|
||||
VALUES (%s, %s, %s, %s, %s)
|
||||
(phone, folders, user_config, chat_config)
|
||||
VALUES (%s, %s, %s, %s)
|
||||
""",
|
||||
(
|
||||
phone,
|
||||
json.dumps([]),
|
||||
json.dumps(self.static.USER_FOLDERS),
|
||||
json.dumps(self.static.USER_SETTINGS),
|
||||
json.dumps({}),
|
||||
@@ -506,17 +526,23 @@ class AuthProcessors(BaseProcessor):
|
||||
username=user.get("username"),
|
||||
)
|
||||
|
||||
# Генерируем список чатов
|
||||
chats = await self.tools.generate_chats(
|
||||
chats, self.db_pool, user.get("id"), protocol_type=self.type
|
||||
)
|
||||
|
||||
# Генерируем список контактов
|
||||
contacts = await self.tools.collect_user_contacts(
|
||||
user.get("id"), self.db_pool, self.config.avatar_base_url
|
||||
)
|
||||
|
||||
# Формируем данные пакета
|
||||
payload = {
|
||||
"profile": profile,
|
||||
"chats": chats,
|
||||
"chatMarker": 0,
|
||||
"messages": {},
|
||||
"contacts": [],
|
||||
"contacts": contacts,
|
||||
"presence": {},
|
||||
"config": {
|
||||
"server": self.server_config,
|
||||
@@ -532,8 +558,16 @@ class AuthProcessors(BaseProcessor):
|
||||
cmd=self.proto.CMD_OK, seq=seq, opcode=self.opcodes.LOGIN, payload=payload
|
||||
)
|
||||
|
||||
# print(
|
||||
# json.dumps(payload, indent=4)
|
||||
# )
|
||||
|
||||
# Отправляем
|
||||
await self._send(writer, packet)
|
||||
|
||||
# Отправляем баннеры
|
||||
await self._send_banners(writer)
|
||||
|
||||
return int(user.get("phone")), int(user.get("id")), hashed_token
|
||||
|
||||
async def logout(self, seq, writer, hashedToken):
|
||||
|
||||
@@ -67,7 +67,8 @@ class HistoryProcessors(BaseProcessor):
|
||||
"text": row.get("text"),
|
||||
"attaches": json.loads(row.get("attaches")),
|
||||
"elements": json.loads(row.get("elements")),
|
||||
"reactionInfo": {}
|
||||
"reactionInfo": {},
|
||||
"options": 1,
|
||||
})
|
||||
|
||||
if forward > 0:
|
||||
|
||||
@@ -49,7 +49,8 @@ class MessagesProcessors(BaseProcessor):
|
||||
"eventType": "typing",
|
||||
"chatId": chatId,
|
||||
"type": type,
|
||||
"userId": senderId
|
||||
"userId": senderId,
|
||||
"writer": writer,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from oneme.models import (
|
||||
|
||||
|
||||
class SearchProcessors(BaseProcessor):
|
||||
async def contact_info(self, payload, seq, writer):
|
||||
async def contact_info(self, payload, seq, writer, senderId):
|
||||
"""Поиск пользователей по ID"""
|
||||
# Валидируем данные пакета
|
||||
try:
|
||||
@@ -39,6 +39,16 @@ class SearchProcessors(BaseProcessor):
|
||||
avatar_url = None if not photoId else self.config.avatar_base_url + photoId
|
||||
description = None if not user.get("description") else user.get("description")
|
||||
|
||||
# Получаем данные контакта
|
||||
await cursor.execute(
|
||||
"SELECT * FROM contacts WHERE owner_id = %s AND contact_id = %s",
|
||||
(senderId, contactId),
|
||||
)
|
||||
contact_row = await cursor.fetchone()
|
||||
custom_firstname = contact_row.get("custom_firstname") if contact_row else None
|
||||
custom_lastname = contact_row.get("custom_lastname") if contact_row else None
|
||||
blocked = bool(contact_row.get("is_blocked")) if contact_row else False
|
||||
|
||||
# Генерируем профиль
|
||||
users.append(
|
||||
self.tools.generate_profile(
|
||||
@@ -54,7 +64,10 @@ class SearchProcessors(BaseProcessor):
|
||||
accountStatus=int(user.get("accountstatus")),
|
||||
profileOptions=json.loads(user.get("profileoptions")),
|
||||
includeProfileOptions=False,
|
||||
username=user.get("username")
|
||||
username=user.get("username"),
|
||||
custom_firstname=custom_firstname,
|
||||
custom_lastname=custom_lastname,
|
||||
blocked=blocked,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -119,6 +132,18 @@ class SearchProcessors(BaseProcessor):
|
||||
avatar_url = None if not photoId else self.config.avatar_base_url + photoId
|
||||
description = None if not user.get("description") else user.get("description")
|
||||
|
||||
# Получаем данные контакта
|
||||
async with self.db_pool.acquire() as conn:
|
||||
async with conn.cursor() as cursor:
|
||||
await cursor.execute(
|
||||
"SELECT * FROM contacts WHERE owner_id = %s AND contact_id = %s",
|
||||
(senderId, user.get("id")),
|
||||
)
|
||||
contact_row = await cursor.fetchone()
|
||||
custom_firstname = contact_row.get("custom_firstname") if contact_row else None
|
||||
custom_lastname = contact_row.get("custom_lastname") if contact_row else None
|
||||
blocked = bool(contact_row.get("is_blocked")) if contact_row else False
|
||||
|
||||
# Генерируем профиль
|
||||
profile = self.tools.generate_profile(
|
||||
id=user.get("id"),
|
||||
@@ -133,7 +158,10 @@ class SearchProcessors(BaseProcessor):
|
||||
accountStatus=int(user.get("accountstatus")),
|
||||
profileOptions=json.loads(user.get("profileoptions")),
|
||||
includeProfileOptions=False,
|
||||
username=user.get("username")
|
||||
username=user.get("username"),
|
||||
custom_firstname=custom_firstname,
|
||||
custom_lastname=custom_lastname,
|
||||
blocked=blocked,
|
||||
)
|
||||
|
||||
# Создаем данные пакета
|
||||
|
||||
@@ -250,6 +250,7 @@ class OnemeMobile:
|
||||
payload,
|
||||
seq,
|
||||
writer,
|
||||
userId,
|
||||
)
|
||||
case self.opcodes.COMPLAIN_REASONS_GET:
|
||||
await self.auth_required(
|
||||
|
||||
@@ -224,6 +224,7 @@ class OnemeWS:
|
||||
payload,
|
||||
seq,
|
||||
websocket,
|
||||
userId,
|
||||
)
|
||||
case self.opcodes.COMPLAIN_REASONS_GET:
|
||||
await self.auth_required(
|
||||
|
||||
Reference in New Issue
Block a user