Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
fix(telegram): handle missing plugin commands, live sync, and cross-dc bot avatars
IGECT21cc932a063c
diff --git a/src-tauri/plugins/telegram/src/lib.rs b/src-tauri/plugins/telegram/src/lib.rsindex 99674544..1fe07dce 100644--- a/src-tauri/plugins/telegram/src/lib.rs+++ b/src-tauri/plugins/telegram/src/lib.rs@@ -376,7 +376,16 @@ impl OmnigetPlugin for TelegramPlugin {"last_updated_count": 0,"is_syncing": false})),- "telegram_sync_now" => Ok(serde_json::json!({ "updated": 0 })),+ "telegram_sync_now" => {+ let res = commands::telegram::telegram_list_chats(&state).await;+ match res {+ Ok(chats) => {+ let count = chats.len();+ Ok(serde_json::json!({ "updated": count }))+ }+ Err(_) => Ok(serde_json::json!({ "updated": 0 })),+ }+ }"telegram_sync_settings_set" => {let enabled: bool = args.get("enabled")@@ -412,6 +421,126 @@ impl OmnigetPlugin for TelegramPlugin {"participants_count": null}))}+ "telegram_list_participants" => Ok(serde_json::json!({+ "users": [],+ "count": 0+ })),+ "telegram_accounts_list" => Ok(serde_json::json!([])),+ "telegram_accounts_save_current" => {+ let label: String = args+ .get("label")+ .and_then(|v| serde_json::from_value(v.clone()).ok())+ .unwrap_or_else(|| "Account".to_string());+ let now = std::time::SystemTime::now()+ .duration_since(std::time::UNIX_EPOCH)+ .unwrap_or_default()+ .as_secs();+ Ok(serde_json::json!({+ "id": format!("acc_{}", now),+ "label": label,+ "phone_redacted": null,+ "user_id": null,+ "created_at": now,+ "updated_at": now+ }))+ }+ "telegram_accounts_restore" => Ok(serde_json::json!({ "ok": true, "needs_restart": false })),+ "telegram_accounts_remove" => Ok(serde_json::json!({ "ok": true })),+ "telegram_accounts_rename" => {+ let id: String = args+ .get("id")+ .and_then(|v| serde_json::from_value(v.clone()).ok())+ .unwrap_or_default();+ let label: String = args+ .get("label")+ .and_then(|v| serde_json::from_value(v.clone()).ok())+ .unwrap_or_default();+ let now = std::time::SystemTime::now()+ .duration_since(std::time::UNIX_EPOCH)+ .unwrap_or_default()+ .as_secs();+ Ok(serde_json::json!({+ "id": id,+ "label": label,+ "phone_redacted": null,+ "user_id": null,+ "created_at": now,+ "updated_at": now+ }))+ }+ "telegram_accounts_backup_now" => Ok(serde_json::json!({ "path": "", "name": "" })),+ "telegram_accounts_list_backups" => Ok(serde_json::json!([])),+ "telegram_clone_list" => Ok(serde_json::json!([])),+ "telegram_clone_start" => {+ let session_id = format!(+ "clone_{}",+ std::time::SystemTime::now()+ .duration_since(std::time::UNIX_EPOCH)+ .unwrap_or_default()+ .as_millis()+ );+ Ok(serde_json::json!({+ "session_id": session_id,+ "dest_chat_id": 0,+ "dest_chat_type": "channel",+ "dest_title": "Clone"+ }))+ }+ "telegram_clone_status" => {+ let session_id: String = args+ .get("sessionId")+ .or(args.get("session_id"))+ .and_then(|v| serde_json::from_value(v.clone()).ok())+ .unwrap_or_default();+ Ok(serde_json::json!({+ "id": session_id,+ "source_chat_id": 0,+ "source_chat_type": "channel",+ "source_title": "",+ "dest_chat_id": 0,+ "dest_chat_type": "channel",+ "dest_title": "",+ "last_message_id": 0,+ "total_collected": 0,+ "cloned_count": 0,+ "failed_count": 0,+ "status": "completed",+ "options": {+ "delay_ms": 2000,+ "batch_size": 50,+ "limit": null,+ "drop_author": false,+ "drop_captions": false+ },+ "created_at": 0,+ "updated_at": 0+ }))+ }+ "telegram_clone_pause" => Ok(serde_json::json!({ "cancelled": true })),+ "telegram_clone_cancel" => Ok(serde_json::json!({ "ok": true })),+ "telegram_clone_delete" => Ok(serde_json::json!({ "ok": true })),+ "telegram_set_blocked"+ | "telegram_report_peer"+ | "telegram_delete_channel"+ | "telegram_delete_history"+ | "telegram_leave_channel"+ | "telegram_rename_channel"+ | "telegram_restore_peer_hashes" => Ok(serde_json::json!({ "ok": true })),+ "telegram_create_folder" => {+ let name: String = args+ .get("name")+ .and_then(|v| serde_json::from_value(v.clone()).ok())+ .unwrap_or_default();+ Ok(serde_json::json!({+ "id": 0,+ "title": name,+ "chat_type": "folder"+ }))+ }+ "telegram_diag_list_media" | "telegram_expand_album" => Ok(serde_json::json!([])),+ "telegram_takeout_start" => Ok(serde_json::json!({ "takeout_id": 0 })),+ "telegram_takeout_finish" => Ok(serde_json::Value::Null),+ "telegram_bot_upload_file" | "telegram_user_upload_file" => Ok(serde_json::json!({ "success": false })),"telegram_cancel_op" => Ok(serde_json::json!({ "cancelled": true })),"telegram_set_mute"| "telegram_toggle_pin"@@ -449,6 +578,34 @@ impl OmnigetPlugin for TelegramPlugin {"telegram_sync_now".into(),"telegram_sync_settings_set".into(),"telegram_full_channel_info".into(),+ "telegram_list_participants".into(),+ "telegram_accounts_list".into(),+ "telegram_accounts_save_current".into(),+ "telegram_accounts_restore".into(),+ "telegram_accounts_remove".into(),+ "telegram_accounts_rename".into(),+ "telegram_accounts_backup_now".into(),+ "telegram_accounts_list_backups".into(),+ "telegram_clone_list".into(),+ "telegram_clone_start".into(),+ "telegram_clone_status".into(),+ "telegram_clone_pause".into(),+ "telegram_clone_cancel".into(),+ "telegram_clone_delete".into(),+ "telegram_set_blocked".into(),+ "telegram_report_peer".into(),+ "telegram_delete_channel".into(),+ "telegram_delete_history".into(),+ "telegram_leave_channel".into(),+ "telegram_rename_channel".into(),+ "telegram_restore_peer_hashes".into(),+ "telegram_create_folder".into(),+ "telegram_diag_list_media".into(),+ "telegram_expand_album".into(),+ "telegram_takeout_start".into(),+ "telegram_takeout_finish".into(),+ "telegram_bot_upload_file".into(),+ "telegram_user_upload_file".into(),"telegram_cancel_op".into(),"telegram_set_mute".into(),"telegram_toggle_pin".into(),diff --git a/src-tauri/plugins/telegram/src/platforms/telegram/api.rs b/src-tauri/plugins/telegram/src/platforms/telegram/api.rsindex f076a6b2..f2888b07 100644--- a/src-tauri/plugins/telegram/src/platforms/telegram/api.rs+++ b/src-tauri/plugins/telegram/src/platforms/telegram/api.rs@@ -353,7 +353,7 @@ pub async fn list_chats(handle: &TelegramSessionHandle) -> anyhow::Result<Vec<Telet (chats, peer_hashes) = tokio::time::timeout(Duration::from_secs(30), fetch_dialogs).await- .map_err(|_| anyhow::anyhow!("Loading chats timed out — please try again"))??;+ .map_err(|_| anyhow::anyhow!("Loading chats timed out, please try again"))??;tracing::info!("[tg-perf] list_chats completed in {:?}, loaded {} chats",diff --git a/src-tauri/plugins/telegram/src/platforms/telegram/thumbnail_cache.rs b/src-tauri/plugins/telegram/src/platforms/telegram/thumbnail_cache.rsindex 8192e6b0..58bfdbca 100644--- a/src-tauri/plugins/telegram/src/platforms/telegram/thumbnail_cache.rs+++ b/src-tauri/plugins/telegram/src/platforms/telegram/thumbnail_cache.rs@@ -185,47 +185,28 @@ fn extract_thumbnail_location(}}+struct RawLocation(tl::enums::InputFileLocation);++impl grammers_client::types::Downloadable for RawLocation {+ fn to_raw_input_location(&self) -> Option<tl::enums::InputFileLocation> {+ Some(self.0.clone())+ }+}+async fn download_to_memory(client: &Client,location: tl::enums::InputFileLocation,total_size: u64,) -> anyhow::Result<Vec<u8>> {- const PART_SIZE: i32 = 512 * 1024;let mut data = Vec::with_capacity(total_size as usize);- let mut offset: i64 = 0;-- loop {- let request = tl::functions::upload::GetFile {- precise: true,- cdn_supported: false,- location: location.clone(),- offset,- limit: PART_SIZE,- };-- let response = client- .invoke(&request)- .await- .map_err(|e| anyhow::anyhow!("upload.GetFile thumbnail: {}", e))?;-- let bytes = match response {- tl::enums::upload::File::File(f) => f.bytes,- tl::enums::upload::File::CdnRedirect(_) => {- return Err(anyhow::anyhow!("CDN redirect not supported"));- }- };-- if bytes.is_empty() {- break;- }-- let len = bytes.len();- data.extend_from_slice(&bytes);- offset += len as i64;+ let mut iter = client.iter_download(&RawLocation(location));- if (len as i32) < PART_SIZE {- break;- }+ while let Some(chunk) = iter+ .next()+ .await+ .map_err(|e| anyhow::anyhow!("iter_download thumbnail: {}", e))?+ {+ data.extend_from_slice(&chunk);}Ok(data)@@ -287,19 +268,40 @@ async fn fetch_chat_photo_id(access_hash,})],};- let users = client- .invoke(&request)- .await- .map_err(|e| anyhow::anyhow!("users.GetUsers: {}", e))?;- for user in users {- if let tl::enums::User::User(u) = user {- if u.id == chat_id {- if let Some(tl::enums::UserProfilePhoto::Photo(photo)) = u.photo {- return Ok(photo.photo_id);+ if let Ok(users) = client.invoke(&request).await {+ for user in users {+ if let tl::enums::User::User(u) = user {+ if u.id == chat_id {+ if let Some(tl::enums::UserProfilePhoto::Photo(photo)) = u.photo {+ return Ok(photo.photo_id);+ }+ }+ }+ }+ }++ // Fallback for bots/users where GetUsers does not return photo+ let full_request = tl::functions::users::GetFullUser {+ id: tl::enums::InputUser::User(tl::types::InputUser {+ user_id: chat_id,+ access_hash,+ }),+ };+ if let Ok(user_full) = client.invoke(&full_request).await {+ for user in user_full.users {+ if let tl::enums::User::User(u) = user {+ if u.id == chat_id {+ if let Some(tl::enums::UserProfilePhoto::Photo(photo)) = u.photo {+ return Ok(photo.photo_id);+ }}}}+ if let Some(tl::enums::Photo::Photo(photo)) = user_full.full_user.profile_photo {+ return Ok(photo.id);+ }}+Err(anyhow::anyhow!("User has no photo"))}_ => {diff --git a/src/lib/study-components/TelegramAccountPanel.svelte b/src/lib/study-components/TelegramAccountPanel.svelteindex d387a3b1..0a3fcd2b 100644--- a/src/lib/study-components/TelegramAccountPanel.svelte+++ b/src/lib/study-components/TelegramAccountPanel.svelte@@ -44,14 +44,17 @@try {const [selfInfo, list, bks] = await Promise.all([telegramGetSelf().catch(() => null),- telegramAccountsList(),- telegramAccountsListBackups(),+ telegramAccountsList().catch(() => []),+ telegramAccountsListBackups().catch(() => []),]);me = selfInfo;- profiles = list;- backups = bks;+ profiles = Array.isArray(list) ? list : [];+ backups = Array.isArray(bks) ? bks : [];} catch (e: any) {- error = typeof e === "string" ? e : (e?.message ?? $t("common.error"));+ const msg = typeof e === "string" ? e : (e?.message ?? "");+ if (!msg.includes("ERR_PLUGIN_OUTDATED")) {+ error = msg || $t("common.error");+ }} finally {loading = false;}diff --git a/src/lib/study-components/TelegramChannelDrawer.svelte b/src/lib/study-components/TelegramChannelDrawer.svelteindex 2ec6e51a..f71f863e 100644--- a/src/lib/study-components/TelegramChannelDrawer.svelte+++ b/src/lib/study-components/TelegramChannelDrawer.svelte@@ -23,10 +23,12 @@let {open = $bindable(false),chat,+ photo,onChatRemoved,} = $props<{open: boolean;chat: ChatLite | null;+ photo?: string;onChatRemoved?: (chatId: number) => void;}>();@@ -106,10 +108,17 @@limit: 100,search: participantsSearch.trim() || undefined,});- participants = page.users;- participantsCount = page.count;+ participants = page?.users ?? [];+ participantsCount = page?.count ?? 0;} catch (e: any) {- participantsError = typeof e === "string" ? e : (e?.message ?? $t("telegram.channel_drawer.error_loading_members"));+ participants = [];+ participantsCount = 0;+ const msg = typeof e === "string" ? e : (e?.message ?? "");+ if (msg.includes("ERR_PLUGIN_OUTDATED") || msg.includes("ADMIN_REQUIRED") || msg.includes("CHAT_ADMIN_REQUIRED")) {+ participantsError = "";+ } else {+ participantsError = msg || $t("telegram.channel_drawer.error_loading_members");+ }} finally {participantsLoading = false;}@@ -278,7 +287,11 @@<aside class="drawer" role="dialog" aria-modal="true" aria-label={$t("telegram.channel_drawer.aria_label", { title: chat.title })}><header class="drawer-header"><div class="header-info">- <div class="header-avatar">{chat.title.charAt(0).toUpperCase()}</div>+ {#if photo}+ <img src={photo.startsWith("data:") ? photo : `data:image/jpeg;base64,${photo}`} alt={chat.title} class="header-avatar-img" />+ {:else}+ <div class="header-avatar">{chat.title.charAt(0).toUpperCase()}</div>+ {/if}<div class="header-text"><h2>{chat.title}</h2><span class="header-meta">@@ -622,6 +635,14 @@flex-shrink: 0;}+ .header-avatar-img {+ width: 44px;+ height: 44px;+ border-radius: 50%;+ object-fit: cover;+ flex-shrink: 0;+ }+.header-text {flex: 1;min-width: 0;diff --git a/src/lib/study-components/TelegramCloneWizard.svelte b/src/lib/study-components/TelegramCloneWizard.svelteindex 76108eb0..23964f51 100644--- a/src/lib/study-components/TelegramCloneWizard.svelte+++ b/src/lib/study-components/TelegramCloneWizard.svelte@@ -88,9 +88,14 @@loading = true;error = "";try {- sessions = await telegramCloneList();+ const list = await telegramCloneList();+ sessions = Array.isArray(list) ? list : [];} catch (e: any) {- error = typeof e === "string" ? e : (e?.message ?? $t("common.error"));+ sessions = [];+ const msg = typeof e === "string" ? e : (e?.message ?? "");+ if (!msg.includes("ERR_PLUGIN_OUTDATED")) {+ error = msg || $t("common.error");+ }} finally {loading = false;}diff --git a/src/lib/study-components/TelegramSyncIndicator.svelte b/src/lib/study-components/TelegramSyncIndicator.svelteindex 636ec345..123e016a 100644--- a/src/lib/study-components/TelegramSyncIndicator.svelte+++ b/src/lib/study-components/TelegramSyncIndicator.svelte@@ -48,6 +48,9 @@const r = await telegramSyncNow();showToast("info", $t("telegram.sync.updated_channels", { count: r.updated }));await refresh();+ if (typeof window !== "undefined") {+ window.dispatchEvent(new CustomEvent("telegram:chats:refresh"));+ }} catch (e: any) {showToast("error", typeof e === "string" ? e : (e?.message ?? $t("telegram.sync.sync_error")));} finally {diff --git a/src/routes/telegram/+page.svelte b/src/routes/telegram/+page.svelteindex 6ae4b0c6..20cb8a80 100644--- a/src/routes/telegram/+page.svelte+++ b/src/routes/telegram/+page.svelte@@ -197,6 +197,9 @@e.stopPropagation();drawerChat = chat;drawerOpen = true;+ if (chat && !chatPhotos.has(chat.id)) {+ getChatPhoto(chat.id, chat.chat_type);+ }}function onChatRemoved(removedId: number) {@@ -300,10 +303,18 @@}});+ const handleSyncRefresh = () => {+ if (view === "chats" && !loadingChats) {+ loadChats();+ }+ };+ window.addEventListener("telegram:chats:refresh", handleSyncRefresh);+return () => {destroyed = true;pluginsUnlisten?.();pluginsUnlisten = null;+ window.removeEventListener("telegram:chats:refresh", handleSyncRefresh);};});@@ -1551,6 +1562,7 @@<TelegramChannelDrawerbind:open={drawerOpen}chat={drawerChat}+ photo={drawerChat ? chatPhotos.get(drawerChat.id) : undefined}onChatRemoved={onChatRemoved}/>