mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
added Channel.MainUsername helper | simplified GetAllChats example
This commit is contained in:
parent
750dbef33b
commit
014f563b89
|
|
@ -34,10 +34,10 @@ namespace WTelegramClientTest
|
|||
foreach (var (id, chat) in chats.chats)
|
||||
switch (chat)
|
||||
{
|
||||
case Chat smallgroup when (smallgroup.flags & Chat.Flags.deactivated) == 0:
|
||||
case Chat smallgroup when smallgroup.IsActive:
|
||||
Console.WriteLine($"{id}: Small group: {smallgroup.title} with {smallgroup.participants_count} members");
|
||||
break;
|
||||
case Channel channel when (channel.flags & Channel.Flags.broadcast) != 0:
|
||||
case Channel channel when channel.IsChannel:
|
||||
Console.WriteLine($"{id}: Channel {channel.username}: {channel.title}");
|
||||
//Console.WriteLine($" → access_hash = {channel.access_hash:X}");
|
||||
break;
|
||||
|
|
|
|||
16
README.md
16
README.md
|
|
@ -129,18 +129,8 @@ using TL;
|
|||
var chats = await client.Messages_GetAllChats();
|
||||
Console.WriteLine("This user has joined the following:");
|
||||
foreach (var (id, chat) in chats.chats)
|
||||
switch (chat) // example of downcasting to their real classes:
|
||||
{
|
||||
case Chat basicChat when basicChat.IsActive:
|
||||
Console.WriteLine($"{id}: Basic chat: {basicChat.title}");
|
||||
break;
|
||||
case Channel group when group.IsGroup:
|
||||
Console.WriteLine($"{id}: Group {group.username}: {group.title}");
|
||||
break;
|
||||
case Channel channel:
|
||||
Console.WriteLine($"{id}: Channel {channel.username}: {channel.title}");
|
||||
break;
|
||||
}
|
||||
if (chat.IsActive)
|
||||
Console.WriteLine($"{id,10}: {chat}");
|
||||
Console.Write("Type a chat ID to send a message: ");
|
||||
long chatId = long.Parse(Console.ReadLine());
|
||||
var target = chats.chats[chatId];
|
||||
|
|
@ -149,7 +139,7 @@ await client.SendMessageAsync(target, "Hello, World");
|
|||
```
|
||||
|
||||
➡️ You can find lots of useful code snippets in [EXAMPLES](https://wiz0u.github.io/WTelegramClient/EXAMPLES)
|
||||
and in the [Examples subdirectory](https://github.com/wiz0u/WTelegramClient/tree/master/Examples).
|
||||
and more detailed programs in the [Examples subdirectory](https://github.com/wiz0u/WTelegramClient/tree/master/Examples).
|
||||
➡️ Check [the FAQ](https://wiz0u.github.io/WTelegramClient/FAQ#compile) if example codes don't compile correctly on your machine, or other troubleshooting.
|
||||
|
||||
<a name="terminology"></a>
|
||||
|
|
|
|||
|
|
@ -216,6 +216,7 @@ namespace TL
|
|||
partial class Channel
|
||||
{
|
||||
public override bool IsActive => (flags & Flags.left) == 0;
|
||||
public string MainUsername => username ?? usernames?.FirstOrDefault(u => u.flags.HasFlag(Username.Flags.active))?.username;
|
||||
public override ChatPhoto Photo => photo;
|
||||
public override bool IsBanned(ChatBannedRights.Flags flags = 0) => ((banned_rights?.flags ?? 0) & flags) != 0 || ((default_banned_rights?.flags ?? 0) & flags) != 0;
|
||||
public override InputPeer ToInputPeer() => new InputPeerChannel(id, access_hash);
|
||||
|
|
|
|||
Loading…
Reference in a new issue