From 76d75a6035efe73500ad23bead8ea9d7e123b36c Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Sat, 26 Nov 2022 23:10:06 +0100 Subject: [PATCH] implicit Input* operators for Wallpaper, EncryptedChat, PhoneCall, Theme, GroupCall --- src/TL.Helpers.cs | 50 +++++++++++++++++++------ src/TL.Schema.cs | 94 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 126 insertions(+), 18 deletions(-) diff --git a/src/TL.Helpers.cs b/src/TL.Helpers.cs index baa60d3..dc68173 100644 --- a/src/TL.Helpers.cs +++ b/src/TL.Helpers.cs @@ -97,6 +97,17 @@ namespace TL public override InputSecureFileBase ToInputSecureFile(byte[] file_hash, byte[] secret) => new InputSecureFileUploaded { id = id, parts = parts, file_hash = file_hash, secret = secret }; } + partial class InputMediaUploadedDocument + { + public InputMediaUploadedDocument() { } + public InputMediaUploadedDocument(InputFileBase inputFile, string mimeType) + { + file = inputFile; + mime_type = mimeType; + if (inputFile.Name is string filename) attributes = new[] { new DocumentAttributeFilename { file_name = filename } }; + } + } + partial class InputPhoto { public static implicit operator InputMediaPhoto(InputPhoto photo) => new() { id = photo }; @@ -340,17 +351,19 @@ namespace TL public static implicit operator InputGeoPoint(GeoPoint geo) => new() { lat = geo.lat, lon = geo.lon, accuracy_radius = geo.accuracy_radius, flags = (InputGeoPoint.Flags)geo.flags }; } - partial class InputMediaUploadedDocument + partial class WallPaperBase { - public InputMediaUploadedDocument() { } - public InputMediaUploadedDocument(InputFileBase inputFile, string mimeType) - { - file = inputFile; - mime_type = mimeType; - if (inputFile.Name is string filename) attributes = new[] { new DocumentAttributeFilename { file_name = filename } }; - } + protected abstract InputWallPaperBase ToInputWallPaper(); + public static implicit operator InputWallPaperBase(WallPaperBase wp) => wp.ToInputWallPaper(); + } + partial class WallPaper + { + protected override InputWallPaperBase ToInputWallPaper() => new InputWallPaper { id = id, access_hash = access_hash }; + } + partial class WallPaperNoFile + { + protected override InputWallPaperBase ToInputWallPaper() => new InputWallPaperNoFile { id = id }; } - partial class Contacts_Blocked { public IPeerInfo UserOrChat(PeerBlocked peer) => peer.peer_id?.UserOrChat(users, chats); } partial class Messages_DialogsBase { public IPeerInfo UserOrChat(DialogBase dialog) => UserOrChat(dialog.Peer); public abstract int TotalCount { get; } } @@ -416,7 +429,8 @@ namespace TL }, pts = pts, pts_count = pts_count } }; } - partial class InputEncryptedChat { public static implicit operator int(InputEncryptedChat chat) => chat.chat_id; } + partial class InputEncryptedChat { public static implicit operator int(InputEncryptedChat chat) => chat.chat_id; + public static implicit operator InputEncryptedChat(EncryptedChatBase chat) => new() { chat_id = chat.ID, access_hash = chat.AccessHash }; } partial class EncryptedFile { @@ -554,14 +568,16 @@ namespace TL partial class Game { public static implicit operator InputGameID(Game game) => new() { id = game.id, access_hash = game.access_hash }; } partial class WebDocument { public static implicit operator InputWebFileLocation(WebDocument doc) => new() { url = doc.url, access_hash = doc.access_hash }; } + partial class PhoneCallBase { public static implicit operator InputPhoneCall(PhoneCallBase call) => new() { id = call.ID, access_hash = call.AccessHash }; } + partial class InputMessage { - 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 }; + public static implicit operator InputDialogPeerBase(InputPeer peer) => new InputDialogPeer { peer = peer }; } partial class SecureFile @@ -632,4 +648,14 @@ namespace TL return dic; } } + + partial class Theme + { + public static implicit operator InputTheme(Theme theme) => new() { id = theme.id, access_hash = theme.access_hash }; + } + + partial class GroupCallBase + { + public static implicit operator InputGroupCall(GroupCallBase call) => new() { id = call.ID, access_hash = call.AccessHash }; + } } diff --git a/src/TL.Schema.cs b/src/TL.Schema.cs index 1177959..3da5301 100644 --- a/src/TL.Schema.cs +++ b/src/TL.Schema.cs @@ -2628,7 +2628,7 @@ namespace TL } /// Object contains info on a wallpaper. See Derived classes: , - public abstract class WallPaperBase : IObject + public abstract partial class WallPaperBase : IObject { /// Identifier public virtual long ID { get; } @@ -2637,7 +2637,7 @@ namespace TL } /// Represents a wallpaper based on an image. See [TLDef(0xA437C3ED)] - public class WallPaper : WallPaperBase + public partial class WallPaper : WallPaperBase { /// Identifier public long id; @@ -2673,7 +2673,7 @@ namespace TL } /// Represents a wallpaper only based on colors/gradients. See [TLDef(0xE0804116)] - public class WallPaperNoFile : WallPaperBase + public partial class WallPaperNoFile : WallPaperBase { /// Wallpaper ID public long id; @@ -5006,6 +5006,14 @@ namespace TL { /// Chat ID public virtual int ID { get; } + /// Checking sum depending on user ID + public virtual long AccessHash { get; } + /// Date of chat creation + public virtual DateTime Date { get; } + /// Chat creator ID + public virtual long AdminId { get; } + /// ID of second chat participant + public virtual long ParticipantId { get; } } /// Empty constructor. See [TLDef(0xAB7EC0A0)] @@ -5034,6 +5042,14 @@ namespace TL /// Chat ID public override int ID => id; + /// Checking sum depending on user ID + public override long AccessHash => access_hash; + /// Date of chat creation + public override DateTime Date => date; + /// Chat creator ID + public override long AdminId => admin_id; + /// ID of second chat participant + public override long ParticipantId => participant_id; } /// Request to create an encrypted chat. See [TLDef(0x48F1D94C)] @@ -5064,6 +5080,14 @@ namespace TL /// Chat ID public override int ID => id; + /// Check sum depending on user ID + public override long AccessHash => access_hash; + /// Chat creation date + public override DateTime Date => date; + /// Chat creator ID + public override long AdminId => admin_id; + /// ID of second chat participant + public override long ParticipantId => participant_id; } /// Encrypted chat See [TLDef(0x61F0D4C7)] @@ -5086,6 +5110,14 @@ namespace TL /// Chat ID public override int ID => id; + /// Check sum dependent on the user ID + public override long AccessHash => access_hash; + /// Date chat was created + public override DateTime Date => date; + /// Chat creator ID + public override long AdminId => admin_id; + /// ID of the second chat participant + public override long ParticipantId => participant_id; } /// Discarded or deleted chat. See [TLDef(0x1E1C7C45)] @@ -9202,10 +9234,20 @@ namespace TL } /// Phone call See Derived classes: , , , , , - public abstract class PhoneCallBase : IObject + public abstract partial class PhoneCallBase : IObject { /// Call ID public virtual long ID { get; } + /// Access hash + public virtual long AccessHash { get; } + /// Date + public virtual DateTime Date { get; } + /// Admin ID + public virtual long AdminId { get; } + /// Participant ID + public virtual long ParticipantId { get; } + /// Phone call protocol info + public virtual PhoneCallProtocol Protocol { get; } } /// Empty constructor See [TLDef(0x5366C915)] @@ -9248,6 +9290,16 @@ namespace TL /// Call ID public override long ID => id; + /// Access hash + public override long AccessHash => access_hash; + /// Date + public override DateTime Date => date; + /// Admin ID + public override long AdminId => admin_id; + /// Participant ID + public override long ParticipantId => participant_id; + /// Phone call protocol info + public override PhoneCallProtocol Protocol => protocol; } /// Requested phone call See [TLDef(0x14B0ED0C)] @@ -9278,6 +9330,16 @@ namespace TL /// Phone call ID public override long ID => id; + /// Access hash + public override long AccessHash => access_hash; + /// When was the phone call created + public override DateTime Date => date; + /// ID of the creator of the phone call + public override long AdminId => admin_id; + /// ID of the other participant of the phone call + public override long ParticipantId => participant_id; + /// Call protocol info to be passed to libtgvoip + public override PhoneCallProtocol Protocol => protocol; } /// An accepted phone call See [TLDef(0x3660C311)] @@ -9308,6 +9370,16 @@ namespace TL /// ID of accepted phone call public override long ID => id; + /// Access hash of phone call + public override long AccessHash => access_hash; + /// When was the call accepted + public override DateTime Date => date; + /// ID of the call creator + public override long AdminId => admin_id; + /// ID of the other user in the call + public override long ParticipantId => participant_id; + /// Protocol to use for phone call + public override PhoneCallProtocol Protocol => protocol; } /// Phone call See [TLDef(0x967F7C67)] @@ -9346,6 +9418,16 @@ namespace TL /// Call ID public override long ID => id; + /// Access hash + public override long AccessHash => access_hash; + /// Date of creation of the call + public override DateTime Date => date; + /// User ID of the creator of the call + public override long AdminId => admin_id; + /// User ID of the other participant in the call + public override long ParticipantId => participant_id; + /// Call protocol info to be passed to libtgvoip + public override PhoneCallProtocol Protocol => protocol; } /// Indicates a discarded phone call See [TLDef(0x50CA4DE1)] @@ -11602,7 +11684,7 @@ namespace TL /// Theme See [TLDef(0xA00E67D6)] - public class Theme : IObject + public partial class Theme : IObject { /// Flags, see TL conditional fields public Flags flags; @@ -12433,7 +12515,7 @@ namespace TL } /// A group call See Derived classes: , - public abstract class GroupCallBase : IObject + public abstract partial class GroupCallBase : IObject { /// Group call ID public virtual long ID { get; }