From f495f59bc88c1d690a673b117e10205163bf1cdc Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Wed, 2 Apr 2025 05:58:04 +0200 Subject: [PATCH] Use media DC for uploads --- src/Client.Helpers.cs | 5 +++-- src/Client.cs | 2 +- src/TL.Xtended.cs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Client.Helpers.cs b/src/Client.Helpers.cs index 25124ea..eefcd36 100644 --- a/src/Client.Helpers.cs +++ b/src/Client.Helpers.cs @@ -33,6 +33,7 @@ namespace WTelegram /// an or than can be used in various requests public async Task UploadFileAsync(Stream stream, string filename, ProgressCallback progress = null) { + var client = await GetClientForDC(-_dcSession.DcID, true); using (stream) { bool hasLength = stream.CanSeek; @@ -65,9 +66,9 @@ namespace WTelegram try { if (isBig) - await this.Upload_SaveBigFilePart(file_id, file_part, file_total_parts, bytes); + await client.Upload_SaveBigFilePart(file_id, file_part, file_total_parts, bytes); else - await this.Upload_SaveFilePart(file_id, file_part, bytes); + await client.Upload_SaveFilePart(file_id, file_part, bytes); lock (tasks) { transmitted += bytes.Length; tasks.Remove(file_part); } progress?.Invoke(transmitted, length); } diff --git a/src/Client.cs b/src/Client.cs index 2dc60d6..29d50b7 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -312,7 +312,7 @@ namespace WTelegram try { Auth_ExportedAuthorization exported = null; - if (_session.UserId != 0 && IsMainDC && altSession.UserId != _session.UserId) + if (_session.UserId != 0 && IsMainDC && altSession.UserId != _session.UserId && altSession.DcID != _dcSession.DcID) exported = await this.Auth_ExportAuthorization(Math.Abs(dcId)); await altSession.Client.ConnectAsync(); if (exported != null) diff --git a/src/TL.Xtended.cs b/src/TL.Xtended.cs index 7b36f1d..30a2c39 100644 --- a/src/TL.Xtended.cs +++ b/src/TL.Xtended.cs @@ -525,7 +525,7 @@ namespace TL partial class Document { public override long ID => id; - public override string ToString() => Filename is string filename ? base.ToString() + ": " + filename : base.ToString(); + public override string ToString() => $"{Filename ?? $"Document {mime_type}"} {size:N0} bytes"; public string Filename => GetAttribute()?.file_name; protected override InputDocument ToInputDocument() => new() { id = id, access_hash = access_hash, file_reference = file_reference }; public InputDocumentFileLocation ToFileLocation(PhotoSizeBase thumbSize = null) => new() { id = id, access_hash = access_hash, file_reference = file_reference, thumb_size = thumbSize?.Type };