Skip to content

Commit f96d537

Browse files
committed
fix(poke): fetch CHATS_FETCH_LIMIT dialogs before filtering to private
- /poke used get_private_dialogs(limit=16) which fetched only 16 dialogs of ALL types, then filtered to private — groups/channels could fill all 16 slots leaving zero private chats - Add CHATS_FETCH_LIMIT = ACTIVE_CHATS_LIMIT * 10 (160) to config.py - /poke now fetches 160 dialogs then slices to 16 after filtering - Replace hardcoded ACTIVE_CHATS_LIMIT * 10 in styles_handler.py
1 parent 481121c commit f96d537

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def style_display_name(style: str) -> str:
155155

156156
# Количество чатов в /styles для отображения
157157
ACTIVE_CHATS_LIMIT = 16
158+
CHATS_FETCH_LIMIT = ACTIVE_CHATS_LIMIT * 10 # Запрос с запасом: группы/каналы фильтруются
158159

159160
# ====== ЧАСОВОЙ ПОЯС ======
160161
# 30 популярных UTC-смещений (часы); дробные: +3.5 Иран, +4.5 Афганистан,

handlers/poke_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from config import (
1010
ACTIVE_CHATS_LIMIT,
11+
CHATS_FETCH_LIMIT,
1112
DEBUG_PRINT,
1213
IGNORED_CHAT_IDS,
1314
POKE_FOLLOW_UP_TIMEOUT,
@@ -55,7 +56,8 @@ async def on_poke(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
5556
print(f"{get_timestamp()} [POKE] /poke from user {u.id}")
5657

5758
# Получаем список чатов
58-
chat_ids = await pyrogram_client.get_private_dialogs(u.id, limit=ACTIVE_CHATS_LIMIT)
59+
chat_ids = await pyrogram_client.get_private_dialogs(u.id, limit=CHATS_FETCH_LIMIT)
60+
chat_ids = chat_ids[:ACTIVE_CHATS_LIMIT]
5961

6062
user = await get_user(u.id)
6163
user_settings = (user or {}).get("settings") or {}

handlers/styles_handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from config import (
1010
AUTO_REPLY_OPTIONS,
1111
ACTIVE_CHATS_LIMIT,
12+
CHATS_FETCH_LIMIT,
1213
DEBUG_PRINT,
1314
DEFAULT_STYLE,
1415
STYLE_OPTIONS,
@@ -137,7 +138,7 @@ async def on_chats(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
137138

138139
# Получаем широкий список диалогов для фильтрации
139140
all_dialogs = await pyrogram_client.get_dialog_info(
140-
u.id, limit=ACTIVE_CHATS_LIMIT * 10,
141+
u.id, limit=CHATS_FETCH_LIMIT,
141142
)
142143

143144
dialogs = _get_relevant_dialogs(all_dialogs, user_settings, u.id)
@@ -167,7 +168,7 @@ async def _refresh_keyboard(
167168
dialogs = context.user_data.get("chats_dialogs") or []
168169
if not dialogs:
169170
all_dialogs = await pyrogram_client.get_dialog_info(
170-
u.id, limit=ACTIVE_CHATS_LIMIT * 10,
171+
u.id, limit=CHATS_FETCH_LIMIT,
171172
)
172173
dialogs = _get_relevant_dialogs(all_dialogs, updated_settings, u.id)
173174
else:

0 commit comments

Comments
 (0)