mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2026-04-05 06:25:30 +00:00
More helpers to generically manage Chats & Channels
This commit is contained in:
parent
e3b7d17d2b
commit
024c5ba705
4 changed files with 76 additions and 14 deletions
|
|
@ -1523,12 +1523,78 @@ namespace WTelegram
|
|||
}
|
||||
}
|
||||
|
||||
public Task<UpdatesBase> AddChatUser(InputPeer peer, InputUserBase user, int fwd_limit = int.MaxValue) => peer switch
|
||||
{
|
||||
InputPeerChat chat => this.Messages_AddChatUser(chat.chat_id, user, fwd_limit),
|
||||
InputPeerChannel channel => this.Channels_InviteToChannel(channel, new[] { user }),
|
||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
||||
};
|
||||
|
||||
public Task<UpdatesBase> DeleteChatUser(InputPeer peer, InputUser user, bool revoke_history = true) => peer switch
|
||||
{
|
||||
InputPeerChat chat => this.Messages_DeleteChatUser(chat.chat_id, user, revoke_history),
|
||||
InputPeerChannel channel => this.Channels_EditBanned(channel, user, new ChatBannedRights { flags = ChatBannedRights.Flags.view_messages }),
|
||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
||||
};
|
||||
|
||||
public Task<UpdatesBase> LeaveChat(InputPeer peer, bool revoke_history = true) => peer switch
|
||||
{
|
||||
InputPeerChat chat => this.Messages_DeleteChatUser(chat.chat_id, InputUser.Self, revoke_history),
|
||||
InputPeerChannel channel => this.Channels_LeaveChannel(channel),
|
||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
||||
};
|
||||
|
||||
public async Task<UpdatesBase> EditChatAdmin(InputPeer peer, InputUserBase user, bool is_admin)
|
||||
{
|
||||
switch (peer)
|
||||
{
|
||||
case InputPeerChat chat:
|
||||
await this.Messages_EditChatAdmin(chat.chat_id, user, is_admin);
|
||||
return new Updates { date = DateTime.UtcNow, users = new(), updates = Array.Empty<Update>(),
|
||||
chats = (await this.Messages_GetChats(new[] { chat.chat_id })).chats };
|
||||
case InputPeerChannel channel:
|
||||
return await this.Channels_EditAdmin(channel, user,
|
||||
new ChatAdminRights { flags = is_admin ? (ChatAdminRights.Flags)0x8BF : 0 }, null);
|
||||
default:
|
||||
throw new ArgumentException("This method works on Chat & Channel only");
|
||||
}
|
||||
}
|
||||
|
||||
public Task<UpdatesBase> EditChatPhoto(InputPeer peer, InputChatPhotoBase photo) => peer switch
|
||||
{
|
||||
InputPeerChat chat => this.Messages_EditChatPhoto(chat.chat_id, photo),
|
||||
InputPeerChannel channel => this.Channels_EditPhoto(channel, photo),
|
||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
||||
};
|
||||
|
||||
public Task<UpdatesBase> EditChatTitle(InputPeer peer, string title) => peer switch
|
||||
{
|
||||
InputPeerChat chat => this.Messages_EditChatTitle(chat.chat_id, title),
|
||||
InputPeerChannel channel => this.Channels_EditTitle(channel, title),
|
||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
||||
};
|
||||
|
||||
public Task<Messages_ChatFull> GetFullChat(InputPeer peer) => peer switch
|
||||
{
|
||||
InputPeerChat chat => this.Messages_GetFullChat(chat.chat_id),
|
||||
InputPeerChannel channel => this.Channels_GetFullChannel(channel),
|
||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
||||
};
|
||||
|
||||
public async Task<UpdatesBase> DeleteChat(InputPeer peer)
|
||||
{
|
||||
switch (peer)
|
||||
{
|
||||
case InputPeerChat chat:
|
||||
await this.Messages_DeleteChat(chat.chat_id);
|
||||
return new Updates { date = DateTime.UtcNow, users = new(), updates = Array.Empty<Update>(),
|
||||
chats = (await this.Messages_GetChats(new[] { chat.chat_id })).chats };
|
||||
case InputPeerChannel channel:
|
||||
return await this.Channels_DeleteChannel(channel);
|
||||
default:
|
||||
throw new ArgumentException("This method works on Chat & Channel only");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ namespace WTelegram
|
|||
}
|
||||
|
||||
[TLDef(0x7A19CB76)] //RSA_public_key#7a19cb76 n:bytes e:bytes = RSAPublicKey
|
||||
public partial class RSAPublicKey : IObject { public byte[] n, e; }
|
||||
public class RSAPublicKey : IObject { public byte[] n, e; }
|
||||
|
||||
public static void LoadPublicKey(string pem)
|
||||
{
|
||||
|
|
|
|||
10
src/TL.cs
10
src/TL.cs
|
|
@ -370,7 +370,7 @@ namespace TL
|
|||
// Below TL types are commented "parsed manually" from https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/Resources/tl/mtproto.tl
|
||||
|
||||
[TLDef(0xF35C6D01)] //rpc_result#f35c6d01 req_msg_id:long result:Object = RpcResult
|
||||
public partial class RpcResult : IObject
|
||||
public class RpcResult : IObject
|
||||
{
|
||||
public long req_msg_id;
|
||||
public object result;
|
||||
|
|
@ -378,7 +378,7 @@ namespace TL
|
|||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006")]
|
||||
[TLDef(0x5BB8E511)] //message#5bb8e511 msg_id:long seqno:int bytes:int body:Object = Message
|
||||
public partial class _Message
|
||||
public class _Message
|
||||
{
|
||||
public long msg_id;
|
||||
public int seqno;
|
||||
|
|
@ -387,10 +387,10 @@ namespace TL
|
|||
}
|
||||
|
||||
[TLDef(0x73F1F8DC)] //msg_container#73f1f8dc messages:vector<%Message> = MessageContainer
|
||||
public partial class MsgContainer : IObject { public _Message[] messages; }
|
||||
public class MsgContainer : IObject { public _Message[] messages; }
|
||||
[TLDef(0xE06046B2)] //msg_copy#e06046b2 orig_message:Message = MessageCopy
|
||||
public partial class MsgCopy : IObject { public _Message orig_message; }
|
||||
public class MsgCopy : IObject { public _Message orig_message; }
|
||||
|
||||
[TLDef(0x3072CFA1)] //gzip_packed#3072cfa1 packed_data:bytes = Object
|
||||
public partial class GzipPacked : IObject { public byte[] packed_data; }
|
||||
public class GzipPacked : IObject { public byte[] packed_data; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue