Esempio n. 1
0
        public Task GetContactFromAddress(string address, Action <Contact, Contact.ID> result)
        {
            return(Task.Factory.StartNew(async() =>
            {
                Func <IUser, Tuple <TelegramContact, TelegramContact.ID> > buildContact = user =>
                {
                    var id = new TelegramContact.ID
                    {
                        Service = this,
                        Id = address,
                    };
                    var contact = new TelegramContact
                    {
                        FirstName = TelegramUtils.GetUserName(user),
                        Ids = new List <Contact.ID>
                        {
                            id
                        },
                    };
                    return Tuple.Create(contact, id);
                };
                if (address == null)
                {
                    return;
                }

                var userTuple = _dialogs.GetUser(uint.Parse(address));
                if (userTuple != null)
                {
                    var tuple = buildContact(userTuple);
                    result(tuple.Item1, tuple.Item2);
                    return;
                }

                var userContacts = await FetchContacts();
                foreach (var userContact in userContacts)
                {
                    var userId = TelegramUtils.GetUserId(userContact);
                    if (userId == address)
                    {
                        var tuple = buildContact(userContact);
                        result(tuple.Item1, tuple.Item2);
                        return;
                    }
                }
                result(null, null);
            }));
        }
Esempio n. 2
0
        public Task GetContactFromAddress(string address, Action<Contact, Contact.ID> result)
        {
            return Task.Factory.StartNew(async () =>
            {
                Func<IUser, Tuple<TelegramContact, TelegramContact.ID>> buildContact = user =>
                {
                    var id = new TelegramContact.ID
                    {
                        Service = this,
                        Id = address,
                    };
                    var contact = new TelegramContact
                    {
                        FirstName = TelegramUtils.GetUserName(user),
                        Ids = new List<Contact.ID>
                        {
                            id
                        },
                    };
                    return Tuple.Create(contact, id);
                };
                if (address == null)
                {
                    return;
                }

                var userTuple = _dialogs.GetUser(uint.Parse(address));
                if (userTuple != null)
                {
                    var tuple = buildContact(userTuple);
                    result(tuple.Item1, tuple.Item2);
                    return;
                }

                var userContacts = await FetchContacts();
                foreach (var userContact in userContacts)
                {
                    var userId = TelegramUtils.GetUserId(userContact);
                    if (userId == address)
                    {
                        var tuple = buildContact(userContact);
                        result(tuple.Item1, tuple.Item2);
                        return;
                    }
                }
                result(null, null);
            });
        }