updated example Programs.cs

This commit is contained in:
Wizou 2022-02-13 03:15:23 +01:00
parent 34f05f5947
commit 0667d36ed8
5 changed files with 4 additions and 8 deletions

3
.github/dev.yml vendored
View file

@ -2,7 +2,7 @@ pr: none
trigger:
- master
name: 2.1.1-dev.$(Rev:r)
name: 2.1.2-dev.$(Rev:r)
pool:
vmImage: ubuntu-latest
@ -36,4 +36,3 @@ steps:
nuGetFeedType: 'internal'
publishVstsFeed: 'WTelegramClient/WTelegramClient'

View file

@ -32,7 +32,6 @@ namespace WTelegramClientTest
}
Console.WriteLine("Connecting to Telegram...");
await client.ConnectAsync();
await client.LoginUserIfNeeded();
var durovAccessHash = client.GetAccessHashFor<Channel>(DurovID);

View file

@ -14,7 +14,6 @@ namespace WTelegramClientTest
{
Console.WriteLine("The program will download photos/medias from messages you send/forward to yourself (Saved Messages)");
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.ConnectAsync();
var user = await client.LoginUserIfNeeded();
client.Update += Client_Update;
Console.ReadKey();

View file

@ -26,11 +26,10 @@ namespace WTelegramClientTest
static async Task Main(string[] _)
{
using var client = new WTelegram.Client(Config);
await client.ConnectAsync();
var user = await client.LoginUserIfNeeded();
Console.WriteLine($"We are logged-in as {user.username ?? user.first_name + " " + user.last_name} (id {user.id})");
var chats = await client.Messages_GetAllChats(null); // chats = groups/channels (does not include users dialogs)
var chats = await client.Messages_GetAllChats(); // chats = groups/channels (does not include users dialogs)
Console.WriteLine("This user has joined the following:");
foreach (var (id, chat) in chats.chats)
switch (chat)

View file

@ -25,7 +25,7 @@ namespace WTelegramClientTest
// Note that on login Telegram may sends a bunch of updates/messages that happened in the past and were not acknowledged
Console.WriteLine($"We are logged-in as {My.username ?? My.first_name + " " + My.last_name} (id {My.id})");
// We collect all infos about the users/chats so that updates can be printed with their names
var dialogsBase = await Client.Messages_GetDialogs(default, 0, null, 0, 0); // dialogs = groups/channels/users
var dialogsBase = await Client.Messages_GetDialogs(); // dialogs = groups/channels/users
if (dialogsBase is Messages_Dialogs dialogs)
while (dialogs.dialogs.Length != 0)
{
@ -34,7 +34,7 @@ namespace WTelegramClientTest
var lastDialog = dialogs.dialogs[^1];
var lastMsg = dialogs.messages.LastOrDefault(m => m.Peer.ID == lastDialog.Peer.ID && m.ID == lastDialog.TopMessage);
var offsetPeer = dialogs.UserOrChat(lastDialog).ToInputPeer();
dialogs = (Messages_Dialogs)await Client.Messages_GetDialogs(lastMsg?.Date ?? default, lastDialog.TopMessage, offsetPeer, 500, 0);
dialogs = (Messages_Dialogs)await Client.Messages_GetDialogs(lastMsg?.Date ?? default, lastDialog.TopMessage, offsetPeer);
}
Console.ReadKey();
}