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: trigger:
- master - master
name: 1.3.2-ci.$(Rev:r) name: 1.4.1-ci.$(Rev:r)
pool: pool:
vmImage: ubuntu-latest 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); using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded(); await client.LoginUserIfNeeded();
var resolved = await client.Contacts_ResolveUsername("USERNAME"); 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 ### Send a message to someone by phone number
```csharp ```csharp
@ -25,19 +25,20 @@ await client.LoginUserIfNeeded();
var imported = await client.Contacts_ImportContacts(new[] { new InputPhoneContact { phone = "+PHONENUMBER" } }); var imported = await client.Contacts_ImportContacts(new[] { new InputPhoneContact { phone = "+PHONENUMBER" } });
await client.SendMessageAsync(imported.users[0], "Hello!"); 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 ### List all chats (groups/channels) the user is in and send a message to one
```csharp ```csharp
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable); using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded(); await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null); var chats = await client.Messages_GetAllChats(null);
foreach (var chat in chats.chats) foreach (var (id, chat) in chats.chats)
Console.WriteLine($"{chat.ID} : {chat}"); Console.WriteLine($"{id} : {chat}");
Console.Write("Choose a chat ID to send a message to: "); Console.Write("Choose a chat ID to send a message to: ");
long id = long.Parse(Console.ReadLine()); long chatId = long.Parse(Console.ReadLine());
var target = chats.chats.First(chat => chat.ID == id); await client.SendMessageAsync(chats.chats[chatId], "Hello, World");
await client.SendMessageAsync(target, "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/> <br/>
See a longer version of this example in [Examples/Program_GetAllChats.cs](Examples/Program_GetAllChats.cs) 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); using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded(); await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null); 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); DateTime when = DateTime.UtcNow.AddMinutes(3);
await client.SendMessageAsync(peer, "This will be posted in 3 minutes", schedule_date: when); 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); using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded(); await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null); 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); var inputFile = await client.UploadFileAsync(Filepath);
await client.SendMediaAsync(peer, "Here is the photo", inputFile); await client.SendMediaAsync(peer, "Here is the photo", inputFile);
``` ```
@ -66,7 +67,7 @@ await client.SendMediaAsync(peer, "Here is the photo", inputFile);
```csharp ```csharp
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable); using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded(); 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) if (dialogsBase is Messages_Dialogs dialogs)
while (dialogs.dialogs.Length != 0) 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)) if (dialog is Dialog { peer: var peer } || (dialog is DialogFolder dialogFolder && (peer = dialogFolder.peer) != null))
switch (peer) switch (peer)
{ {
case PeerUser: Console.WriteLine("User " + dialogs.users.First(u => u.ID == peer.ID)); break; case PeerUser: Console.WriteLine("User " + dialogs.users[peer.ID]); break;
case PeerChannel or PeerChat: Console.WriteLine(dialogs.chats.First(c => c.ID == peer.ID)); break; case PeerChannel or PeerChat: Console.WriteLine(dialogs.chats[peer.ID]); break;
} }
var lastDialog = (Dialog)dialogs.dialogs[^1]; var lastDialog = (Dialog)dialogs.dialogs[^1];
var lastMsg = dialogs.messages.LastOrDefault(m => m.Peer.ID == lastDialog.peer.ID && m.ID == lastDialog.top_message); 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) InputPeer offsetPeer = lastDialog.peer is PeerUser pu ? dialogs.users[pu.ID] : dialogs.chats[lastDialog.peer.ID];
: dialogs.chats.First(u => u.ID == lastDialog.peer.ID);
dialogs = (Messages_Dialogs)await client.Messages_GetDialogs(lastMsg?.Date ?? default, lastDialog.top_message, offsetPeer, 500, 0); 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/> <br/>
See also the `Main` method in [Examples/Program_ListenUpdates.cs](Examples/Program_ListenUpdates.cs). 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); using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded(); await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null); 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; ;) for (int offset = 0; ;)
{ {
var participants = await client.Channels_GetParticipants(channel, null, offset, 1000, 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); using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded(); await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null); 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; ;) for (int offset = 0; ;)
{ {
var messagesBase = await client.Messages_GetHistory(peer, 0, default, offset, 1000, 0, 0, 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) var chats = await client.Messages_GetAllChats(null); // chats = groups/channels (does not include users dialogs)
Console.WriteLine("This user has joined the following:"); Console.WriteLine("This user has joined the following:");
foreach (var chat in chats.chats) foreach (var (id, chat) in chats.chats)
switch (chat) switch (chat)
{ {
case Chat smallgroup when (smallgroup.flags & Chat.Flags.deactivated) == 0: 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; break;
case Channel channel when (channel.flags & Channel.Flags.broadcast) != 0: 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}"); //Console.WriteLine($" → access_hash = {channel.access_hash:X}");
break; break;
case Channel group: // no broadcast flag => it's a big group, also called supergroup or megagroup 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}"); //Console.WriteLine($" → access_hash = {group.access_hash:X}");
break; break;
} }
Console.Write("Type a chat ID to send a message: "); Console.Write("Type a chat ID to send a message: ");
long id = long.Parse(Console.ReadLine()); long chatId = long.Parse(Console.ReadLine());
var target = chats.chats.First(chat => chat.ID == id); var target = chats.chats[chatId];
Console.WriteLine($"Sending a message in chat {target.ID}: {target.Title}"); 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) // Next line implicitely creates an adequate InputPeer from ChatBase: (with the access_hash if these is one)
InputPeer peer = target; InputPeer peer = target;
await client.SendMessageAsync(peer, "Hello, World"); await client.SendMessageAsync(peer, "Hello, World");

