diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 7401bb3..9719d10 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -13,6 +13,8 @@ using TeleSharp.TL; using MD5 = System.Security.Cryptography.MD5; using TeleSharp.TL.Help; using TeleSharp.TL.Auth; +using TeleSharp.TL.Contacts; +using TeleSharp.TL.Messages; namespace TLSharp.Core { @@ -153,9 +155,57 @@ namespace TLSharp.Core { await _sender.Send(methodtoExceute); await _sender.Receive(methodtoExceute); - return (T)Convert.ChangeType(typeof(TLMethod).GetProperty("Response").GetValue(methodtoExceute),typeof(T)); + + var result = methodtoExceute.GetType().GetProperty("Response").GetValue(methodtoExceute); + + return (T)result; } - private void OnUserAuthenticated(TLUser TLUser) + + + public async Task GetContacts() + { + if (!IsUserAuthorized()) + throw new InvalidOperationException("Authorize user first!"); + + var req = new TLRequestGetContacts() {hash = ""}; + + return await SendRequest(req); + } + + public async Task SendMessage(TLAbsInputPeer peer, string message) + { + if (!IsUserAuthorized()) + throw new InvalidOperationException("Authorize user first!"); + + long uniqueId = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds); + + return await SendRequest( + new TLRequestSendMessage() + { + peer = peer, + message = message, + random_id = uniqueId + }); + } + + public async Task SendTyping(TLAbsInputPeer peer) + { + var req = new TLRequestSetTyping() + { + action = new TLSendMessageTypingAction(), + peer = peer + }; + return await SendRequest(req); + } + + public async Task GetUserDialogs() + { + var peer = new TLInputPeerSelf(); + return await SendRequest( + new TLRequestGetDialogs() { offset_date = 0, offset_peer = peer, limit = 100 }); + } + + private void OnUserAuthenticated(TLUser TLUser) { _session.TLUser = TLUser; _session.SessionExpires = int.MaxValue; diff --git a/TeleSharp.TL/TL/Auth/TLRequestSendCode.cs b/TeleSharp.TL/TL/Auth/TLRequestSendCode.cs index bb956ef..ddb8efe 100644 --- a/TeleSharp.TL/TL/Auth/TLRequestSendCode.cs +++ b/TeleSharp.TL/TL/Auth/TLRequestSendCode.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using TeleSharp.TL; namespace TeleSharp.TL.Auth { - [TLObject(-2035355412)] + [TLObject(-2035355412)] public class TLRequestSendCode : TLMethod { public override int Constructor @@ -18,55 +18,55 @@ namespace TeleSharp.TL.Auth } } - public int flags { get; set; } - public bool allow_flashcall { get; set; } - public string phone_number { get; set; } - public bool? current_number { get; set; } - public int api_id { get; set; } - public string api_hash { get; set; } - public Auth.TLSentCode Response { get; set; } + public int flags {get;set;} + public bool allow_flashcall {get;set;} + public string phone_number {get;set;} + public bool? current_number {get;set;} + public int api_id {get;set;} + public string api_hash {get;set;} + public Auth.TLSentCode Response{ get; set;} - public void ComputeFlags() - { - flags = 0; - flags = allow_flashcall ? (flags | 1) : (flags & ~1); - flags = current_number != null ? (flags | 1) : (flags & ~1); + public void ComputeFlags() + { + flags = 0; +flags = allow_flashcall ? (flags | 1) : (flags & ~1); +flags = current_number != null ? (flags | 1) : (flags & ~1); - } + } public override void DeserializeBody(BinaryReader br) { flags = br.ReadInt32(); - allow_flashcall = (flags & 1) != 0; - phone_number = StringUtil.Deserialize(br); - if ((flags & 1) != 0) - current_number = BoolUtil.Deserialize(br); - else - current_number = null; +allow_flashcall = (flags & 1) != 0; +phone_number = StringUtil.Deserialize(br); +if ((flags & 1) != 0) +current_number = BoolUtil.Deserialize(br); +else +current_number = null; - api_id = br.ReadInt32(); - api_hash = StringUtil.Deserialize(br); +api_id = br.ReadInt32(); +api_hash = StringUtil.Deserialize(br); } public override void SerializeBody(BinaryWriter bw) { - bw.Write(Constructor); + bw.Write(Constructor); ComputeFlags(); - bw.Write(flags); +bw.Write(flags); - StringUtil.Serialize(phone_number, bw); - if ((flags & 1) != 0) - BoolUtil.Serialize(current_number.Value, bw); - bw.Write(api_id); - StringUtil.Serialize(api_hash, bw); +StringUtil.Serialize(phone_number,bw); +if ((flags & 1) != 0) +BoolUtil.Serialize(current_number.Value,bw); +bw.Write(api_id); +StringUtil.Serialize(api_hash,bw); } - public override void deserializeResponse(BinaryReader br) - { - Response = (Auth.TLSentCode)ObjectUtils.DeserializeObject(br); + public override void deserializeResponse(BinaryReader br) + { + Response = (Auth.TLSentCode)ObjectUtils.DeserializeObject(br); - } + } } } diff --git a/TeleSharp.TL/TL/Contacts/TLRequestImportContacts.cs b/TeleSharp.TL/TL/Contacts/TLRequestImportContacts.cs index c42497d..ebf15be 100644 --- a/TeleSharp.TL/TL/Contacts/TLRequestImportContacts.cs +++ b/TeleSharp.TL/TL/Contacts/TLRequestImportContacts.cs @@ -30,7 +30,7 @@ namespace TeleSharp.TL.Contacts public override void DeserializeBody(BinaryReader br) { - contacts = (TLVector)ObjectUtils.DeserializeVector(br); + contacts = ObjectUtils.DeserializeVector(br); replace = BoolUtil.Deserialize(br); } diff --git a/TeleSharp.TL/TL/TLAbsBool.cs b/TeleSharp.TL/TL/TLAbsBool.cs new file mode 100644 index 0000000..afa7d6c --- /dev/null +++ b/TeleSharp.TL/TL/TLAbsBool.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeleSharp.TL; +namespace TeleSharp.TL +{ + public abstract class TLAbsBool : TLObject + { + } +} diff --git a/TeleSharp.TL/TL/TLBoolFalse.cs b/TeleSharp.TL/TL/TLBoolFalse.cs new file mode 100644 index 0000000..2799fea --- /dev/null +++ b/TeleSharp.TL/TL/TLBoolFalse.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeleSharp.TL; +namespace TeleSharp.TL +{ + [TLObject(-1132882121)] + public class TLBoolFalse : TLAbsBool + { + public override int Constructor + { + get + { + return -1132882121; + } + } + + + + public void ComputeFlags() + { + + } + + public override void DeserializeBody(BinaryReader br) + { + + } + + public override void SerializeBody(BinaryWriter bw) + { + bw.Write(Constructor); + + } + } +} diff --git a/TeleSharp.TL/TL/TLBoolTrue.cs b/TeleSharp.TL/TL/TLBoolTrue.cs new file mode 100644 index 0000000..221d3ef --- /dev/null +++ b/TeleSharp.TL/TL/TLBoolTrue.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeleSharp.TL; +namespace TeleSharp.TL +{ + [TLObject(-1720552011)] + public class TLBoolTrue : TLAbsBool + { + public override int Constructor + { + get + { + return -1720552011; + } + } + + + + public void ComputeFlags() + { + + } + + public override void DeserializeBody(BinaryReader br) + { + + } + + public override void SerializeBody(BinaryWriter bw) + { + bw.Write(Constructor); + + } + } +} diff --git a/TeleSharp.TL/TL/TLTrue.cs b/TeleSharp.TL/TL/TLTrue.cs new file mode 100644 index 0000000..140c5ea --- /dev/null +++ b/TeleSharp.TL/TL/TLTrue.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeleSharp.TL; +namespace TeleSharp.TL +{ + [TLObject(1072550713)] + public class TLTrue : TLObject + { + public override int Constructor + { + get + { + return 1072550713; + } + } + + + + public void ComputeFlags() + { + + } + + public override void DeserializeBody(BinaryReader br) + { + + } + + public override void SerializeBody(BinaryWriter bw) + { + bw.Write(Constructor); + + } + } +} diff --git a/TeleSharp.TL/TLVector.cs b/TeleSharp.TL/TLVector.cs index 4c2b539..6c34270 100644 --- a/TeleSharp.TL/TLVector.cs +++ b/TeleSharp.TL/TLVector.cs @@ -53,7 +53,11 @@ namespace TeleSharp.TL public override void SerializeBody(BinaryWriter bw) { - throw new NotImplementedException(); + bw.Write(Constructor); + foreach (var item in lists.Cast()) + { + item.SerializeBody(bw); + } } } } diff --git a/TeleSharp.TL/TeleSharp.TL.csproj b/TeleSharp.TL/TeleSharp.TL.csproj index a7a5c2c..46e2a18 100644 --- a/TeleSharp.TL/TeleSharp.TL.csproj +++ b/TeleSharp.TL/TeleSharp.TL.csproj @@ -301,6 +301,7 @@ + @@ -370,6 +371,8 @@ + + @@ -639,6 +642,7 @@ +