chats and users fields are now serialized as Dictionary for easier access

This commit is contained in:
Wizou 2021-10-20 19:12:50 +02:00
parent 5e2ddf41f6
commit 718e96a763
10 changed files with 145 additions and 116 deletions

2
.github/ci.yml vendored
View file

@ -2,7 +2,7 @@ pr: none
trigger:
- master
name: 1.3.2-ci.$(Rev:r)
name: 1.4.1-ci.$(Rev:r)
pool:
vmImage: ubuntu-latest

View file

@ -16,7 +16,7 @@ Remember that these are just simple example codes that you should adjust to your
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var resolved = await client.Contacts_ResolveUsername("USERNAME");
await resolved.SendMessageAsync(result.users[0], "Hello!");
await client.SendMessageAsync(resolved.users[0], "Hello!");
```
### Send a message to someone by phone number
```csharp
@ -25,19 +25,20 @@ await client.LoginUserIfNeeded();
var imported = await client.Contacts_ImportContacts(new[] { new InputPhoneContact { phone = "+PHONENUMBER" } });
await client.SendMessageAsync(imported.users[0], "Hello!");
```
*Note: To prevent spam, Telegram may restrict your ability to add new phone numbers.*
### List all chats (groups/channels) the user is in and send a message to one
```csharp
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null);
foreach (var chat in chats.chats)
Console.WriteLine($"{chat.ID} : {chat}");
foreach (var (id, chat) in chats.chats)
Console.WriteLine($"{id} : {chat}");
Console.Write("Choose a chat ID to send a message to: ");
long id = long.Parse(Console.ReadLine());
var target = chats.chats.First(chat => chat.ID == id);
await client.SendMessageAsync(target, "Hello, World");
long chatId = long.Parse(Console.ReadLine());
await client.SendMessageAsync(chats.chats[chatId], "Hello, World");
```
Note: the list returned by Messages_GetAllChats contains the `access_hash` for those chats.
*Note: the list returned by Messages_GetAllChats contains the `access_hash` for those chats.*
<br/>
See a longer version of this example in [Examples/Program_GetAllChats.cs](Examples/Program_GetAllChats.cs)
@ -46,7 +47,7 @@ See a longer version of this example in [Examples/Program_GetAllChats.cs](Exampl
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null);
InputPeer peer = chats.chats.First(chat => chat.ID == 1234567890); // the chat we want
InputPeer peer = chats.chats[1234567890]; // the chat we want
DateTime when = DateTime.UtcNow.AddMinutes(3);
await client.SendMessageAsync(peer, "This will be posted in 3 minutes", schedule_date: when);
```
@ -58,7 +59,7 @@ const string Filepath = @"C:\...\photo.jpg";
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null);
InputPeer peer = chats.chats.First(chat => chat.ID == TargetChatId);
InputPeer peer = chats.chats[TargetChatId];
var inputFile = await client.UploadFileAsync(Filepath);
await client.SendMediaAsync(peer, "Here is the photo", inputFile);
```
@ -66,7 +67,7 @@ await client.SendMediaAsync(peer, "Here is the photo", inputFile);
```csharp
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var dialogsBase = await client.Messages_GetDialogs(default, 0, null, 0, 0); // dialogs = groups/channels/users
var dialogsBase = await client.Messages_GetDialogs(default, 0, null, 0, 0);
if (dialogsBase is Messages_Dialogs dialogs)
while (dialogs.dialogs.Length != 0)
{
@ -74,18 +75,17 @@ if (dialogsBase is Messages_Dialogs dialogs)
if (dialog is Dialog { peer: var peer } || (dialog is DialogFolder dialogFolder && (peer = dialogFolder.peer) != null))
switch (peer)
{
case PeerUser: Console.WriteLine("User " + dialogs.users.First(u => u.ID == peer.ID)); break;
case PeerChannel or PeerChat: Console.WriteLine(dialogs.chats.First(c => c.ID == peer.ID)); break;
case PeerUser: Console.WriteLine("User " + dialogs.users[peer.ID]); break;
case PeerChannel or PeerChat: Console.WriteLine(dialogs.chats[peer.ID]); break;
}
var lastDialog = (Dialog)dialogs.dialogs[^1];
var lastMsg = dialogs.messages.LastOrDefault(m => m.Peer.ID == lastDialog.peer.ID && m.ID == lastDialog.top_message);
InputPeer offsetPeer = lastDialog.peer is PeerUser pu ? dialogs.users.First(u => u.ID == pu.ID)
: dialogs.chats.First(u => u.ID == lastDialog.peer.ID);
InputPeer offsetPeer = lastDialog.peer is PeerUser pu ? dialogs.users[pu.ID] : dialogs.chats[lastDialog.peer.ID];
dialogs = (Messages_Dialogs)await client.Messages_GetDialogs(lastMsg?.Date ?? default, lastDialog.top_message, offsetPeer, 500, 0);
}
```
Note: the lists returned by Messages_GetDialogs contains the `access_hash` for those chats and users.
*Note: the lists returned by Messages_GetDialogs contains the `access_hash` for those chats and users.*
<br/>
See also the `Main` method in [Examples/Program_ListenUpdates.cs](Examples/Program_ListenUpdates.cs).
@ -104,7 +104,7 @@ For a Channel/Group:
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null);
var channel = (Channel)chats.chats.First(chat => chat.ID == 1234567890); // the channel we want
var channel = (Channel)chats.chats[1234567890]; // the channel we want
for (int offset = 0; ;)
{
var participants = await client.Channels_GetParticipants(channel, null, offset, 1000, 0);
@ -120,7 +120,7 @@ for (int offset = 0; ;)
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null);
InputPeer peer = chats.chats.First(chat => chat.ID == 1234567890); // the chat we want
InputPeer peer = chats.chats[1234567890]; // the chat we want
for (int offset = 0; ;)
{
var messagesBase = await client.Messages_GetHistory(peer, 0, default, offset, 1000, 0, 0, 0);

View file

@ -32,26 +32,26 @@ namespace WTelegramClientTest
var chats = await client.Messages_GetAllChats(null); // chats = groups/channels (does not include users dialogs)
Console.WriteLine("This user has joined the following:");
foreach (var chat in chats.chats)
foreach (var (id, chat) in chats.chats)
switch (chat)
{
case Chat smallgroup when (smallgroup.flags & Chat.Flags.deactivated) == 0:
Console.WriteLine($"{smallgroup.id}: Small group: {smallgroup.title} with {smallgroup.participants_count} members");
Console.WriteLine($"{id}: Small group: {smallgroup.title} with {smallgroup.participants_count} members");
break;
case Channel channel when (channel.flags & Channel.Flags.broadcast) != 0:
Console.WriteLine($"{channel.id}: Channel {channel.username}: {channel.title}");
Console.WriteLine($"{id}: Channel {channel.username}: {channel.title}");
//Console.WriteLine($" → access_hash = {channel.access_hash:X}");
break;
case Channel group: // no broadcast flag => it's a big group, also called supergroup or megagroup
Console.WriteLine($"{group.id}: Group {group.username}: {group.title}");
Console.WriteLine($"{id}: Group {group.username}: {group.title}");
//Console.WriteLine($" → access_hash = {group.access_hash:X}");
break;
}
Console.Write("Type a chat ID to send a message: ");
long id = long.Parse(Console.ReadLine());
var target = chats.chats.First(chat => chat.ID == id);
Console.WriteLine($"Sending a message in chat {target.ID}: {target.Title}");
long chatId = long.Parse(Console.ReadLine());
var target = chats.chats[chatId];
Console.WriteLine($"Sending a message in chat {chatId}: {target.Title}");
// Next line implicitely creates an adequate InputPeer from ChatBase: (with the access_hash if these is one)
InputPeer peer = target;
await client.SendMessageAsync(peer, "Hello, World");

View file

@ -24,12 +24,11 @@ namespace WTelegramClientTest
if (dialogsBase is Messages_Dialogs dialogs)
while (dialogs.dialogs.Length != 0)
{
foreach (var user in dialogs.users) users[user.ID] = user;
foreach (var chat in dialogs.chats) chats[chat.ID] = chat;
foreach (var (id, user) in dialogs.users) users[id] = user;
foreach (var (id, chat) in dialogs.chats) chats[id] = chat;
var lastDialog = (Dialog)dialogs.dialogs[^1];
var lastMsg = dialogs.messages.LastOrDefault(m => m.Peer.ID == lastDialog.peer.ID && m.ID == lastDialog.top_message);
InputPeer offsetPeer = lastDialog.peer is PeerUser pu ? dialogs.users.First(u => u.ID == pu.ID)
: dialogs.chats.First(u => u.ID == lastDialog.peer.ID);
InputPeer offsetPeer = lastDialog.peer is PeerUser pu ? dialogs.users[pu.ID] : dialogs.chats[lastDialog.peer.ID];
dialogs = (Messages_Dialogs)await client.Messages_GetDialogs(lastMsg?.Date ?? default, lastDialog.top_message, offsetPeer, 500, 0);
}
Console.ReadKey();
@ -53,13 +52,13 @@ namespace WTelegramClientTest
case UpdateShortSentMessage: Console.WriteLine($"You sent a message"); break;
case UpdateShort updateShort: DisplayUpdate(updateShort.update); break;
case Updates u:
foreach (var user in u.users) users[user.ID] = user;
foreach (var chat in u.chats) chats[chat.ID] = chat;
foreach (var (id, user) in u.users) users[id] = user;
foreach (var (id, chat) in u.chats) chats[id] = chat;
foreach (var update in u.updates) DisplayUpdate(update);
break;
case UpdatesCombined uc:
foreach (var user in uc.users) users[user.ID] = user;
foreach (var chat in uc.chats) chats[chat.ID] = chat;
foreach (var (id, user) in uc.users) users[id] = user;
foreach (var (id, chat) in uc.chats) chats[id] = chat;
foreach (var update in uc.updates) DisplayUpdate(update);
break;
default: Console.WriteLine(arg.GetType().Name); break;

View file

@ -76,23 +76,23 @@ using TL;
...
var chats = await client.Messages_GetAllChats(null);
Console.WriteLine("This user has joined the following:");
foreach (var chat in chats.chats)
foreach (var (id, chat) in chats.chats)
switch (chat)
{
case Chat smallgroup when (smallgroup.flags & Chat.Flags.deactivated) == 0:
Console.WriteLine($"{smallgroup.id}: Small group: {smallgroup.title} with {smallgroup.participants_count} members");
Console.WriteLine($"{id}: Small group: {smallgroup.title} with {smallgroup.participants_count} members");
break;
case Channel channel when (channel.flags & Channel.Flags.broadcast) != 0:
Console.WriteLine($"{channel.id}: Channel {channel.username}: {channel.title}");
Console.WriteLine($"{id}: Channel {channel.username}: {channel.title}");
break;
case Channel group:
Console.WriteLine($"{group.id}: Group {group.username}: {group.title}");
Console.WriteLine($"{id}: Group {group.username}: {group.title}");
break;
}
Console.Write("Type a chat ID to send a message: ");
long id = long.Parse(Console.ReadLine());
var target = chats.chats.First(chat => chat.ID == id);
Console.WriteLine($"Sending a message in chat {target.ID}: {target.Title}");
long chatId = long.Parse(Console.ReadLine());
var target = chats.chats[chatId];
Console.WriteLine($"Sending a message in chat {chatId}: {target.Title}");
await client.SendMessageAsync(target, "Hello, World");
```

