Example #1
0
 public Task FetchBubbleGroupAddress(Tuple <Contact, Contact.ID>[] contacts, Action <bool, string> result)
 {
     return(Task.Factory.StartNew(async() =>
     {
         if (contacts.Length > 1)
         {
             var userContacts = await FetchContacts();
             var inputUsers = new List <IInputUser>();
             var names = new List <string>();
             foreach (var contact in contacts)
             {
                 names.Add(contact.Item1.FullName);
                 var id = uint.Parse(contact.Item2.Id);
                 foreach (var userContact in userContacts)
                 {
                     if (userContact.Id == id)
                     {
                         var inputUser = TelegramUtils.CastUserToInputUser(userContact);
                         if (inputUser != null)
                         {
                             inputUsers.Add(inputUser);
                             break;
                         }
                     }
                 }
             }
             if (inputUsers.Any())
             {
                 var subject = BubbleGroupUtils.GeneratePartyTitle(names.ToArray());
                 if (subject.Length > 25)
                 {
                     subject = subject.Substring(0, 22);
                     subject += "...";
                 }
                 using (var client = new FullClientDisposable(this))
                 {
                     var response = await client.Client.Methods.MessagesCreateChatAsync(
                         new MessagesCreateChatArgs
                     {
                         Users = inputUsers,
                         Title = subject,
                     });
                     ProcessIncomingPayload(response, true);
                     SaveState(response);
                     var chat = TelegramUtils.GetChatFromStatedMessage(response);
                     result(true, TelegramUtils.GetChatId(chat));
                 }
             }
             else
             {
                 result(false, null);
             }
         }
         else
         {
             result(true, contacts[0].Item2.Id);
         }
     }));
 }