From 1dce594e439526e3f3e30a8835103c7c076aea24 Mon Sep 17 00:00:00 2001 From: Ilya Pirozhneko Date: Mon, 1 Feb 2016 23:39:39 +0300 Subject: [PATCH] - Update layer to 23 - Start implementing get user by userName --- TLSharp.Core/MTProto/TL.cs | 1 + TLSharp.Core/Requests/ImportByUserName.cs | 35 +++++++++++++++++++ .../Requests/InitConnectionRequest.cs | 3 +- TLSharp.Core/TLSharp.Core.csproj | 1 + TLSharp.Core/TelegramClient.cs | 9 +++++ TLSharp.Tests/NotificatioClientTests.cs | 15 ++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 TLSharp.Core/Requests/ImportByUserName.cs diff --git a/TLSharp.Core/MTProto/TL.cs b/TLSharp.Core/MTProto/TL.cs index 2253f67..9a40399 100644 --- a/TLSharp.Core/MTProto/TL.cs +++ b/TLSharp.Core/MTProto/TL.cs @@ -10966,6 +10966,7 @@ namespace TLSharp.Core.MTProto public override void Read(BinaryReader reader) { this.date = reader.ReadInt32(); + var expires = reader.ReadInt32(); this.test_mode = reader.ReadUInt32() == 0x997275b5; this.this_dc = reader.ReadInt32(); reader.ReadInt32(); // vector code diff --git a/TLSharp.Core/Requests/ImportByUserName.cs b/TLSharp.Core/Requests/ImportByUserName.cs new file mode 100644 index 0000000..89030c5 --- /dev/null +++ b/TLSharp.Core/Requests/ImportByUserName.cs @@ -0,0 +1,35 @@ +using System; +using System.IO; +using TLSharp.Core.MTProto; + +namespace TLSharp.Core.Requests +{ + public class ImportByUserName : MTProtoRequest + { + private readonly string _userName; + public ImportByUserName(string userName) + { + _userName = userName; + } + + public override void OnSend(BinaryWriter writer) + { + writer.Write(0xf93ccba3); + Serializers.String.write(writer, _userName); + } + + public override void OnResponse(BinaryReader reader) + { + var code = reader.ReadUInt32(); + var peer = TL.Parse(reader); + } + + public override void OnException(Exception exception) + { + throw new NotImplementedException(); + } + + public override bool Confirmed { get; } + public override bool Responded { get; } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Requests/InitConnectionRequest.cs b/TLSharp.Core/Requests/InitConnectionRequest.cs index fbeaa13..7386d3a 100644 --- a/TLSharp.Core/Requests/InitConnectionRequest.cs +++ b/TLSharp.Core/Requests/InitConnectionRequest.cs @@ -16,7 +16,8 @@ namespace TLSharp.Core.Requests public override void OnSend(BinaryWriter writer) { - writer.Write(0x1c900537); // invokeWithLayer18#1c900537 + writer.Write(0xda9b0d0d); + writer.Write(23);// invokeWithLayer23#1c900537 writer.Write(0x69796de9); // initConnection writer.Write(_apiId); // api id Serializers.String.write(writer, "WinPhone Emulator"); // device model diff --git a/TLSharp.Core/TLSharp.Core.csproj b/TLSharp.Core/TLSharp.Core.csproj index 2ccc605..2541b51 100644 --- a/TLSharp.Core/TLSharp.Core.csproj +++ b/TLSharp.Core/TLSharp.Core.csproj @@ -72,6 +72,7 @@ + diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 10965e8..8d4685d 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -210,6 +210,15 @@ namespace TLSharp.Core return importedUser?.user_id; } + public async Task ImportByUserName(string username) + { + var request = new ImportByUserName(username); + await _sender.Send(request); + await _sender.Recieve(request); + + return null; + } + public async Task SendMessage(int id, string message) { var request = new SendMessageRequest(new InputPeerContactConstructor(id), message); diff --git a/TLSharp.Tests/NotificatioClientTests.cs b/TLSharp.Tests/NotificatioClientTests.cs index 53f2cf9..19e8c7c 100644 --- a/TLSharp.Tests/NotificatioClientTests.cs +++ b/TLSharp.Tests/NotificatioClientTests.cs @@ -72,6 +72,21 @@ namespace TLSharp.Tests Assert.IsNotNull(res); } + [TestMethod] + public async Task ImportByUserName() + { + var store = new FileSessionStore(); + var client = new TelegramClient(store, "session"); + + await client.Connect(); + + Assert.IsTrue(client.IsUserAuthorized()); + + var res = await client.ImportByUserName(NumberToSendMessage); + + Assert.IsNotNull(res); + } + [TestMethod] public async Task SendMessage() {