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); } })); }
public Task FetchBubbleGroupAddress(Tuple <Contact, Contact.ID>[] contacts, Action <bool, string> result) { return(Task.Factory.StartNew(async() => { if (contacts.Length > 1) { var inputUsers = new List <IInputUser>(); var names = new List <string>(); foreach (var contact in contacts) { names.Add(contact.Item1.FullName); var telegramContact = contact.Item1 as TelegramContact; var inputUser = TelegramUtils.CastUserToInputUser(telegramContact.User); if (inputUser != null) { inputUsers.Add(inputUser); } } 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)) { try { var response = await client.Client.Methods.MessagesCreateChatAsync( new MessagesCreateChatArgs { Users = inputUsers, Title = subject, }); var updates = response as Updates; if (updates != null) { SendToResponseDispatcher(updates, client.Client); _dialogs.AddUsers(updates.Users); _dialogs.AddChats(updates.Chats); var chat = TelegramUtils.GetChatFromUpdate(updates); result(true, TelegramUtils.GetChatId(chat)); } else { result(false, null); } } catch (Exception e) { //we get an exception if the user is not allowed to create groups var rpcError = e as RpcErrorException; if (rpcError != null) { result(false, null); } } } } else { result(false, null); } } else { if (contacts[0].Item2 is Contact.PartyID) { JoinChannelIfLeft(contacts[0].Item2.Id); result(true, contacts[0].Item2.Id); } else { var telegramContact = contacts[0].Item1 as TelegramContact; _dialogs.AddUser(telegramContact.User); result(true, contacts[0].Item2.Id); } } })); }