From c9ac0bab8744e1d13542a293456361b467f6866b Mon Sep 17 00:00:00 2001 From: CheshireCaat Date: Thu, 23 Jan 2020 07:02:19 +0300 Subject: [PATCH] Add methods for working with contacts. (#896) Added methods for working with contacts: * Import contact list * Delete contact list * Delete one contact --- TLSharp.Core/TelegramClient.cs | 30 ++++++++++++++++++++++++++++++ TeleSharp.TL/TLVector.cs | 12 +++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index f7e0258..d86b349 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -234,6 +234,36 @@ namespace TLSharp.Core return (T)result; } + public async Task ImportContactsAsync(IReadOnlyList contacts) + { + if (!IsUserAuthorized()) + throw new InvalidOperationException("Authorize user first!"); + + var req = new TLRequestImportContacts { Contacts = new TLVector(contacts)}; + + return await SendRequestAsync(req); + } + + public async Task DeleteContactsAsync(IReadOnlyList users) + { + if (!IsUserAuthorized()) + throw new InvalidOperationException("Authorize user first!"); + + var req = new TLRequestDeleteContacts {Id = new TLVector(users)}; + + return await SendRequestAsync(req); + } + + public async Task DeleteContactAsync(TLAbsInputUser user) + { + if (!IsUserAuthorized()) + throw new InvalidOperationException("Authorize user first!"); + + var req = new TLRequestDeleteContact {Id = user}; + + return await SendRequestAsync(req); + } + public async Task GetContactsAsync() { if (!IsUserAuthorized()) diff --git a/TeleSharp.TL/TLVector.cs b/TeleSharp.TL/TLVector.cs index 4df828b..29f82e7 100644 --- a/TeleSharp.TL/TLVector.cs +++ b/TeleSharp.TL/TLVector.cs @@ -11,7 +11,17 @@ namespace TeleSharp.TL public class TLVector : TLObject, IList { [TLObject(481674261)] - private List lists = new List(); + private List lists; + + public TLVector(IEnumerable collection) + { + lists = new List(collection); + } + + public TLVector() + { + lists = new List(); + } public T this[int index] {