From f1bcd62df3545df5696922c035466ca453621a51 Mon Sep 17 00:00:00 2001 From: CheshireCaat Date: Thu, 23 Jan 2020 03:16:50 +0300 Subject: [PATCH] Added methods for working with contacts. Added custom constructor for TLVector. --- TLSharp.Core/TelegramClient.cs | 32 +++++++++++++++++++++++++++++++- TeleSharp.TL/TLVector.cs | 12 +++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index f7e0258..97d0f6d 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -234,12 +234,42 @@ 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()) throw new InvalidOperationException("Authorize user first!"); - var req = new TLRequestGetContacts() { Hash = "" }; + var req = new TLRequestGetContacts {Hash = ""}; return await SendRequestAsync(req); } 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] {