mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
added DownloadProfilePhotoAsync helper
This commit is contained in:
parent
791dc88ea0
commit
72b28e97ba
8
FAQ.md
8
FAQ.md
|
|
@ -69,15 +69,15 @@ You can access these versions for testing in your program by going to our [priva
|
|||
After that, you should be able to see/install the pre-release versions in your Nuget package manager and install them in your application. *(make sure you enable the **pre-release** checkbox)*
|
||||
|
||||
<a name="wrong-server"></a>
|
||||
#### 6. Telegram can't find any chats and asks me to signup (firstname, lastname) even for an existing account
|
||||
#### 6. Telegram asks me to signup (firstname, lastname) even for an existing account
|
||||
This happens when you connect to Telegram Test servers instead of Production servers.
|
||||
On these separate test servers, all created accounts and chats are periodically deleted, so you shouldn't use them under normal circumstances.
|
||||
|
||||
You can verify this is your case by looking at [WTelegram logs](EXAMPLES.MD#logging) on the line `Connected to (Test) DC x...`
|
||||
You can verify this is your issue by looking at [WTelegram logs](EXAMPLES.MD#logging) on the line `Connected to (Test) DC x...`
|
||||
|
||||
This wrong-server problem typically happens when you use WTelegramClient Github source project in your application in DEBUG builds.
|
||||
It is **not recommended** to use WTelegramClient in source code form.
|
||||
Instead, you should use the Nuget manager to **import the WTelegramClient Nuget package** into your application.
|
||||
Instead, you should use the Nuget manager to **install package WTelegramClient** into your application.
|
||||
|
||||
If you use the Github source project in an old .NET Framework 4.x or .NET Core x.x application, you may also experience the following error
|
||||
> System.TypeInitializationException (FileNotFoundException for "System.Text.Json Version=5.0.0.0 ...")
|
||||
|
|
@ -140,7 +140,7 @@ However, note that those Channel-compatible methods will require an `InputChanne
|
|||
That object must be created with both fields `channel_id` and `access_hash` correctly filled. You can read more about this in [FAQ #4](#access-hash).
|
||||
|
||||
<a name="chats-chats"></a>
|
||||
#### 10. `chats.chats[id]` throws KeyNotFoundException. My chats list is empty or does not contain the chat id.
|
||||
#### 10. `chats.chats[id]` fails. My chats list is empty or does not contain the chat id.
|
||||
|
||||
There can be several reasons why `chats.chats[id]` raise an error:
|
||||
- The user account you're currently logged-in as has not joined this particular chat.
|
||||
|
|
|
|||
|
|
@ -1268,14 +1268,14 @@ namespace WTelegram
|
|||
/// <summary>Download a file from Telegram into the outputStream</summary>
|
||||
/// <param name="fileLocation">Telegram file identifier, typically obtained with a .ToFileLocation() call</param>
|
||||
/// <param name="outputStream">Stream to write file content to. This method does not close/dispose the stream</param>
|
||||
/// <param name="fileDC">(optional) DC on which the file is stored</param>
|
||||
/// <param name="dc_id">(optional) DC on which the file is stored</param>
|
||||
/// <param name="fileSize">(optional) Expected file size</param>
|
||||
/// <param name="progress">(optional) Callback for tracking the progression of the transfer</param>
|
||||
/// <returns>The file type</returns>
|
||||
public async Task<Storage_FileType> DownloadFileAsync(InputFileLocationBase fileLocation, Stream outputStream, int fileDC = 0, int fileSize = 0, ProgressCallback progress = null)
|
||||
public async Task<Storage_FileType> DownloadFileAsync(InputFileLocationBase fileLocation, Stream outputStream, int dc_id = 0, int fileSize = 0, ProgressCallback progress = null)
|
||||
{
|
||||
Storage_FileType fileType = Storage_FileType.unknown;
|
||||
var client = fileDC == 0 ? this : await GetClientForDC(fileDC, true);
|
||||
var client = dc_id == 0 ? this : await GetClientForDC(dc_id, true);
|
||||
using var writeSem = new SemaphoreSlim(1);
|
||||
long streamStartPos = outputStream.Position;
|
||||
int fileOffset = 0, maxOffsetSeen = 0;
|
||||
|
|
@ -1288,7 +1288,7 @@ namespace WTelegram
|
|||
await _parallelTransfers.WaitAsync();
|
||||
var task = LoadPart(fileOffset);
|
||||
lock (tasks) tasks[fileOffset] = task;
|
||||
if (fileDC == 0) { await task; fileDC = client._dcSession.DcID; }
|
||||
if (dc_id == 0) { await task; dc_id = client._dcSession.DcID; }
|
||||
fileOffset += FilePartSize;
|
||||
if (fileSize != 0 && fileOffset >= fileSize)
|
||||
{
|
||||
|
|
@ -1365,6 +1365,39 @@ namespace WTelegram
|
|||
return fileType;
|
||||
}
|
||||
|
||||
/// <summary>Download the profile photo for a given peer into the outputStream</summary>
|
||||
/// <param name="peer">User, Chat or Channel</param>
|
||||
/// <param name="outputStream">Stream to write the file content to. This method does not close/dispose the stream</param>
|
||||
/// <param name="big">Whether to download the high-quality version of the picture</param>
|
||||
/// <returns>The file type of the photo, or 0 if no photo available</returns>
|
||||
public async Task<Storage_FileType> DownloadProfilePhotoAsync(IPeerInfo peer, Stream outputStream, bool big = false)
|
||||
{
|
||||
int dc_id;
|
||||
var fileLocation = new InputPeerPhotoFileLocation { peer = peer.ToInputPeer() };
|
||||
if (big) fileLocation.flags = InputPeerPhotoFileLocation.Flags.big;
|
||||
switch (peer)
|
||||
{
|
||||
case User user:
|
||||
if (user.photo == null) return 0;
|
||||
dc_id = user.photo.dc_id;
|
||||
fileLocation.photo_id = user.photo.photo_id;
|
||||
break;
|
||||
case Chat chat:
|
||||
if (chat.photo == null) return 0;
|
||||
dc_id = chat.photo.dc_id;
|
||||
fileLocation.photo_id = chat.photo.photo_id;
|
||||
break;
|
||||
case Channel channel:
|
||||
if (channel.photo == null) return 0;
|
||||
dc_id = channel.photo.dc_id;
|
||||
fileLocation.photo_id = channel.photo.photo_id;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return await DownloadFileAsync(fileLocation, outputStream, dc_id);
|
||||
}
|
||||
|
||||
/// <summary>Helper method that tries to fetch all participants from a Channel (beyond Telegram server-side limitations)</summary>
|
||||
/// <param name="channel">The channel to query</param>
|
||||
/// <param name="includeKickBan">Also fetch the kicked/banned members?</param>
|
||||
|
|
|
|||
Loading…
Reference in a new issue