Added methods for working with contacts.

Added custom constructor for TLVector.
This commit is contained in:
CheshireCaat 2020-01-23 03:16:50 +03:00
parent 3c6f53be68
commit f1bcd62df3
2 changed files with 42 additions and 2 deletions

View file

@ -234,12 +234,42 @@ namespace TLSharp.Core
return (T)result;
}
public async Task<TLImportedContacts> ImportContactsAsync(IReadOnlyList<TLInputPhoneContact> contacts)
{
if (!IsUserAuthorized())
throw new InvalidOperationException("Authorize user first!");
var req = new TLRequestImportContacts { Contacts = new TLVector<TLInputPhoneContact>(contacts)};
return await SendRequestAsync<TLImportedContacts>(req);
}
public async Task<bool> DeleteContactsAsync(IReadOnlyList<TLAbsInputUser> users)
{
if (!IsUserAuthorized())
throw new InvalidOperationException("Authorize user first!");
var req = new TLRequestDeleteContacts {Id = new TLVector<TLAbsInputUser>(users)};
return await SendRequestAsync<bool>(req);
}
public async Task<TLLink> DeleteContactAsync(TLAbsInputUser user)
{
if (!IsUserAuthorized())
throw new InvalidOperationException("Authorize user first!");
var req = new TLRequestDeleteContact {Id = user};
return await SendRequestAsync<TLLink>(req);
}
public async Task<TLContacts> GetContactsAsync()
{
if (!IsUserAuthorized())
throw new InvalidOperationException("Authorize user first!");
var req = new TLRequestGetContacts() { Hash = "" };
var req = new TLRequestGetContacts {Hash = ""};
return await SendRequestAsync<TLContacts>(req);
}

View file

@ -11,7 +11,17 @@ namespace TeleSharp.TL
public class TLVector<T> : TLObject, IList<T>
{
[TLObject(481674261)]
private List<T> lists = new List<T>();
private List<T> lists;
public TLVector(IEnumerable<T> collection)
{
lists = new List<T>(collection);
}
public TLVector()
{
lists = new List<T>();
}
public T this[int index]
{