Add methods for working with contacts. (#896)

Added methods for working with contacts:

* Import contact list
* Delete contact list
* Delete one contact
This commit is contained in:
CheshireCaat 2020-01-23 07:02:19 +03:00 committed by Andres G. Aragoneses
parent 3c6f53be68
commit c9ac0bab87
2 changed files with 41 additions and 1 deletions

View file

@ -234,6 +234,36 @@ 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())

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]
{