View file

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

View file

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

View file

@ -98,6 +98,7 @@ namespace WTelegram
using var sw = new StreamWriter(outputCs, false, Encoding.UTF8); using var sw = new StreamWriter(outputCs, false, Encoding.UTF8);
sw.WriteLine("// This file is generated automatically using the Generator class"); sw.WriteLine("// This file is generated automatically using the Generator class");
sw.WriteLine("using System;"); sw.WriteLine("using System;");
sw.WriteLine("using System.Collections.Generic;");
if (schema.methods.Count != 0) sw.WriteLine("using System.Threading.Tasks;"); if (schema.methods.Count != 0) sw.WriteLine("using System.Threading.Tasks;");
sw.WriteLine(); sw.WriteLine();
sw.WriteLine("namespace TL"); sw.WriteLine("namespace TL");
@ -442,7 +443,13 @@ namespace WTelegram
private string MapType(string type, string name) private string MapType(string type, string name)
{ {
if (type.StartsWith("Vector<", StringComparison.OrdinalIgnoreCase)) 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) + "[]"; return MapType(type[7..^1], name) + "[]";
}
else if (type == "Bool") else if (type == "Bool")
return "bool"; return "bool";
else if (type == "bytes") else if (type == "bytes")

View file

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

View file

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

View file

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

View file

@ -141,6 +141,10 @@ namespace TL
return new Int128(reader); return new Int128(reader);
else if (type == typeof(Int256)) else if (type == typeof(Int256))
return new Int256(reader); 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 else
return reader.ReadTLObject(); return reader.ReadTLObject();
default: default:
@ -184,6 +188,22 @@ namespace TL
throw new ApplicationException($"Cannot deserialize {type.Name} with ctor #{ctorNb:x}"); 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) internal static void WriteTLStamp(this BinaryWriter writer, DateTime datetime)
=> writer.Write(datetime == DateTime.MaxValue ? int.MaxValue : (int)(datetime.ToUniversalTime().Ticks / 10000000 - 62135596800L)); => writer.Write(datetime == DateTime.MaxValue ? int.MaxValue : (int)(datetime.ToUniversalTime().Ticks / 10000000 - 62135596800L));