View file

@ -98,6 +98,7 @@ namespace WTelegram
using var sw = new StreamWriter(outputCs, false, Encoding.UTF8);
sw.WriteLine("// This file is generated automatically using the Generator class");
sw.WriteLine("using System;");
sw.WriteLine("using System.Collections.Generic;");
if (schema.methods.Count != 0) sw.WriteLine("using System.Threading.Tasks;");
sw.WriteLine();
sw.WriteLine("namespace TL");
@ -442,7 +443,13 @@ namespace WTelegram
private string MapType(string type, string name)
{
if (type.StartsWith("Vector<", StringComparison.OrdinalIgnoreCase))
{
if (name == "users" && type == "Vector<User>")
return $"Dictionary<long, " + MapType(type[7..^1], name) + ">";
else if (name == "chats" && type == "Vector<Chat>")
return $"Dictionary<long, " + MapType(type[7..^1], name) + ">";
return MapType(type[7..^1], name) + "[]";
}
else if (type == "Bool")
return "bool";
else if (type == "bytes")
@ -471,7 +478,7 @@ namespace WTelegram
else if (typeInfos.TryGetValue(type, out var typeInfo))
return typeInfo.ReturnName;
else
{ // try to find type in a lower layer
{ // try to find type in a lower layer
/*foreach (var layer in typeInfosByLayer.OrderByDescending(kvp => kvp.Key))
if (layer.Value.TryGetValue(type, out typeInfo))
return layer.Key == 0 ? typeInfo.ReturnName : $"Layer{layer.Key}.{typeInfo.ReturnName}";*/

View file

@ -1,5 +1,6 @@
// This file is generated automatically using the Generator class
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace TL

View file

@ -1,5 +1,6 @@
// This file is generated automatically using the Generator class
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace TL
@ -1257,7 +1258,7 @@ namespace TL
{
public Contact[] contacts;
public int saved_count;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/contacts.importedContacts"/></summary>
@ -1267,7 +1268,7 @@ namespace TL
public ImportedContact[] imported;
public PopularContact[] popular_invites;
public long[] retry_contacts;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/contacts.blocked"/></summary>
@ -1275,8 +1276,8 @@ namespace TL
public partial class Contacts_Blocked : ITLObject
{
public PeerBlocked[] blocked;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/contacts.blockedSlice"/></summary>
[TLDef(0xE1664194, inheritAfter = true)]
@ -1290,8 +1291,8 @@ namespace TL
{
public DialogBase[] dialogs;
public MessageBase[] messages;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.dialogsSlice"/></summary>
[TLDef(0x71E094F3, inheritAfter = true)]
@ -1307,8 +1308,8 @@ namespace TL
public partial class Messages_Messages : Messages_MessagesBase
{
public MessageBase[] messages;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.messagesSlice"/></summary>
[TLDef(0x3A54685E, inheritAfter = true)]
@ -1330,8 +1331,8 @@ namespace TL
public int count;
[IfFlag(2)] public int offset_id_offset;
public MessageBase[] messages;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.messagesNotModified"/></summary>
[TLDef(0x74535F21)]
@ -1339,7 +1340,7 @@ namespace TL
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.chats"/></summary>
[TLDef(0x64FF9FD5)]
public partial class Messages_Chats : ITLObject { public ChatBase[] chats; }
public partial class Messages_Chats : ITLObject { public Dictionary<long, ChatBase> chats; }
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.chatsSlice"/></summary>
[TLDef(0x9CD81144, inheritAfter = true)]
public partial class Messages_ChatsSlice : Messages_Chats { public int count; }
@ -1349,8 +1350,8 @@ namespace TL
public partial class Messages_ChatFull : ITLObject
{
public ChatFullBase full_chat;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.affectedHistory"/></summary>
@ -2102,8 +2103,8 @@ namespace TL
public MessageBase[] new_messages;
public EncryptedMessageBase[] new_encrypted_messages;
public Update[] other_updates;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
public Updates_State state;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/updates.differenceSlice"/></summary>
@ -2113,8 +2114,8 @@ namespace TL
public MessageBase[] new_messages;
public EncryptedMessageBase[] new_encrypted_messages;
public Update[] other_updates;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
public Updates_State intermediate_state;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/updates.differenceTooLong"/></summary>
@ -2177,8 +2178,8 @@ namespace TL
public partial class UpdatesCombined : UpdatesBase
{
public Update[] updates;
public UserBase[] users;
public ChatBase[] chats;
public Dictionary<long, UserBase> users;
public Dictionary<long, ChatBase> chats;
public DateTime date;
public int seq_start;
public int seq;
@ -2188,8 +2189,8 @@ namespace TL
public partial class Updates : UpdatesBase
{
public Update[] updates;
public UserBase[] users;
public ChatBase[] chats;
public Dictionary<long, UserBase> users;
public Dictionary<long, ChatBase> chats;
public DateTime date;
public int seq;
}
@ -2213,7 +2214,7 @@ namespace TL
public partial class Photos_Photos : ITLObject
{
public PhotoBase[] photos;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/photos.photosSlice"/></summary>
[TLDef(0x15051F54, inheritAfter = true)]
@ -2224,7 +2225,7 @@ namespace TL
public partial class Photos_Photo : ITLObject
{
public PhotoBase photo;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/type/upload.File"/></summary>
@ -2609,8 +2610,8 @@ namespace TL
{
public Peer[] my_results;
public Peer[] results;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/type/InputPrivacyKey"/></summary>
@ -2714,8 +2715,8 @@ namespace TL
public partial class Account_PrivacyRules : ITLObject
{
public PrivacyRule[] rules;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/accountDaysTTL"/></summary>
@ -3229,8 +3230,8 @@ namespace TL
public partial class Contacts_ResolvedPeer : ITLObject
{
public Peer peer;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messageRange"/></summary>
@ -3261,8 +3262,8 @@ namespace TL
[IfFlag(1)] public int timeout;
public DialogBase dialog;
public MessageBase[] messages;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/updates.channelDifference"/></summary>
[TLDef(0x2064674E)]
@ -3274,8 +3275,8 @@ namespace TL
[IfFlag(1)] public int timeout;
public MessageBase[] new_messages;
public Update[] other_updates;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/channelMessagesFilter"/></summary>
@ -3383,8 +3384,8 @@ namespace TL
{
public int count;
public ChannelParticipantBase[] participants;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/channels.channelParticipant"/></summary>
@ -3392,8 +3393,8 @@ namespace TL
public partial class Channels_ChannelParticipant : ITLObject
{
public ChannelParticipantBase participant;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/help.termsOfService"/></summary>
@ -3655,7 +3656,7 @@ namespace TL
[IfFlag(2)] public InlineBotSwitchPM switch_pm;
public BotInlineResultBase[] results;
public DateTime cache_time;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/exportedMessageLink"/></summary>
@ -3762,8 +3763,8 @@ namespace TL
{
public DialogBase[] dialogs;
public MessageBase[] messages;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
public Updates_State state;
}
@ -3813,8 +3814,8 @@ namespace TL
public partial class Contacts_TopPeers : Contacts_TopPeersBase
{
public TopPeerCategoryPeers[] categories;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/contacts.topPeersDisabled"/></summary>
[TLDef(0xB52C939D)]
@ -3967,7 +3968,7 @@ namespace TL
public partial class Messages_HighScores : ITLObject
{
public HighScore[] scores;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/type/RichText"/></summary>
@ -4377,7 +4378,7 @@ namespace TL
[IfFlag(4)] public DataJSON native_params;
[IfFlag(0)] public PaymentRequestedInfo saved_info;
[IfFlag(1)] public PaymentSavedCredentials saved_credentials;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/payments.validatedRequestedInfo"/></summary>
@ -4418,7 +4419,7 @@ namespace TL
public string currency;
public long total_amount;
public string credentials_title;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/payments.savedInfo"/></summary>
@ -4607,7 +4608,7 @@ namespace TL
public partial class Phone_PhoneCall : ITLObject
{
public PhoneCallBase phone_call;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/type/upload.CdnFile"/></summary>
@ -4862,8 +4863,8 @@ namespace TL
public partial class Channels_AdminLogResults : ITLObject
{
public ChannelAdminLogEvent[] events;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/channelAdminLogEventsFilter"/></summary>
@ -4917,8 +4918,8 @@ namespace TL
public partial class Help_RecentMeUrls : ITLObject
{
public RecentMeUrl[] urls;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/inputSingleMedia"/></summary>
@ -4953,7 +4954,7 @@ namespace TL
public partial class Account_WebAuthorizations : ITLObject
{
public WebAuthorization[] authorizations;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/type/InputMessage"/></summary>
@ -5242,7 +5243,7 @@ namespace TL
public SecureRequiredTypeBase[] required_types;
public SecureValue[] values;
public SecureValueErrorBase[] errors;
public UserBase[] users;
public Dictionary<long, UserBase> users;
[IfFlag(0)] public string privacy_policy_url;
}
@ -5804,8 +5805,8 @@ namespace TL
public partial class Messages_InactiveChats : ITLObject
{
public int[] dates;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/type/BaseTheme"/></summary>
@ -5898,7 +5899,7 @@ namespace TL
public Flags flags;
public int count;
public MessageUserVoteBase[] votes;
public UserBase[] users;
public Dictionary<long, UserBase> users;
[IfFlag(0)] public string next_offset;
}
@ -6026,8 +6027,8 @@ namespace TL
public Flags flags;
public DateTime expires;
public Peer peer;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
[IfFlag(1)] public string psa_type;
[IfFlag(2)] public string psa_message;
}
@ -6092,7 +6093,7 @@ namespace TL
public StatsGroupTopPoster[] top_posters;
public StatsGroupTopAdmin[] top_admins;
public StatsGroupTopInviter[] top_inviters;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/globalPrivacySettings"/></summary>
@ -6152,8 +6153,8 @@ namespace TL
public partial class Messages_MessageViews : ITLObject
{
public MessageViews[] views;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.discussionMessage"/></summary>
@ -6167,8 +6168,8 @@ namespace TL
[IfFlag(1)] public int read_inbox_max_id;
[IfFlag(2)] public int read_outbox_max_id;
public int unread_count;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messageReplyHeader"/></summary>
@ -6272,8 +6273,8 @@ namespace TL
public GroupCallBase call;
public GroupCallParticipant[] participants;
public string participants_next_offset;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/phone.groupParticipants"/></summary>
@ -6283,8 +6284,8 @@ namespace TL
public int count;
public GroupCallParticipant[] participants;
public string next_offset;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
public int version;
}
@ -6340,7 +6341,7 @@ namespace TL
{
public int count;
public ExportedChatInvite[] invites;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/type/messages.ExportedChatInvite"/></summary>
@ -6350,7 +6351,7 @@ namespace TL
public partial class Messages_ExportedChatInvite : Messages_ExportedChatInviteBase
{
public ExportedChatInvite invite;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.exportedChatInviteReplaced"/></summary>
[TLDef(0x222600EF)]
@ -6358,7 +6359,7 @@ namespace TL
{
public ExportedChatInvite invite;
public ExportedChatInvite new_invite;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.chatInviteImporters"/></summary>
@ -6367,7 +6368,7 @@ namespace TL
{
public int count;
public ChatInviteImporter[] importers;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/chatAdminWithInvites"/></summary>
@ -6384,7 +6385,7 @@ namespace TL
public partial class Messages_ChatAdminsWithInvites : ITLObject
{
public ChatAdminWithInvites[] admins;
public UserBase[] users;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/messages.checkedHistoryImportPeer"/></summary>
@ -6396,8 +6397,8 @@ namespace TL
public partial class Phone_JoinAsPeers : ITLObject
{
public Peer[] peers;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
///<summary>See <a href="https://corefork.telegram.org/constructor/phone.exportedGroupCallInvite"/></summary>
@ -6499,8 +6500,8 @@ namespace TL
public partial class Messages_SponsoredMessages : ITLObject
{
public SponsoredMessage[] messages;
public ChatBase[] chats;
public UserBase[] users;
public Dictionary<long, ChatBase> chats;
public Dictionary<long, UserBase> users;
}
// ---functions---

View file

@ -1,5 +1,6 @@
// This file is generated automatically using the Generator class
using System;
using System.Collections.Generic;
namespace TL
{

View file

@ -141,6 +141,10 @@ namespace TL
return new Int128(reader);
else if (type == typeof(Int256))
return new Int256(reader);
else if (type == typeof(Dictionary<long, UserBase>))
return reader.ReadTLDictionary<UserBase>(u => u.ID);
else if (type == typeof(Dictionary<long, ChatBase>))
return reader.ReadTLDictionary<ChatBase>(c => c.ID);
else
return reader.ReadTLObject();
default:
@ -184,6 +188,22 @@ namespace TL
throw new ApplicationException($"Cannot deserialize {type.Name} with ctor #{ctorNb:x}");
}
internal static Dictionary<long, T> ReadTLDictionary<T>(this BinaryReader reader, Func<T, long> getID)
{
uint ctorNb = reader.ReadUInt32();
var elementType = typeof(T);
if (ctorNb != Layer.VectorCtor)
throw new ApplicationException($"Cannot deserialize Vector<{elementType.Name}> with ctor #{ctorNb:x}");
int count = reader.ReadInt32();
var dict = new Dictionary<long, T>(count);
for (int i = 0; i < count; i++)
{
var value = (T)reader.ReadTLValue(elementType);
dict.Add(getID(value), value);
}
return dict;
}
internal static void WriteTLStamp(this BinaryWriter writer, DateTime datetime)
=> writer.Write(datetime == DateTime.MaxValue ? int.MaxValue : (int)(datetime.ToUniversalTime().Ticks / 10000000 - 62135596800L));