From 51a89bc6a1db0d0103b38c0d03e6fd3d8620505c Mon Sep 17 00:00:00 2001 From: Wizou Date: Sat, 25 Dec 2021 03:20:22 +0100 Subject: [PATCH] change Dictionary of UserBase into Dictionary of User --- EXAMPLES.md | 31 +++-- Examples/Program_ListenUpdates.cs | 2 +- FAQ.md | 2 +- src/TL.Helpers.cs | 22 ++-- src/TL.Schema.cs | 188 +++++++++++++++--------------- src/TL.cs | 8 +- 6 files changed, 131 insertions(+), 122 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index 3bf8182..54dca92 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -20,7 +20,7 @@ In real production code, you might want to properly test the success of each ope using var client = new WTelegram.Client(Environment.GetEnvironmentVariable); await client.LoginUserIfNeeded(); var resolved = await client.Contacts_ResolveUsername("channelname"); // without the @ -if (resolved.UserOrChat is Channel channel) +if (resolved.Chat is Channel channel) await client.Channels_JoinChannel(channel); ``` @@ -51,7 +51,8 @@ if (contacts.imported.Length > 0) ```csharp using var client = new WTelegram.Client(Environment.GetEnvironmentVariable); var user = await client.LoginUserIfNeeded(); -var text = $"Hello __dear *{Markdown.Escape(user.first_name)}*__\nEnjoy this `userbot` written with [WTelegramClient](https://github.com/wiz0u/WTelegramClient)"; +var text = $"Hello __dear *{Markdown.Escape(user.first_name)}*__\n" + + "Enjoy this `userbot` written with [WTelegramClient](https://github.com/wiz0u/WTelegramClient)"; var entities = client.MarkdownToEntities(ref text); await client.SendMessageAsync(InputPeer.Self, text, entities: entities); ``` @@ -59,7 +60,7 @@ See [MarkdownV2 formatting style](https://core.telegram.org/bots/api/#markdownv2 *Note: For the `tg://user?id=` notation to work, that user's access hash must have been collected first ([see below](#collect-access-hash))* -### Fun with stickers, dice and animated emojies +### Fun with stickers, GIFs, dice, and animated emojies ```csharp using var client = new WTelegram.Client(Environment.GetEnvironmentVariable); var user = await client.LoginUserIfNeeded(); @@ -82,6 +83,21 @@ var laughId = friendlyPanda.packs.First(p => p.emoticon == "😂").documents[0]; var laughDoc = friendlyPanda.documents.First(d => d.ID == laughId); await client.SendMessageAsync(InputPeer.Self, null, new InputMediaDocument { id = laughDoc }); +// • Send a GIF from an internet URL +await client.SendMessageAsync(InputPeer.Self, null, new InputMediaDocumentExternal + { url = "https://upload.wikimedia.org/wikipedia/commons/2/2c/Rotating_earth_%28large%29.gif" }); + +// • Send a GIF stored on the computer (you can save inputFile for later reuse) +var inputFile = await client.UploadFileAsync(@"C:\Pictures\Rotating_earth_(large).gif"); +await client.SendMediaAsync(InputPeer.Self, null, inputFile); + +// • Send a random dice/game-of-chance effect from the list of available "dices", see https://core.telegram.org/api/dice +var appConfig = await client.Help_GetAppConfig(); +var emojies_send_dice = appConfig["emojies_send_dice"] as string[]; +var dice_emoji = emojies_send_dice[random.Next(emojies_send_dice.Length)]; +var diceMsg = await client.SendMessageAsync(InputPeer.Self, null, new InputMediaDice { emoticon = dice_emoji }); +Console.WriteLine("Dice result:" + ((MessageMediaDice)diceMsg.media).value); + // • Send an animated emoji with full-screen animation, see https://core.telegram.org/api/animated-emojis#emoji-reactions // Please note that on Telegram Desktop, you won't view the effect from the sender user's point of view // You can view the effect if you're on Telegram Android, or if you're the receiving user (instead of Self) @@ -94,13 +110,6 @@ var typing = await client.Messages_SetTyping(InputPeer.Self, new SendMessageEmoj interaction = new DataJSON { data = @"{""v"":1,""a"":[{""t"":0.0,""i"":1}]}" } }); await Task.Delay(5000); - -// • Send a random dice/game-of-chance effect from the list of available "dices", see https://core.telegram.org/api/dice -var appConfig = await client.Help_GetAppConfig(); -var emojies_send_dice = appConfig["emojies_send_dice"] as string[]; -var dice_emoji = emojies_send_dice[random.Next(emojies_send_dice.Length)]; -var diceMsg = await client.SendMessageAsync(InputPeer.Self, null, new InputMediaDice { emoticon = dice_emoji }); -Console.WriteLine("Dice result:" + ((MessageMediaDice)diceMsg.media).value); ``` @@ -155,7 +164,7 @@ while (dialogs.Dialogs.Length != 0) foreach (var dialog in dialogs.Dialogs) switch (dialogs.UserOrChat(dialog)) { - case UserBase user when user.IsActive: Console.WriteLine("User " + user); break; + case User user when user.IsActive: Console.WriteLine("User " + user); break; case ChatBase chat when chat.IsActive: Console.WriteLine(chat); break; } var lastDialog = dialogs.Dialogs[^1]; diff --git a/Examples/Program_ListenUpdates.cs b/Examples/Program_ListenUpdates.cs index e7784d6..768452a 100644 --- a/Examples/Program_ListenUpdates.cs +++ b/Examples/Program_ListenUpdates.cs @@ -35,7 +35,7 @@ namespace WTelegramClientTest } - private static readonly Dictionary _users = new(); + private static readonly Dictionary _users = new(); private static readonly Dictionary _chats = new(); private static string User(long id) => _users.TryGetValue(id, out var user) ? user.ToString() : $"User {id}"; private static string Chat(long id) => _chats.TryGetValue(id, out var chat) ? chat.ToString() : $"Chat {id}"; diff --git a/FAQ.md b/FAQ.md index a586863..84e97ea 100644 --- a/FAQ.md +++ b/FAQ.md @@ -53,7 +53,7 @@ You obtain the `access_hash` through **description structures** like `Channel`, *(if you have a `Peer` object, you can convert it to a `User`/`Channel`/`Chat` via the `UserOrChat` helper from the root class that contained the peer)* Once you obtained the description structure, there are 3 methods for building your `Input...` structure: -* **Recommended:** If you take a look at the **description structure** class or `ChatBase/UserBase`, +* **Recommended:** If you take a look at the **description structure** class or base class `ChatBase/UserBase`, you will see that they have conversion implicit operators or methods that can create the `Input...` structure for you automatically. So you can just pass that structure you already have, in place of the `Input...` argument, it will work! * Alternatively, you can manually create the `Input...` structure yourself by extracting the `access_hash` from the **description structure** diff --git a/src/TL.Helpers.cs b/src/TL.Helpers.cs index 3e982e6..7384682 100644 --- a/src/TL.Helpers.cs +++ b/src/TL.Helpers.cs @@ -39,25 +39,25 @@ namespace TL partial class Peer { public abstract long ID { get; } - abstract internal IPeerInfo UserOrChat(Dictionary users, Dictionary chats); + abstract internal IPeerInfo UserOrChat(Dictionary users, Dictionary chats); } partial class PeerUser { public override string ToString() => "user " + user_id; public override long ID => user_id; - internal override IPeerInfo UserOrChat(Dictionary users, Dictionary chats) => users[user_id]; + internal override IPeerInfo UserOrChat(Dictionary users, Dictionary chats) => users[user_id]; } partial class PeerChat { public override string ToString() => "chat " + chat_id; public override long ID => chat_id; - internal override IPeerInfo UserOrChat(Dictionary users, Dictionary chats) => chats[chat_id]; + internal override IPeerInfo UserOrChat(Dictionary users, Dictionary chats) => chats[chat_id]; } partial class PeerChannel { public override string ToString() => "channel " + channel_id; public override long ID => channel_id; - internal override IPeerInfo UserOrChat(Dictionary users, Dictionary chats) => chats[channel_id]; + internal override IPeerInfo UserOrChat(Dictionary users, Dictionary chats) => chats[channel_id]; } partial class UserBase : IPeerInfo @@ -66,8 +66,8 @@ namespace TL public abstract bool IsActive { get; } public abstract InputPeer ToInputPeer(); protected abstract InputUser ToInputUser(); - public static implicit operator InputPeer(UserBase user) => user.ToInputPeer(); - public static implicit operator InputUser(UserBase user) => user.ToInputUser(); + public static implicit operator InputPeer(UserBase user) => user?.ToInputPeer(); + public static implicit operator InputUser(UserBase user) => user?.ToInputUser(); } partial class UserEmpty { @@ -305,7 +305,7 @@ namespace TL partial class Contacts_ResolvedPeer { public static implicit operator InputPeer(Contacts_ResolvedPeer resolved) => resolved.UserOrChat.ToInputPeer(); - public UserBase User => peer is PeerUser pu ? users[pu.user_id] : null; + public User User => peer is PeerUser pu ? users[pu.user_id] : null; public ChatBase Chat => peer is PeerChat or PeerChannel ? chats[peer.ID] : null; } @@ -361,21 +361,21 @@ namespace TL partial class UpdatesBase { public abstract Update[] UpdateList { get; } - public virtual Dictionary Users => NoUsers; + public virtual Dictionary Users => NoUsers; public virtual Dictionary Chats => NoChats; - private static readonly Dictionary NoUsers = new(); + private static readonly Dictionary NoUsers = new(); private static readonly Dictionary NoChats = new(); } partial class UpdatesCombined { public override Update[] UpdateList => updates; - public override Dictionary Users => users; + public override Dictionary Users => users; public override Dictionary Chats => chats; } partial class Updates { public override Update[] UpdateList => updates; - public override Dictionary Users => users; + public override Dictionary Users => users; public override Dictionary Chats => chats; } partial class UpdatesTooLong { public override Update[] UpdateList => Array.Empty(); } diff --git a/src/TL.Schema.cs b/src/TL.Schema.cs index 339702f..4c97de8 100644 --- a/src/TL.Schema.cs +++ b/src/TL.Schema.cs @@ -2659,7 +2659,7 @@ namespace TL /// Number of contacts that were saved successfully public int saved_count; /// User list - public Dictionary users; + public Dictionary users; } /// Info on succesfully imported contacts. See @@ -2673,7 +2673,7 @@ namespace TL /// List of contact ids that could not be imported due to system limitation and will need to be imported at a later date.
Parameter added in
Layer 13
public long[] retry_contacts; /// List of users - public Dictionary users; + public Dictionary users; } /// Full list of blocked users. See @@ -2685,8 +2685,8 @@ namespace TL /// Blocked chats public Dictionary chats; /// List of users - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// Incomplete list of blocked users. See @@ -2704,7 +2704,7 @@ namespace TL public abstract DialogBase[] Dialogs { get; } /// List of last messages from each chat public abstract MessageBase[] Messages { get; } - /// returns a or for the given Peer + /// returns a or for the given Peer public abstract IPeerInfo UserOrChat(Peer peer); } /// Full list of chats with messages and auxiliary data. See @@ -2718,13 +2718,13 @@ namespace TL /// List of groups mentioned in the chats public Dictionary chats; /// List of users mentioned in messages and groups - public Dictionary users; + public Dictionary users; /// List of chats public override DialogBase[] Dialogs => dialogs; /// List of last messages from each chat public override MessageBase[] Messages => messages; - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// Incomplete list of dialogs with messages and auxiliary data. See @@ -2743,7 +2743,7 @@ namespace TL public override DialogBase[] Dialogs => default; public override MessageBase[] Messages => default; - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => null; } @@ -2752,7 +2752,7 @@ namespace TL { /// List of messages public abstract MessageBase[] Messages { get; } - /// returns a or for the given Peer + /// returns a or for the given Peer public abstract IPeerInfo UserOrChat(Peer peer); } /// Full list of messages with auxilary data. See @@ -2764,11 +2764,11 @@ namespace TL /// List of chats mentioned in dialogs public Dictionary chats; /// List of users mentioned in messages and chats - public Dictionary users; + public Dictionary users; /// List of messages public override MessageBase[] Messages => messages; - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// Incomplete list of messages and auxiliary data. See @@ -2811,7 +2811,7 @@ namespace TL /// Chats public Dictionary chats; /// Users - public Dictionary users; + public Dictionary users; [Flags] public enum Flags { @@ -2823,7 +2823,7 @@ namespace TL /// Found messages public override MessageBase[] Messages => messages; - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// No new messages matching the query were found See @@ -2834,7 +2834,7 @@ namespace TL public int count; public override MessageBase[] Messages => default; - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => null; } @@ -2862,8 +2862,8 @@ namespace TL /// List containing basic info on chat public Dictionary chats; /// List of users mentioned above - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -4079,7 +4079,7 @@ namespace TL public abstract EncryptedMessageBase[] NewEncryptedMessages { get; } /// List of updates public abstract Update[] OtherUpdates { get; } - /// returns a or for the given Peer + /// returns a or for the given Peer public abstract IPeerInfo UserOrChat(Peer peer); } /// No events. See @@ -4094,7 +4094,7 @@ namespace TL public override MessageBase[] NewMessages => Array.Empty(); public override EncryptedMessageBase[] NewEncryptedMessages => Array.Empty(); public override Update[] OtherUpdates => Array.Empty(); - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => null; } /// Full list of occurred events. See @@ -4110,7 +4110,7 @@ namespace TL /// List of chats mentioned in events public Dictionary chats; /// List of users mentioned in events - public Dictionary users; + public Dictionary users; /// Current state public Updates_State state; @@ -4120,7 +4120,7 @@ namespace TL public override EncryptedMessageBase[] NewEncryptedMessages => new_encrypted_messages; /// List of updates public override Update[] OtherUpdates => other_updates; - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// Incomplete list of occurred events. See @@ -4136,7 +4136,7 @@ namespace TL /// List of chats mentioned in events public Dictionary chats; /// List of users mentioned in events - public Dictionary users; + public Dictionary users; /// Intermediary state public Updates_State intermediate_state; @@ -4146,7 +4146,7 @@ namespace TL public override EncryptedMessageBase[] NewEncryptedMessages => new_encrypted_messages; /// List of updates public override Update[] OtherUpdates => other_updates; - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// The difference is too long, and the specified state must be used to refetch updates. See @@ -4159,7 +4159,7 @@ namespace TL public override MessageBase[] NewMessages => default; public override EncryptedMessageBase[] NewEncryptedMessages => default; public override Update[] OtherUpdates => default; - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => null; } @@ -4304,7 +4304,7 @@ namespace TL /// List of updates public Update[] updates; /// List of users mentioned in updates - public Dictionary users; + public Dictionary users; /// List of chats mentioned in updates public Dictionary chats; /// Current date @@ -4316,7 +4316,7 @@ namespace TL /// Current date public override DateTime Date => date; - /// returns a or for the given Peer + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// Full constructor of updates See @@ -4326,7 +4326,7 @@ namespace TL /// List of updates public Update[] updates; /// List of users mentioned in updates - public Dictionary users; + public Dictionary users; /// List of chats mentioned in updates public Dictionary chats; /// Current date @@ -4336,7 +4336,7 @@ namespace TL /// Current date public override DateTime Date => date; - /// returns a or for the given Peer + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// Shortened constructor containing info on one outgoing message to a contact (the destination chat has to be extracted from the method call that returned this object). See @@ -4383,7 +4383,7 @@ namespace TL /// List of photos public PhotoBase[] photos; /// List of mentioned users - public Dictionary users; + public Dictionary users; } /// Incomplete list of photos with auxiliary data. See [TLDef(0x15051F54)] @@ -4400,7 +4400,7 @@ namespace TL /// Photo public PhotoBase photo; /// Users - public Dictionary users; + public Dictionary users; } /// Contains info on file. Derived classes: , See @@ -5117,8 +5117,8 @@ namespace TL /// Found chats public Dictionary chats; /// List of users - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -5259,8 +5259,8 @@ namespace TL /// Chats to which the rules apply public Dictionary chats; /// Users to which the rules apply - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -6262,8 +6262,8 @@ namespace TL /// Chats public Dictionary chats; /// Users - public Dictionary users; - /// returns a or for the result + public Dictionary users; + /// returns a or for the result public IPeerInfo UserOrChat => peer.UserOrChat(users, chats); } @@ -6280,7 +6280,7 @@ namespace TL /// Contains the difference (new messages) between our local channel state and the remote state Derived classes: , , See public abstract partial class Updates_ChannelDifferenceBase : IObject, IPeerResolver { - /// returns a or for the given Peer + /// returns a or for the given Peer public abstract IPeerInfo UserOrChat(Peer peer); } /// There are no new updates See @@ -6301,7 +6301,7 @@ namespace TL /// Field has a value has_timeout = 0x2, } - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => null; } /// The provided pts + limit < remote pts. Simply, there are too many updates to be fetched (more than limit), the client has to resolve the update gap in one of the following ways: See @@ -6319,7 +6319,7 @@ namespace TL /// Chats from messages public Dictionary chats; /// Users from messages - public Dictionary users; + public Dictionary users; [Flags] public enum Flags { @@ -6328,7 +6328,7 @@ namespace TL /// Field has a value has_timeout = 0x2, } - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// The new updates See @@ -6348,7 +6348,7 @@ namespace TL /// Chats public Dictionary chats; /// Users - public Dictionary users; + public Dictionary users; [Flags] public enum Flags { @@ -6357,7 +6357,7 @@ namespace TL /// Field has a value has_timeout = 0x2, } - /// returns a or for the given Peer + /// returns a or for the given Peer public override IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -6554,8 +6554,8 @@ namespace TL /// Mentioned chats public Dictionary chats; /// Users mentioned in participant info - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -6568,8 +6568,8 @@ namespace TL /// Mentioned chats public Dictionary chats; /// Users - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -7160,7 +7160,7 @@ namespace TL /// Caching validity of the results public DateTime cache_time; /// Users mentioned in the results - public Dictionary users; + public Dictionary users; [Flags] public enum Flags { @@ -7381,10 +7381,10 @@ namespace TL /// Chats public Dictionary chats; /// Users - public Dictionary users; + public Dictionary users; /// Current update state of dialog public Updates_State state; - /// returns a or for the given Peer + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -7443,8 +7443,8 @@ namespace TL /// Chats public Dictionary chats; /// Users - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } /// Top peers disabled See @@ -7685,7 +7685,7 @@ namespace TL /// Highscores public HighScore[] scores; /// Users, associated to the highscores - public Dictionary users; + public Dictionary users; } /// Rich text Derived classes: , , , , , , , , , , , , , , See @@ -8411,7 +8411,7 @@ namespace TL /// Contains information about saved card credentials [IfFlag(1)] public PaymentSavedCredentials saved_credentials; /// Users - public Dictionary users; + public Dictionary users; [Flags] public enum Flags { @@ -8498,7 +8498,7 @@ namespace TL /// Payment credential name public string credentials_title; /// Users - public Dictionary users; + public Dictionary users; [Flags] public enum Flags { @@ -8903,7 +8903,7 @@ namespace TL /// The VoIP phone call public PhoneCallBase phone_call; /// VoIP phone call participants - public Dictionary users; + public Dictionary users; } /// Represents the download status of a CDN file Derived classes: , See @@ -9347,8 +9347,8 @@ namespace TL /// Chats mentioned in events public Dictionary chats; /// Users mentioned in events - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -9467,8 +9467,8 @@ namespace TL /// Chats public Dictionary chats; /// Users - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -9525,7 +9525,7 @@ namespace TL /// Web authorization list public WebAuthorization[] authorizations; /// Users - public Dictionary users; + public Dictionary users; } /// A message Derived classes: , , , See @@ -10015,7 +10015,7 @@ namespace TL /// Telegram Passport errors public SecureValueErrorBase[] errors; /// Info about the bot to which the form will be submitted - public Dictionary users; + public Dictionary users; /// URL of the service's privacy policy [IfFlag(0)] public string privacy_policy_url; @@ -11057,8 +11057,8 @@ namespace TL /// Chat list public Dictionary chats; /// Users mentioned in the chat list - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -11227,7 +11227,7 @@ namespace TL /// Vote info for each user public MessageUserVoteBase[] votes; /// Info about users that voted in the poll - public Dictionary users; + public Dictionary users; /// Offset to use with the next messages.getPollVotes request, empty string if no more results are available. [IfFlag(0)] public string next_offset; @@ -11444,7 +11444,7 @@ namespace TL /// Chat info public Dictionary chats; /// User info - public Dictionary users; + public Dictionary users; /// PSA type [IfFlag(1)] public string psa_type; /// PSA message @@ -11459,7 +11459,7 @@ namespace TL /// Field has a value has_psa_message = 0x4, } - /// returns a or for the result + /// returns a or for the result public IPeerInfo UserOrChat => peer.UserOrChat(users, chats); } @@ -11560,7 +11560,7 @@ namespace TL /// Info about most active group inviters public StatsGroupTopInviter[] top_inviters; /// Info about users mentioned in statistics - public Dictionary users; + public Dictionary users; } /// Global privacy settings See @@ -11669,8 +11669,8 @@ namespace TL /// Chats mentioned in constructor public Dictionary chats; /// Users mentioned in constructor - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -11693,7 +11693,7 @@ namespace TL /// Chats mentioned in constructor public Dictionary chats; /// Users mentioned in constructor - public Dictionary users; + public Dictionary users; [Flags] public enum Flags { @@ -11704,7 +11704,7 @@ namespace TL /// Field has a value has_read_outbox_max_id = 0x4, } - /// returns a or for the given Peer + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -11948,8 +11948,8 @@ namespace TL /// Chats mentioned in the participants vector public Dictionary chats; /// Users mentioned in the participants vector - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -11966,10 +11966,10 @@ namespace TL /// Mentioned chats public Dictionary chats; /// Mentioned users - public Dictionary users; + public Dictionary users; /// Version info public int version; - /// returns a or for the given Peer + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -12061,7 +12061,7 @@ namespace TL /// Exported invites public ExportedChatInvite[] invites; /// Info about the admin - public Dictionary users; + public Dictionary users; } /// Contains info about a chat invite, and eventually a pointer to the newest chat invite. Derived classes: , See @@ -12070,7 +12070,7 @@ namespace TL /// Info about the chat invite public abstract ExportedChatInvite Invite { get; } /// Mentioned users - public abstract Dictionary Users { get; } + public abstract Dictionary Users { get; } } /// Info about a chat invite See [TLDef(0x1871BE50)] @@ -12079,12 +12079,12 @@ namespace TL /// Info about the chat invite public ExportedChatInvite invite; /// Mentioned users - public Dictionary users; + public Dictionary users; /// Info about the chat invite public override ExportedChatInvite Invite => invite; /// Mentioned users - public override Dictionary Users => users; + public override Dictionary Users => users; } /// The specified chat invite was replaced with another one See [TLDef(0x222600EF)] @@ -12095,12 +12095,12 @@ namespace TL /// The invite that replaces the previous invite public ExportedChatInvite new_invite; /// Mentioned users - public Dictionary users; + public Dictionary users; /// The replaced chat invite public override ExportedChatInvite Invite => invite; /// Mentioned users - public override Dictionary Users => users; + public override Dictionary Users => users; } /// Info about the users that joined the chat using a specific chat invite See @@ -12112,7 +12112,7 @@ namespace TL /// The users that joined public ChatInviteImporter[] importers; /// The users that joined - public Dictionary users; + public Dictionary users; } /// Info about chat invites generated by admins. See @@ -12134,7 +12134,7 @@ namespace TL /// Info about chat invites generated by admins. public ChatAdminWithInvites[] admins; /// Mentioned users - public Dictionary users; + public Dictionary users; } /// Contains a confirmation text to be shown to the user, upon importing chat history, click here for more info ». See @@ -12154,8 +12154,8 @@ namespace TL /// Chats mentioned in the peers vector public Dictionary chats; /// Users mentioned in the peers vector - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -12297,8 +12297,8 @@ namespace TL /// Chats mentioned in the sponsored messages public Dictionary chats; /// Users mentioned in the sponsored messages - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -12324,7 +12324,7 @@ namespace TL public SearchResultsCalendarPeriod[] periods; public MessageBase[] messages; public Dictionary chats; - public Dictionary users; + public Dictionary users; [Flags] public enum Flags { @@ -12332,7 +12332,7 @@ namespace TL /// Field has a value has_offset_id_offset = 0x2, } - /// returns a or for the given Peer + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -12361,8 +12361,8 @@ namespace TL { public Peer[] peers; public Dictionary chats; - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -12372,8 +12372,8 @@ namespace TL { public UserFull full_user; public Dictionary chats; - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } @@ -12383,8 +12383,8 @@ namespace TL { public PeerSettings settings; public Dictionary chats; - public Dictionary users; - /// returns a or for the given Peer + public Dictionary users; + /// returns a or for the given Peer public IPeerInfo UserOrChat(Peer peer) => peer.UserOrChat(users, chats); } diff --git a/src/TL.cs b/src/TL.cs index 3aa9357..4e177b0 100644 --- a/src/TL.cs +++ b/src/TL.cs @@ -145,8 +145,8 @@ namespace TL return new Int128(reader); else if (type == typeof(Int256)) return new Int256(reader); - else if (type == typeof(Dictionary)) - return reader.ReadTLDictionary(u => u.ID); + else if (type == typeof(Dictionary)) + return reader.ReadTLDictionary(u => u.ID); else if (type == typeof(Dictionary)) return reader.ReadTLDictionary(c => c.ID); else @@ -212,7 +212,7 @@ namespace TL throw new ApplicationException($"Cannot deserialize {type.Name} with ctor #{ctorNb:x}"); } - internal static Dictionary ReadTLDictionary(this BinaryReader reader, Func getID) + internal static Dictionary ReadTLDictionary(this BinaryReader reader, Func getID) where T : class { uint ctorNb = reader.ReadUInt32(); var elementType = typeof(T); @@ -223,7 +223,7 @@ namespace TL for (int i = 0; i < count; i++) { var value = (T)reader.ReadTLValue(elementType); - dict.Add(getID(value), value); + dict.Add(getID(value), value is UserEmpty ? null : value); } return dict; }