ToInputChatPhoto helper

This commit is contained in:
Wizou 2022-10-25 20:07:43 +02:00
parent 517fab89bb
commit cc9cf16f8a
3 changed files with 13 additions and 6 deletions

2
FAQ.md
View file

@ -292,6 +292,8 @@ Here are the recommended actions to fix your problem:
}
```
Also, remember to add a `using TL;` at the top of your files to have access to all the Telegram API methods.
<a name="troubleshoot"></a>
## Troubleshooting guide

View file

@ -588,12 +588,8 @@ namespace WTelegram
fingerprint ^= fingerprint >> 32;
using var ige = new AES_IGE_Stream(stream, aes_key, aes_iv, true);
return await client.UploadFileAsync(ige, null, progress) switch
{
InputFile ifl => new InputEncryptedFileUploaded { id = ifl.id, parts = ifl.parts, md5_checksum = ifl.md5_checksum, key_fingerprint = (int)fingerprint },
InputFileBig ifb => new InputEncryptedFileBigUploaded { id = ifb.id, parts = ifb.parts, key_fingerprint = (int)fingerprint },
_ => null
};
var inputFile = await client.UploadFileAsync(ige, null, progress);
return inputFile.ToInputEncryptedFile((int)fingerprint);
}
/// <summary>Download and decrypt an encrypted file from Telegram Secret Chat into the outputStream</summary>

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
@ -57,6 +58,14 @@ namespace TL
{
public abstract InputEncryptedFileBase ToInputEncryptedFile(int key_fingerprint);
public abstract InputSecureFileBase ToInputSecureFile(byte[] file_hash, byte[] secret);
/// <param name="isSquareVideo10s"><see langword="false"/> for a profile photo. <see langword="null"/> for auto-detection<br/><see langword="true"/> for a profile video. The video <u>MUST</u> be square and 10 seconds max</param>
public InputChatUploadedPhoto ToInputChatPhoto(bool? isSquareVideo10s = null)
{
if (isSquareVideo10s ?? Path.GetExtension(Name)?.ToLowerInvariant() is ".mp4")
return new InputChatUploadedPhoto { video = this, flags = InputChatUploadedPhoto.Flags.has_video };
else
return new InputChatUploadedPhoto { file = this, flags = InputChatUploadedPhoto.Flags.has_file };
}
}
partial class InputFile
{