mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
implicit operator InputDialogPeer from InputPeer
This commit is contained in:
parent
280bc3c411
commit
10c159b2d3
|
|
@ -574,25 +574,26 @@ namespace WTelegram
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const string OnlyChatChannel = "This method works on Chat & Channel only";
|
||||||
public Task<UpdatesBase> AddChatUser(InputPeer peer, InputUserBase user, int fwd_limit = int.MaxValue) => peer switch
|
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),
|
InputPeerChat chat => this.Messages_AddChatUser(chat.chat_id, user, fwd_limit),
|
||||||
InputPeerChannel channel => this.Channels_InviteToChannel(channel, new[] { user }),
|
InputPeerChannel channel => this.Channels_InviteToChannel(channel, new[] { user }),
|
||||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
_ => throw new ArgumentException(OnlyChatChannel),
|
||||||
};
|
};
|
||||||
|
|
||||||
public Task<UpdatesBase> DeleteChatUser(InputPeer peer, InputUser user) => peer switch
|
public Task<UpdatesBase> DeleteChatUser(InputPeer peer, InputUser user) => peer switch
|
||||||
{
|
{
|
||||||
InputPeerChat chat => this.Messages_DeleteChatUser(chat.chat_id, user, true),
|
InputPeerChat chat => this.Messages_DeleteChatUser(chat.chat_id, user, true),
|
||||||
InputPeerChannel channel => this.Channels_EditBanned(channel, user, new ChatBannedRights { flags = ChatBannedRights.Flags.view_messages }),
|
InputPeerChannel channel => this.Channels_EditBanned(channel, user, new ChatBannedRights { flags = ChatBannedRights.Flags.view_messages }),
|
||||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
_ => throw new ArgumentException(OnlyChatChannel),
|
||||||
};
|
};
|
||||||
|
|
||||||
public Task<UpdatesBase> LeaveChat(InputPeer peer) => peer switch
|
public Task<UpdatesBase> LeaveChat(InputPeer peer) => peer switch
|
||||||
{
|
{
|
||||||
InputPeerChat chat => this.Messages_DeleteChatUser(chat.chat_id, InputUser.Self, true),
|
InputPeerChat chat => this.Messages_DeleteChatUser(chat.chat_id, InputUser.Self, true),
|
||||||
InputPeerChannel channel => this.Channels_LeaveChannel(channel),
|
InputPeerChannel channel => this.Channels_LeaveChannel(channel),
|
||||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
_ => throw new ArgumentException(OnlyChatChannel),
|
||||||
};
|
};
|
||||||
|
|
||||||
public async Task<UpdatesBase> EditChatAdmin(InputPeer peer, InputUserBase user, bool is_admin)
|
public async Task<UpdatesBase> EditChatAdmin(InputPeer peer, InputUserBase user, bool is_admin)
|
||||||
|
|
@ -607,7 +608,7 @@ namespace WTelegram
|
||||||
return await this.Channels_EditAdmin(channel, user,
|
return await this.Channels_EditAdmin(channel, user,
|
||||||
new ChatAdminRights { flags = is_admin ? (ChatAdminRights.Flags)0x8BF : 0 }, null);
|
new ChatAdminRights { flags = is_admin ? (ChatAdminRights.Flags)0x8BF : 0 }, null);
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException("This method works on Chat & Channel only");
|
throw new ArgumentException(OnlyChatChannel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -615,21 +616,21 @@ namespace WTelegram
|
||||||
{
|
{
|
||||||
InputPeerChat chat => this.Messages_EditChatPhoto(chat.chat_id, photo),
|
InputPeerChat chat => this.Messages_EditChatPhoto(chat.chat_id, photo),
|
||||||
InputPeerChannel channel => this.Channels_EditPhoto(channel, photo),
|
InputPeerChannel channel => this.Channels_EditPhoto(channel, photo),
|
||||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
_ => throw new ArgumentException(OnlyChatChannel),
|
||||||
};
|
};
|
||||||
|
|
||||||
public Task<UpdatesBase> EditChatTitle(InputPeer peer, string title) => peer switch
|
public Task<UpdatesBase> EditChatTitle(InputPeer peer, string title) => peer switch
|
||||||
{
|
{
|
||||||
InputPeerChat chat => this.Messages_EditChatTitle(chat.chat_id, title),
|
InputPeerChat chat => this.Messages_EditChatTitle(chat.chat_id, title),
|
||||||
InputPeerChannel channel => this.Channels_EditTitle(channel, title),
|
InputPeerChannel channel => this.Channels_EditTitle(channel, title),
|
||||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
_ => throw new ArgumentException(OnlyChatChannel),
|
||||||
};
|
};
|
||||||
|
|
||||||
public Task<Messages_ChatFull> GetFullChat(InputPeer peer) => peer switch
|
public Task<Messages_ChatFull> GetFullChat(InputPeer peer) => peer switch
|
||||||
{
|
{
|
||||||
InputPeerChat chat => this.Messages_GetFullChat(chat.chat_id),
|
InputPeerChat chat => this.Messages_GetFullChat(chat.chat_id),
|
||||||
InputPeerChannel channel => this.Channels_GetFullChannel(channel),
|
InputPeerChannel channel => this.Channels_GetFullChannel(channel),
|
||||||
_ => throw new ArgumentException("This method works on Chat & Channel only"),
|
_ => throw new ArgumentException(OnlyChatChannel),
|
||||||
};
|
};
|
||||||
|
|
||||||
public async Task<UpdatesBase> DeleteChat(InputPeer peer)
|
public async Task<UpdatesBase> DeleteChat(InputPeer peer)
|
||||||
|
|
@ -643,25 +644,15 @@ namespace WTelegram
|
||||||
case InputPeerChannel channel:
|
case InputPeerChannel channel:
|
||||||
return await this.Channels_DeleteChannel(channel);
|
return await this.Channels_DeleteChannel(channel);
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException("This method works on Chat & Channel only");
|
throw new ArgumentException(OnlyChatChannel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Messages_MessagesBase> GetMessages(InputPeer peer, params InputMessage[] id)
|
public Task<Messages_MessagesBase> GetMessages(InputPeer peer, params InputMessage[] id)
|
||||||
{
|
=> peer is InputPeerChannel channel ? this.Channels_GetMessages(channel, id) : this.Messages_GetMessages(id);
|
||||||
if (peer is InputPeerChannel channel)
|
|
||||||
return await this.Channels_GetMessages(channel, id);
|
|
||||||
else
|
|
||||||
return await this.Messages_GetMessages(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Messages_AffectedMessages> DeleteMessages(InputPeer peer, params int[] id)
|
public Task<Messages_AffectedMessages> DeleteMessages(InputPeer peer, params int[] id)
|
||||||
{
|
=> peer is InputPeerChannel channel ? this.Channels_DeleteMessages(channel, id) : this.Messages_DeleteMessages(id);
|
||||||
if (peer is InputPeerChannel channel)
|
|
||||||
return await this.Channels_DeleteMessages(channel, id);
|
|
||||||
else
|
|
||||||
return await this.Messages_DeleteMessages(id);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -524,6 +524,11 @@ namespace TL
|
||||||
public static implicit operator InputMessage(int id) => new InputMessageID() { id = id };
|
public static implicit operator InputMessage(int id) => new InputMessageID() { id = id };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial class InputDialogPeerBase
|
||||||
|
{
|
||||||
|
public static implicit operator InputDialogPeerBase(InputPeer peer) => new InputDialogPeer() { peer = peer };
|
||||||
|
}
|
||||||
|
|
||||||
partial class SecureFile
|
partial class SecureFile
|
||||||
{
|
{
|
||||||
public static implicit operator InputSecureFile(SecureFile file) => new() { id = file.id, access_hash = file.access_hash };
|
public static implicit operator InputSecureFile(SecureFile file) => new() { id = file.id, access_hash = file.access_hash };
|
||||||
|
|
|
||||||
|
|
@ -10033,7 +10033,7 @@ namespace TL
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Peer, or all peers in a certain folder <para>Derived classes: <see cref="InputDialogPeer"/>, <see cref="InputDialogPeerFolder"/></para> <para>See <a href="https://corefork.telegram.org/type/InputDialogPeer"/></para></summary>
|
/// <summary>Peer, or all peers in a certain folder <para>Derived classes: <see cref="InputDialogPeer"/>, <see cref="InputDialogPeerFolder"/></para> <para>See <a href="https://corefork.telegram.org/type/InputDialogPeer"/></para></summary>
|
||||||
public abstract class InputDialogPeerBase : IObject { }
|
public abstract partial class InputDialogPeerBase : IObject { }
|
||||||
/// <summary>A peer <para>See <a href="https://corefork.telegram.org/constructor/inputDialogPeer"/></para></summary>
|
/// <summary>A peer <para>See <a href="https://corefork.telegram.org/constructor/inputDialogPeer"/></para></summary>
|
||||||
[TLDef(0xFCAAFEB7)]
|
[TLDef(0xFCAAFEB7)]
|
||||||
public class InputDialogPeer : InputDialogPeerBase
|
public class InputDialogPeer : InputDialogPeerBase
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue