mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
feat: support all chat types in channel discovery and enrich bot messages
Channel Discovery: - Remove channel/supergroup filter from getAccountChats — all chat types (private, groups, Saved Messages, etc.) are now discoverable as sources - Detect and label the self-chat as "Saved Messages" via getMe - Update channel picker dialog to accept any chat type string Bot Rich Messages: - Enhance package send preview with creator, file count, tags, and source channel info in MarkdownV2 caption - Include tags in new_package subscription notifications - Expand getPendingSendRequest to fetch richer package data Performance: - Reviewed pipeline for many-channel load — getChats pagination fix and per-channel getChat pre-load from prior commit address the main concerns - Channels with no new messages skip in 2-3 API calls Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -150,6 +150,7 @@ export async function createPackageWithFiles(input: CreatePackageInput) {
|
||||
packageId: pkg.id,
|
||||
fileName: input.fileName,
|
||||
creator: input.creator ?? null,
|
||||
tags: input.tags ?? [],
|
||||
})
|
||||
);
|
||||
} catch {
|
||||
|
||||
@@ -16,13 +16,24 @@ export interface TelegramChatInfo {
|
||||
/**
|
||||
* Fetch all chats the account is a member of.
|
||||
* Uses TDLib's getChats to load the chat list, then getChat for details.
|
||||
* Filters to channels and supergroups only (groups/privates are not useful for ingestion).
|
||||
* Returns ALL chat types: channels, supergroups, groups, private chats,
|
||||
* and the special "Saved Messages" (self) chat.
|
||||
*/
|
||||
export async function getAccountChats(
|
||||
client: Client
|
||||
): Promise<TelegramChatInfo[]> {
|
||||
const chats: TelegramChatInfo[] = [];
|
||||
|
||||
// Get the current user's ID so we can label Saved Messages
|
||||
let selfUserId: number | null = null;
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const me = (await client.invoke({ _: "getMe" })) as any;
|
||||
selfUserId = me.id;
|
||||
} catch {
|
||||
log.warn("Failed to get current user via getMe");
|
||||
}
|
||||
|
||||
// Load ALL chats from the main list by paginating getChats.
|
||||
// TDLib's getChats returns batches — keep calling until it returns
|
||||
// an empty list, which signals all chats have been loaded.
|
||||
@@ -56,6 +67,7 @@ export async function getAccountChats(
|
||||
const chatType = chat.type?._;
|
||||
let type: TelegramChatInfo["type"] = "other";
|
||||
let isForum = false;
|
||||
let title = chat.title ?? `Chat ${chatId}`;
|
||||
|
||||
if (chatType === "chatTypeSupergroup") {
|
||||
// Get supergroup details to check if it's a channel or group
|
||||
@@ -78,17 +90,18 @@ export async function getAccountChats(
|
||||
type = "group";
|
||||
} else if (chatType === "chatTypePrivate" || chatType === "chatTypeSecret") {
|
||||
type = "private";
|
||||
// Label the self-chat as "Saved Messages"
|
||||
if (selfUserId !== null && chat.type?.user_id === selfUserId) {
|
||||
title = "Saved Messages";
|
||||
}
|
||||
}
|
||||
|
||||
// Only include channels and supergroups
|
||||
if (type === "channel" || type === "supergroup") {
|
||||
chats.push({
|
||||
chatId: BigInt(chatId),
|
||||
title: chat.title ?? `Chat ${chatId}`,
|
||||
type,
|
||||
isForum,
|
||||
});
|
||||
}
|
||||
chats.push({
|
||||
chatId: BigInt(chatId),
|
||||
title,
|
||||
type,
|
||||
isForum,
|
||||
});
|
||||
} catch (err) {
|
||||
log.warn({ chatId, err }, "Failed to get chat details, skipping");
|
||||
}
|
||||
@@ -99,7 +112,7 @@ export async function getAccountChats(
|
||||
|
||||
log.info(
|
||||
{ total: chats.length },
|
||||
"Fetched channels/supergroups from Telegram"
|
||||
"Fetched all chats from Telegram"
|
||||
);
|
||||
|
||||
return chats;
|
||||
|
||||
Reference in New Issue
Block a user