fix: restore get_subs_list_keyboard helper
This commit is contained in:
21
SubMind.py
21
SubMind.py
@@ -263,6 +263,27 @@ def _parse_category_id_from_callback(data: str) -> int | None:
|
|||||||
return int(payload) if payload.isdigit() else None
|
return int(payload) if payload.isdigit() else None
|
||||||
|
|
||||||
|
|
||||||
|
async def get_subs_list_keyboard(user_id: int, category_filter: str = None) -> InlineKeyboardMarkup:
|
||||||
|
with get_db_connection() as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
query, params = "SELECT id, name FROM subscriptions WHERE user_id = ? ", [user_id]
|
||||||
|
if category_filter:
|
||||||
|
query += "AND category = ? "
|
||||||
|
params.append(category_filter)
|
||||||
|
query += "ORDER BY next_due ASC"
|
||||||
|
cursor.execute(query, tuple(params))
|
||||||
|
subs = cursor.fetchall()
|
||||||
|
if not subs:
|
||||||
|
return None
|
||||||
|
buttons = [InlineKeyboardButton(name, callback_data=f'view_{sub_id}') for sub_id, name in subs]
|
||||||
|
keyboard = [buttons[i:i + 2] for i in range(0, len(buttons), 2)]
|
||||||
|
if category_filter:
|
||||||
|
keyboard.append([InlineKeyboardButton("« 返回分类列表", callback_data='list_categories')])
|
||||||
|
else:
|
||||||
|
keyboard.append([InlineKeyboardButton("🗂️ 按分类浏览", callback_data='list_categories')])
|
||||||
|
return InlineKeyboardMarkup(keyboard)
|
||||||
|
|
||||||
|
|
||||||
def _clear_action_state(context: CallbackContext, keys: list[str]):
|
def _clear_action_state(context: CallbackContext, keys: list[str]):
|
||||||
for key in keys:
|
for key in keys:
|
||||||
context.user_data.pop(key, None)
|
context.user_data.pop(key, None)
|
||||||
|
|||||||
Reference in New Issue
Block a user