Merge pull request #5 from siml173/siml173-patch-5

Create ImportContactRequest
This commit is contained in:
mohammad ahmady 2016-01-16 12:23:26 +03:30
commit c7ad7ba491

View file

@ -0,0 +1,66 @@
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; } }
}
}