Compare commits
5 Commits
ef512b060f
...
5fcc56950f
| Author | SHA1 | Date |
|---|---|---|
|
|
5fcc56950f | |
|
|
a8732b5d7f | |
|
|
aa6411b75d | |
|
|
f2e7e37592 | |
|
|
8d7a1dacb5 |
|
|
@ -108,15 +108,17 @@ class Tools:
|
|||
"lastDelayedUpdateTime": 0,
|
||||
"lastFireDelayedErrorTime": 0,
|
||||
"created": 1,
|
||||
"cid": id,
|
||||
"prevMessageId": prevMessageId,
|
||||
"joinTime": 1,
|
||||
"modified": lastEventTime
|
||||
"modified": lastEventTime,
|
||||
|
||||
}
|
||||
|
||||
# Возвращаем
|
||||
return result
|
||||
|
||||
async def generate_chats(self, chatIds, db_pool, senderId):
|
||||
async def generate_chats(self, chatIds, db_pool, senderId, include_favourites=True):
|
||||
"""Генерирует чаты для отдачи клиенту"""
|
||||
# Готовый список с чатами
|
||||
chats = []
|
||||
|
|
@ -156,34 +158,35 @@ class Tools:
|
|||
)
|
||||
)
|
||||
|
||||
# Получаем последнее сообщение из избранного
|
||||
message, messageTime = await self.get_last_message(
|
||||
senderId, db_pool
|
||||
)
|
||||
|
||||
# ID избранного
|
||||
chatId = senderId ^ senderId
|
||||
|
||||
# Получаем последнюю активность участника (отправителя) в избранном
|
||||
participants = await self.get_participant_last_activity(
|
||||
senderId, [senderId], db_pool
|
||||
)
|
||||
|
||||
# Получаем ID предыдущего сообщения для избранного (чат ID = senderId)
|
||||
prevMessageId = await self.get_previous_message_id(senderId, db_pool)
|
||||
|
||||
# Хардкодим в лист чатов избранное
|
||||
chats.append(
|
||||
self.generate_chat(
|
||||
chatId,
|
||||
senderId,
|
||||
"DIALOG",
|
||||
participants,
|
||||
message,
|
||||
messageTime,
|
||||
prevMessageId
|
||||
if include_favourites == True:
|
||||
# Получаем последнее сообщение из избранного
|
||||
message, messageTime = await self.get_last_message(
|
||||
senderId, db_pool
|
||||
)
|
||||
|
||||
# ID избранного
|
||||
chatId = senderId ^ senderId
|
||||
|
||||
# Получаем последнюю активность участника (отправителя) в избранном
|
||||
participants = await self.get_participant_last_activity(
|
||||
senderId, [senderId], db_pool
|
||||
)
|
||||
|
||||
# Получаем ID предыдущего сообщения для избранного (чат ID = senderId)
|
||||
prevMessageId = await self.get_previous_message_id(senderId, db_pool)
|
||||
|
||||
# Хардкодим в лист чатов избранное
|
||||
chats.append(
|
||||
self.generate_chat(
|
||||
chatId,
|
||||
senderId,
|
||||
"DIALOG",
|
||||
participants,
|
||||
message,
|
||||
messageTime,
|
||||
prevMessageId
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return chats
|
||||
|
||||
|
|
|
|||
|
|
@ -71,8 +71,9 @@ class OnemeMobileController(ControllerBase):
|
|||
)
|
||||
|
||||
# Отправляем пакет
|
||||
writer.write(packet)
|
||||
await writer.drain()
|
||||
if writer != eventData.get("writer"):
|
||||
writer.write(packet)
|
||||
await writer.drain()
|
||||
|
||||
def launch(self, api):
|
||||
async def _start_all():
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ class UserAgentModel(pydantic.BaseModel):
|
|||
pushDeviceType: str
|
||||
arch: str = None
|
||||
locale: str
|
||||
buildNumber: int
|
||||
buildNumber: int = None
|
||||
deviceName: str
|
||||
deviceLocale: str
|
||||
|
||||
class HelloPayloadModel(pydantic.BaseModel):
|
||||
clientSessionId: int
|
||||
clientSessionId: int = None
|
||||
mt_instanceid: str = None
|
||||
userAgent: UserAgentModel
|
||||
deviceId: str
|
||||
|
|
|
|||
|
|
@ -525,10 +525,6 @@ class Processors:
|
|||
"time": int(time.time() * 1000)
|
||||
}
|
||||
|
||||
print(
|
||||
json.dumps(payload, indent=4)
|
||||
)
|
||||
|
||||
# Собираем пакет
|
||||
packet = self.proto.pack_packet(
|
||||
cmd=self.proto.CMD_OK, seq=seq, opcode=self.opcodes.LOGIN, payload=payload
|
||||
|
|
@ -692,7 +688,8 @@ class Processors:
|
|||
"chatId": 0 if chatId == senderId else chatId,
|
||||
"message": bodyMessage,
|
||||
"prevMessageId": lastMessageId,
|
||||
"time": messageTime
|
||||
"time": messageTime,
|
||||
"writer": writer
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -837,7 +834,7 @@ class Processors:
|
|||
|
||||
# Создаем пакет
|
||||
response = self.proto.pack_packet(
|
||||
seq=seq, opcode=self.opcodes.CONTACT_INFO, payload=payload
|
||||
cmd=self.proto.CMD_OK, seq=seq, opcode=self.opcodes.CONTACT_INFO, payload=payload
|
||||
)
|
||||
|
||||
# Отправляем
|
||||
|
|
@ -1263,7 +1260,8 @@ class Processors:
|
|||
user.get('id'),
|
||||
{
|
||||
"eventType": "profile_updated",
|
||||
"profile": profile
|
||||
"profile": profile,
|
||||
"writer": writer
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,572 @@
|
|||
class TTConfig:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
SERVER_CONFIG = {
|
||||
"a-2g": 8,
|
||||
"a-3g": 24,
|
||||
"a-constraints": {
|
||||
"googNoiseSuppression": "true",
|
||||
"googHighpassFilter": "false",
|
||||
"googTypingNoiseDetection": "false",
|
||||
"googAudioNetworkAdaptorConfig": "ChyyARkNCtcjPBUK1yM8GKjDASCw6gEomHUwoJwBCgfKAQQIABAACgvCAQgIqMMBELiRAgosqgEpChEIuBcVzcxMPhjogQIlCtejOxIRCOgHFc3MTD4YsOoBJQrXozsYyAEKC7oBCAiw6gEQoJwB"
|
||||
},
|
||||
"a-lte": 24,
|
||||
"a-wifi": 34,
|
||||
"account-removal-enabled": False,
|
||||
"animated-emojis": {
|
||||
"❤️": {
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/03.json"
|
||||
},
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/04.json"
|
||||
}
|
||||
},
|
||||
"👍": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-29lottie/e/16.json"
|
||||
},
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/01_m.json"
|
||||
}
|
||||
},
|
||||
"👎": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/17.json"
|
||||
},
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/02.json"
|
||||
}
|
||||
},
|
||||
"🙏": {
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/04.json"
|
||||
},
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-29lottie/e/30_ng.json"
|
||||
}
|
||||
},
|
||||
"😘": {
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/05.json"
|
||||
},
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/03.json"
|
||||
}
|
||||
},
|
||||
"🔥": {
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/06.json"
|
||||
},
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/10.json"
|
||||
}
|
||||
},
|
||||
"😂": {
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/07.json"
|
||||
}
|
||||
},
|
||||
"👏": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/56.json"
|
||||
}
|
||||
},
|
||||
"😮": {
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/09.json"
|
||||
}
|
||||
},
|
||||
"💋": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/13_v02.json"
|
||||
},
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-01-18lottie/r/kissing2.json"
|
||||
}
|
||||
},
|
||||
"🥂": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/20.json"
|
||||
},
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/20.json"
|
||||
}
|
||||
},
|
||||
"😳": {
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/09.json"
|
||||
},
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/02.json"
|
||||
}
|
||||
},
|
||||
"😔": {
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/r/11.json"
|
||||
},
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/05.json"
|
||||
}
|
||||
},
|
||||
"😍": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/07.json"
|
||||
}
|
||||
},
|
||||
"😯": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/08.json"
|
||||
}
|
||||
},
|
||||
"😉": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/09.json"
|
||||
}
|
||||
},
|
||||
"🌺": {
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-03-06lottie/flower.json"
|
||||
},
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/11.json"
|
||||
}
|
||||
},
|
||||
"🎂": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/14.json"
|
||||
}
|
||||
},
|
||||
"💩": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/15.json"
|
||||
},
|
||||
"reactionAction": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-01-18lottie/r/shit_1.json"
|
||||
}
|
||||
},
|
||||
"🐰": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/19.json"
|
||||
}
|
||||
},
|
||||
"🎅": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/21.json"
|
||||
}
|
||||
},
|
||||
"🎄": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/23.json"
|
||||
}
|
||||
},
|
||||
"🎆": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/22.json"
|
||||
}
|
||||
},
|
||||
"❄️": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/25.json"
|
||||
}
|
||||
},
|
||||
"🎉": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-28lottie/e/12.json"
|
||||
}
|
||||
},
|
||||
"🥗": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2022-12-29lottie/e/28.json"
|
||||
}
|
||||
},
|
||||
"🧡": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/31.json"
|
||||
}
|
||||
},
|
||||
"💔": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/32.json"
|
||||
}
|
||||
},
|
||||
"🎁": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/34.json"
|
||||
}
|
||||
},
|
||||
"🌹": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/35.json"
|
||||
}
|
||||
},
|
||||
"🌸": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/36.json"
|
||||
}
|
||||
},
|
||||
"🍒": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/37.json"
|
||||
}
|
||||
},
|
||||
"🥕": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/39.json"
|
||||
}
|
||||
},
|
||||
"🍑": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/40.json"
|
||||
}
|
||||
},
|
||||
"🍋": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/41.json"
|
||||
}
|
||||
},
|
||||
"🍃": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/42.json"
|
||||
}
|
||||
},
|
||||
"😺": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/43.json"
|
||||
}
|
||||
},
|
||||
"🐶": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/44.json"
|
||||
}
|
||||
},
|
||||
"🐽": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-07-20animojie/45.json"
|
||||
}
|
||||
},
|
||||
"💐": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/46.json"
|
||||
}
|
||||
},
|
||||
"🎈": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/47.json"
|
||||
}
|
||||
},
|
||||
"🍾": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/48.json"
|
||||
}
|
||||
},
|
||||
"⚡": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/49.json"
|
||||
}
|
||||
},
|
||||
"⭐": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/50.json"
|
||||
}
|
||||
},
|
||||
"✨": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/51.json"
|
||||
}
|
||||
},
|
||||
"💃": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/52.json"
|
||||
}
|
||||
},
|
||||
"☀️": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/53.json"
|
||||
}
|
||||
},
|
||||
"👋": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/54.json"
|
||||
}
|
||||
},
|
||||
"☕": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/57.json"
|
||||
}
|
||||
},
|
||||
"🙂": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/58.json"
|
||||
}
|
||||
},
|
||||
"🤩": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-15animoji/59.json"
|
||||
}
|
||||
},
|
||||
"😇": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/60.json"
|
||||
}
|
||||
},
|
||||
"😎": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/61.json"
|
||||
}
|
||||
},
|
||||
"🍎": {
|
||||
"emoji": {
|
||||
"url": "https://st.okcdn.ru/static/messages/2023-08-14animoji/62.json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"animated-emojis-limits": {
|
||||
"low": 5,
|
||||
"average": 10,
|
||||
"high": 15
|
||||
},
|
||||
"animated-emojis-places": [
|
||||
"MESSAGE_NORMAL_TEXT",
|
||||
"MESSAGE_BIG_EMOJI_TEXT",
|
||||
"MESSAGE_INPUT",
|
||||
"STICKERS_KEYBOARD",
|
||||
"CHATS_LIST"
|
||||
],
|
||||
"attachment-popup-click": False,
|
||||
"audio-transcription-enabled": True,
|
||||
"audio-transcription-locales": [
|
||||
"ru"
|
||||
],
|
||||
"change-self-readmark-on-msg-send": False,
|
||||
"chat-bg": False,
|
||||
"chat-cancel-top-menu-enabled": False,
|
||||
"chat-filter": False,
|
||||
"chat-info-full-list-enabled": False,
|
||||
"chat-preview-enabled": False,
|
||||
"chats-edit-enabled": False,
|
||||
"chats-folder-enabled": True,
|
||||
"chats-list-promo-link-enabled": False,
|
||||
"chats-page-size": 50,
|
||||
"chats-preload-period": 15,
|
||||
"close-keyboard-on-scroll": True,
|
||||
"common-chats-enabled": True,
|
||||
"compact-mode-enabled": False,
|
||||
"congrats-banner-enabled-mob": False,
|
||||
"congrats-banner-enabled-web": True,
|
||||
"contact-verify-enabled": False,
|
||||
"contacts-send": False,
|
||||
"contacts-sort-refresh": 259200,
|
||||
"copy-id-btn": False,
|
||||
"debug-mode": 1,
|
||||
"delayed-messages": False,
|
||||
"delayed-messages-enabled": False,
|
||||
"detect-share-when-send-message": True,
|
||||
"dialog-priority": False,
|
||||
"disconnect-timeout": 300,
|
||||
"drafts-sync-enabled": True,
|
||||
"edit-timeout": 86400,
|
||||
"expandable-appbar-enabled": True,
|
||||
"experimental": False,
|
||||
"fast-chat-actions-enabled": False,
|
||||
"file-upload-enabled": True,
|
||||
"file-upload-max-size": 2147483648,
|
||||
"file-upload-unsupported-types": [
|
||||
"exe"
|
||||
],
|
||||
"gce": True,
|
||||
"hashtags-enabled": True,
|
||||
"html-paste": False,
|
||||
"http-logs-enabled": False,
|
||||
"image-height": 1680,
|
||||
"image-quality": 0.800000011920929,
|
||||
"image-size": 40000000,
|
||||
"image-width": 1680,
|
||||
"invite-header": "Приглашение в ТамТам",
|
||||
"invite-link": "https://tt.me/starwear",
|
||||
"invite-long": "Я общаюсь в ТамТам, присоединяйся https://tt.me/starwear",
|
||||
"invite-short": "Привет! Ставь ТамТам! Жду ответа! https://tt.me/starwear",
|
||||
"keep-connection": 2,
|
||||
"l10n": False,
|
||||
"live-location-enabled": True,
|
||||
"location-enabled": True,
|
||||
"logs-enabled": True,
|
||||
"markdown-enabled": True,
|
||||
"markdown-menu": 0,
|
||||
"markdown-miui-enabled": True,
|
||||
"max-audio-length": 3600,
|
||||
"max-cname-length": 200,
|
||||
"max-description-length": 400,
|
||||
"max-favorite-chats": 5,
|
||||
"max-favorite-sticker-sets": 100,
|
||||
"max-favorite-stickers": 100,
|
||||
"max-msg-length": 4000,
|
||||
"max-participants": 20000,
|
||||
"max-readmarks": 300,
|
||||
"max-theme-length": 200,
|
||||
"max-video-duration-download": 1200,
|
||||
"mediabar-scroll-layout": True,
|
||||
"mentions-enabled": True,
|
||||
"mentions_entity_names_limit": 3,
|
||||
"min-image-side-size": 64,
|
||||
"moderated-groups": False,
|
||||
"moderated-groups-filter": False,
|
||||
"multiselect": True,
|
||||
"music-files-enabled": False,
|
||||
"muted-chat-call-enabled": False,
|
||||
"nearby-timeouts": {
|
||||
"enabled": "True",
|
||||
"LaunchBroadcastTime": "0",
|
||||
"LaunchBroadcastTimeLimit": "300",
|
||||
"ContactsScreenBroadcastTime": "10",
|
||||
"ChatSearchScreenBroadcastTime": "10",
|
||||
"RecentContactTime": "300"
|
||||
},
|
||||
"new-chats-searching": True,
|
||||
"new-chats-ui": True,
|
||||
"new-fcm-push": True,
|
||||
"notif-images": True,
|
||||
"offline-icon": False,
|
||||
"often-chats": False,
|
||||
"ok-avatar-icon": False,
|
||||
"ok-profile-unbind-enabled": True,
|
||||
"ok-tt-chat-separation": True,
|
||||
"one-chat-enabled": False,
|
||||
"one-chat-new-panel-sticker": False,
|
||||
"peer-connection-params": {
|
||||
"ebv": [
|
||||
"xiaomi",
|
||||
"huawei"
|
||||
],
|
||||
"ebm": [
|
||||
"oneplus a5010"
|
||||
]
|
||||
},
|
||||
"phone-bind-enabled": True,
|
||||
"phone-layer-enabled": True,
|
||||
"play-background-listen-to-end": False,
|
||||
"play-next-audio": False,
|
||||
"plus-menu-enabled": False,
|
||||
"prefs": 1,
|
||||
"profile-autodelete-enabled": True,
|
||||
"profiling-enabled": False,
|
||||
"progress-diff-for-notify": 1,
|
||||
"promo-contact-id": 0,
|
||||
"promo-recent-contacts": True,
|
||||
"promo_contact_label": "Белый Маг",
|
||||
"proxy": "msgproxy.okcdn.ru",
|
||||
"proxy-domains": [
|
||||
"okcdn.ru",
|
||||
"mycdn.me",
|
||||
"ok.ru",
|
||||
"odnoklassniki.ru",
|
||||
"odkl.ru",
|
||||
"vk.com",
|
||||
"userapi.com",
|
||||
"vkuser.net",
|
||||
"vkusercdn.ru"
|
||||
],
|
||||
"proxy-exclude": [
|
||||
"r.mradx.net",
|
||||
"ad.mail.ru"
|
||||
],
|
||||
"proxy-rotation": True,
|
||||
"push-alert-timeout": 604800,
|
||||
"push-tracking-enabled": True,
|
||||
"quick-forward-cases": [],
|
||||
"react-permission": 2,
|
||||
"reactions-enabled": True,
|
||||
"reactions-max": 3,
|
||||
"reactions-menu": [
|
||||
"👍",
|
||||
"❤️",
|
||||
"💩",
|
||||
"😂",
|
||||
"🔥",
|
||||
"🙏",
|
||||
"👎",
|
||||
"😮"
|
||||
],
|
||||
"readmark-enabled-delay-ms": 400,
|
||||
"remove-profile-enable": True,
|
||||
"remove-user-msg-del": True,
|
||||
"retry-sig-count": 5,
|
||||
"retry-sig-delay": 4,
|
||||
"screen-share-enabled": False,
|
||||
"screen-sharing-enabled": True,
|
||||
"send-media-from-system-keyboard": False,
|
||||
"send-side-bwe": True,
|
||||
"send-system-keyboard-png-as-stickers": True,
|
||||
"set-unread-timeout": 31536000,
|
||||
"settings-use": False,
|
||||
"show-invited-by": True,
|
||||
"show-rm-limits": [
|
||||
15,
|
||||
100
|
||||
],
|
||||
"show-snow": True,
|
||||
"sticker-gif-enabled": True,
|
||||
"sticker-sections": [
|
||||
"TOP",
|
||||
"NEW"
|
||||
],
|
||||
"sticker-sets-links-enabled": True,
|
||||
"sticker-suggest-disabled": False,
|
||||
"stickers-suggestion": [
|
||||
"RECENT",
|
||||
"NEW",
|
||||
"TOP"
|
||||
],
|
||||
"stickers-suggestion-keywords-inline": False,
|
||||
"support-account": "tt.me/support",
|
||||
"support-button-enable": False,
|
||||
"t-ice-reconnect": 15,
|
||||
"t-incoming-call": 40,
|
||||
"t-start-connect": 20,
|
||||
"tam-emoji-font-url": "https://st.okcdn.ru/static/messages/2022-08-25noto/TamNotoColorEmojiCompat.ttf",
|
||||
"tcp-candidates": False,
|
||||
"tracer-crash-report-enabled": True,
|
||||
"tracer-crash-report-host": "https://api-hprof.odkl.ru",
|
||||
"tracer-crash-send-asap-enabled": True,
|
||||
"tracer-crash-send-logs-enabled": True,
|
||||
"tracer-crash-send-threads-dump-enabled": True,
|
||||
"tracer-disk-overflow-report-threshold": 3000000000,
|
||||
"tracer-disk-usage-probability": 500,
|
||||
"tracer-enabled": True,
|
||||
"tracer-host": "https://api-hprof.odkl.ru",
|
||||
"tracer-hprof-probability": -1,
|
||||
"tracer-sampled-conditions": "tag=app_start_ui_freeze_2k;probability=100000;startEvent=app_first_activity_created;interestingEvent=app_freeze;interestingDuration=2000",
|
||||
"tracer-sampled-duration": 20000,
|
||||
"tracer-systrace-duration": 20000,
|
||||
"tracer-systrace-interesting-duration": 10000,
|
||||
"tracer-systrace-probability": 10000,
|
||||
"unknown-person-attention": True,
|
||||
"unread-filter-enabled": False,
|
||||
"update-non-contacts": 10,
|
||||
"use-congrats-list-in-mass-sending": False,
|
||||
"use-new-message-rendering": True,
|
||||
"v-2g": 128,
|
||||
"v-3g": 1024,
|
||||
"v-fps": 24,
|
||||
"v-fps-v8": 20,
|
||||
"v-height": 720,
|
||||
"v-height-vp8": 480,
|
||||
"v-lte": 1024,
|
||||
"v-vp8": 512,
|
||||
"v-width": 1280,
|
||||
"v-width-vp8": 640,
|
||||
"v-wifi": 2048,
|
||||
"vce": True,
|
||||
"video-attach-download-enabled": False,
|
||||
"video-auto-compress-enabled": True,
|
||||
"video-messages": False,
|
||||
"video-params": True,
|
||||
"video-preview": "480x270",
|
||||
"wakelock-on-push": False,
|
||||
"wm-analytics-enabled": True,
|
||||
"wm-workers-limit": 80,
|
||||
"iceServers": [],
|
||||
"has-phone": True,
|
||||
"promo-constructors": []
|
||||
}
|
||||
|
|
@ -31,4 +31,10 @@ class FinalAuthPayloadModel(pydantic.BaseModel):
|
|||
|
||||
class LoginPayloadModel(pydantic.BaseModel):
|
||||
interactive: bool
|
||||
token: str
|
||||
token: str
|
||||
|
||||
class SearchUsersPayloadModel(pydantic.BaseModel):
|
||||
contactIds: list
|
||||
|
||||
class PingPayloadModel(pydantic.BaseModel):
|
||||
interactive: bool
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
from .main import MainProcessors
|
||||
from .auth import AuthProcessors
|
||||
from .search import SearchProcessors
|
||||
|
||||
class Processors(MainProcessors, AuthProcessors):
|
||||
class Processors(MainProcessors, AuthProcessors, SearchProcessors):
|
||||
pass
|
||||
|
|
@ -10,8 +10,13 @@ from tamtam.models import (
|
|||
FinalAuthPayloadModel,
|
||||
LoginPayloadModel,
|
||||
)
|
||||
from tamtam.config import TTConfig
|
||||
|
||||
class AuthProcessors(BaseProcessor):
|
||||
def __init__(self, db_pool=None, clients=None, send_event=None, type="socket"):
|
||||
super().__init__(db_pool, clients, send_event, type)
|
||||
self.server_config = TTConfig().SERVER_CONFIG
|
||||
|
||||
async def auth_request(self, payload, seq, writer):
|
||||
"""Обработчик запроса кода"""
|
||||
# Валидируем данные пакета
|
||||
|
|
@ -254,6 +259,9 @@ class AuthProcessors(BaseProcessor):
|
|||
self.error_types.INVALID_PAYLOAD, writer)
|
||||
return
|
||||
|
||||
# Чаты, где состоит пользователь
|
||||
chats = []
|
||||
|
||||
# Получаем данные из пакета
|
||||
token = payload.get("token")
|
||||
|
||||
|
|
@ -280,6 +288,18 @@ class AuthProcessors(BaseProcessor):
|
|||
await cursor.execute("SELECT * FROM user_data WHERE phone = %s", (token_data.get("phone"),))
|
||||
user_data = await cursor.fetchone()
|
||||
|
||||
# Ищем все чаты, где состоит пользователь
|
||||
await cursor.execute(
|
||||
"SELECT * FROM chat_participants WHERE user_id = %s",
|
||||
(user.get('id'))
|
||||
)
|
||||
user_chats = await cursor.fetchall()
|
||||
|
||||
for chat in user_chats:
|
||||
chats.append(
|
||||
chat.get("chat_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)
|
||||
|
|
@ -300,8 +320,8 @@ class AuthProcessors(BaseProcessor):
|
|||
)
|
||||
|
||||
chats = await self.tools.generate_chats(
|
||||
json.loads(user_data.get("chats")),
|
||||
self.db_pool, user.get("id")
|
||||
chats, self.db_pool, user.get("id"),
|
||||
include_favourites=False
|
||||
)
|
||||
|
||||
# Формируем данные пакета
|
||||
|
|
@ -313,8 +333,8 @@ class AuthProcessors(BaseProcessor):
|
|||
"contacts": [],
|
||||
"presence": {},
|
||||
"config": {
|
||||
"hash": "0",
|
||||
"server": {},
|
||||
"hash": "e5903aa8-0000000000000000-80000106-0000000000000001-00000001-0000000000000000-00000000-2-00000001-0000019c9559d057",
|
||||
"server": self.server_config,
|
||||
"user": json.loads(user_data.get("user_config")),
|
||||
"chatFolders": {
|
||||
"FOLDERS": [],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import pydantic
|
||||
from classes.baseprocessor import BaseProcessor
|
||||
from tamtam.models import HelloPayloadModel
|
||||
from tamtam.models import HelloPayloadModel, PingPayloadModel
|
||||
|
||||
class MainProcessors(BaseProcessor):
|
||||
async def session_init(self, payload, seq, writer):
|
||||
|
|
@ -7,7 +8,7 @@ class MainProcessors(BaseProcessor):
|
|||
# Валидируем данные пакета
|
||||
try:
|
||||
HelloPayloadModel.model_validate(payload)
|
||||
except Exception as e:
|
||||
except pydantic.ValidationError as error:
|
||||
await self._send_error(seq, self.opcodes.SESSION_INIT,
|
||||
self.error_types.INVALID_PAYLOAD, writer)
|
||||
return None, None
|
||||
|
|
@ -33,4 +34,32 @@ class MainProcessors(BaseProcessor):
|
|||
|
||||
# Отправляем
|
||||
await self._send(writer, packet)
|
||||
return device_type, device_name
|
||||
return device_type, device_name
|
||||
|
||||
async def ping(self, payload, seq, writer):
|
||||
"""Обработчик пинга"""
|
||||
# Валидируем данные пакета
|
||||
try:
|
||||
PingPayloadModel.model_validate(payload)
|
||||
except pydantic.ValidationError as error:
|
||||
self.logger.error(f"Возникли ошибки при валидации пакета: {error}")
|
||||
await self._send_error(seq, self.opcodes.PING, self.error_types.INVALID_PAYLOAD, writer)
|
||||
return
|
||||
|
||||
# Собираем пакет
|
||||
packet = self.proto.pack_packet(
|
||||
cmd=self.proto.CMD_OK, seq=seq, opcode=self.opcodes.PING, payload=None
|
||||
)
|
||||
|
||||
# Отправляем
|
||||
await self._send(writer, packet)
|
||||
|
||||
async def log(self, payload, seq, writer):
|
||||
"""Обработчик лога"""
|
||||
# Собираем пакет
|
||||
packet = self.proto.pack_packet(
|
||||
cmd=self.proto.CMD_OK, seq=seq, opcode=self.opcodes.LOG, payload=None
|
||||
)
|
||||
|
||||
# Отправляем
|
||||
await self._send(writer, packet)
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
import json, pydantic
|
||||
from classes.baseprocessor import BaseProcessor
|
||||
from tamtam.models import SearchUsersPayloadModel
|
||||
|
||||
class SearchProcessors(BaseProcessor):
|
||||
async def contact_info(self, payload, seq, writer):
|
||||
"""Поиск пользователей по ID"""
|
||||
# Валидируем данные пакета
|
||||
try:
|
||||
SearchUsersPayloadModel.model_validate(payload)
|
||||
except pydantic.ValidationError as error:
|
||||
self.logger.error(f"Возникли ошибки при валидации пакета: {error}")
|
||||
await self._send_error(seq, self.opcodes.CONTACT_INFO, self.error_types.INVALID_PAYLOAD, writer)
|
||||
return
|
||||
|
||||
# Итоговый список пользователей
|
||||
users = []
|
||||
|
||||
# ID пользователей, которые нам предстоит найти
|
||||
contactIds = payload.get("contactIds")
|
||||
|
||||
# Ищем пользователей в бд
|
||||
async with self.db_pool.acquire() as conn:
|
||||
async with conn.cursor() as cursor:
|
||||
for contactId in contactIds:
|
||||
await cursor.execute("SELECT * FROM users WHERE id = %s", (contactId,))
|
||||
user = await cursor.fetchone()
|
||||
|
||||
# Если такой пользователь есть, добавляем его в список
|
||||
if user:
|
||||
# Аватарка с биографией
|
||||
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 + photo_id
|
||||
description = None if not user.get("description") else user.get("description")
|
||||
|
||||
# Генерируем профиль
|
||||
users.append(
|
||||
self.tools.generate_profile_tt(
|
||||
id=user.get("id"),
|
||||
phone=int(user.get("phone")),
|
||||
avatarUrl=avatar_url,
|
||||
photoId=photo_id,
|
||||
updateTime=int(user.get("updatetime")),
|
||||
firstName=user.get("firstname"),
|
||||
lastName=user.get("lastname"),
|
||||
options=json.loads(user.get("options")),
|
||||
description=description,
|
||||
username=user.get("username")
|
||||
)
|
||||
)
|
||||
|
||||
# Создаем данные пакета
|
||||
payload = {
|
||||
"contacts": users
|
||||
}
|
||||
|
||||
# Создаем пакет
|
||||
response = self.proto.pack_packet(
|
||||
cmd=self.proto.CMD_OK, seq=seq, opcode=self.opcodes.CONTACT_INFO, payload=payload
|
||||
)
|
||||
|
||||
# Отправляем
|
||||
await self._send(writer, response)
|
||||
|
|
@ -3,6 +3,7 @@ from common.proto_tcp import MobileProto
|
|||
from tamtam.processors import Processors
|
||||
from common.rate_limiter import RateLimiter
|
||||
from common.opcodes import Opcodes
|
||||
from common.tools import Tools
|
||||
|
||||
class TTMobileServer:
|
||||
def __init__(self, host="0.0.0.0", port=443, ssl_context=None, db_pool=None, clients={}, send_event=None):
|
||||
|
|
@ -18,6 +19,7 @@ class TTMobileServer:
|
|||
|
||||
self.proto = MobileProto()
|
||||
self.processors = Processors(db_pool=db_pool, clients=clients, send_event=send_event)
|
||||
self.auth_required = Tools().auth_required
|
||||
|
||||
# rate limiter
|
||||
self.auth_rate_limiter = RateLimiter(max_attempts=5, window_seconds=60)
|
||||
|
|
@ -74,6 +76,10 @@ class TTMobileServer:
|
|||
match opcode:
|
||||
case self.opcodes.SESSION_INIT:
|
||||
deviceType, deviceName = await self.processors.session_init(payload, seq, writer)
|
||||
case self.opcodes.PING:
|
||||
await self.processors.ping(payload, seq, writer)
|
||||
case self.opcodes.LOG:
|
||||
await self.processors.log(payload, seq, writer)
|
||||
case self.opcodes.AUTH_REQUEST:
|
||||
if not self.auth_rate_limiter.is_allowed(address[0]):
|
||||
await self.processors._send_error(seq, self.opcodes.AUTH_REQUEST, self.processors.error_types.RATE_LIMITED, writer)
|
||||
|
|
@ -97,6 +103,10 @@ class TTMobileServer:
|
|||
|
||||
if userPhone:
|
||||
await self._finish_auth(writer, address, userPhone, userId)
|
||||
case self.opcodes.CONTACT_INFO:
|
||||
await self.auth_required(
|
||||
userPhone, self.processors.contact_info, payload, seq, writer
|
||||
)
|
||||
case _:
|
||||
self.logger.warning(f"Неизвестный опкод {opcode}")
|
||||
except Exception as e:
|
||||
|
|
@ -118,7 +128,7 @@ class TTMobileServer:
|
|||
"writer": writer,
|
||||
"ip": addr[0],
|
||||
"port": addr[1],
|
||||
"protocol": "oneme_mobile"
|
||||
"protocol": "tamtam_mobile"
|
||||
}
|
||||
)
|
||||
else:
|
||||
|
|
@ -130,7 +140,7 @@ class TTMobileServer:
|
|||
"writer": writer,
|
||||
"ip": addr[0],
|
||||
"port": addr[1],
|
||||
"protocol": "oneme_mobile"
|
||||
"protocol": "tamtam_mobile"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue