This commit is contained in:
Ilya Pirozhneko 2016-02-07 13:28:41 +03:00
parent 84cbe0afc8
commit 103e41fb2b
8 changed files with 91 additions and 80 deletions

View file

@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using TLSharp.Core.MTProto;
namespace TLSharp.Core.Requests
{
public class ImportContactRequest : MTProtoRequest
{
private List<InputContact> Contact { get; set; }
private bool Replace { get; set; }
public List<ImportedContact> imported;
public List<User> users;
public ImportContactRequest(List<InputContact> contact, bool shouldReplace = true)
{
Contact = contact;
Replace = shouldReplace;
}
public override void OnSend(BinaryWriter writer)
{
writer.Write(0xda30b32d);
writer.Write(0x1cb5c415);
writer.Write(Contact.Count);
foreach (var item in Contact)
{
item.Write(writer);
}
writer.Write(Replace ? 0x997275b5 : 0xbc799737);
}
public override void OnResponse(BinaryReader reader)
{
var code = reader.ReadUInt32();
var result = reader.ReadInt32(); // vector code
int imported_len = reader.ReadInt32();
this.imported = new List<ImportedContact>(imported_len);
for (int imported_index = 0; imported_index < imported_len; imported_index++)
{
ImportedContact imported_element;
imported_element = TL.Parse<ImportedContact>(reader);
this.imported.Add(imported_element);
}
reader.ReadInt32(); // vector code
int users_len = reader.ReadInt32();
this.users = new List<User>(users_len);
for (int users_index = 0; users_index < users_len; users_index++)
{
User users_element;
users_element = TL.Parse<User>(reader);
this.users.Add(users_element);
}
}
public override void OnException(Exception exception)
{
throw new NotImplementedException();
}
public override bool Confirmed { get { return true; } }
private readonly bool responded;
public override bool Responded { get { return responded; } }
}
}

View file

@ -85,6 +85,9 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<Compile Include="Requests\CreateChatRequest.cs" />
<None Include="Requests\AddChatUserRequest.cs" />
<None Include="Requests\DeleteChatUserRequest.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TLSharp.Core.Auth;
using TLSharp.Core.MTProto;
@ -183,7 +184,7 @@ namespace TLSharp.Core
return inputFile;
}
public async Task<Boolean> SendMediaMessage(int contactId, InputFile file)
public async Task<bool> SendMediaMessage(int contactId, InputFile file)
{
var request = new Message_SendMediaRequest(
new InputPeerContactConstructor(contactId),
@ -195,8 +196,11 @@ namespace TLSharp.Core
return true;
}
public async Task<int?> ImportContact(string phoneNumber)
public async Task<int?> ImportContactByPhoneNumber(string phoneNumber)
{
if (!validateNumber(phoneNumber))
throw new InvalidOperationException("Invalid phone number. It should be only digit string, from 5 to 20 digits.");
var request = new ImportContactRequest(new InputPhoneContactConstructor(0, phoneNumber, "My Test Name", String.Empty));
await _sender.Send(request);
await _sender.Recieve(request);
@ -208,6 +212,9 @@ namespace TLSharp.Core
public async Task<int?> ImportByUserName(string username)
{
if (string.IsNullOrEmpty(username))
throw new InvalidOperationException("Username can't be null");
var request = new ImportByUserName(username);
await _sender.Send(request);
await _sender.Recieve(request);
@ -231,5 +238,12 @@ namespace TLSharp.Core
return request.messages;
}
private bool validateNumber(string number)
{
var regex = new Regex("^\\d{7,20}$");
return regex.IsMatch(number);
}
}
}