Ejemplo n.º 1
0
        public void LoadContacts()
        {
            ProtoService.Send(new SearchContacts(string.Empty, int.MaxValue), async result =>
            {
                if (result is Telegram.Td.Api.Users users)
                {
                    BeginOnUIThread(() =>
                    {
                        foreach (var id in users.UserIds)
                        {
                            var user = ProtoService.GetUser(id);
                            if (user != null)
                            {
                                Items.Add(user);
                            }
                        }
                    });

                    if (ApplicationSettings.Current.IsContactsSyncEnabled)
                    {
                        await _contactsService.ExportAsync(users);
                        await _contactsService.ImportAsync();
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public async Task LoadContactsAsync()
        {
            Items.Clear();

            var contacts = CacheService.GetContacts();

            foreach (var item in contacts.OfType <TLUser>())
            {
                var user = item as TLUser;
                if (user.IsSelf)
                {
                    continue;
                }

                Items.Add(user);
            }

            var savedCount = ApplicationSettings.Current.ContactsSavedCount;
            var hash       = CalculateContactsHash(savedCount, contacts.OrderBy(x => x.Id));

            var response = await ProtoService.GetContactsAsync(hash);

            if (response.IsSucceeded && response.Result is TLContactsContacts result)
            {
                ApplicationSettings.Current.ContactsSavedCount = result.SavedCount;

                BeginOnUIThread(() =>
                {
                    Items.Clear();

                    foreach (var item in result.Users.OfType <TLUser>())
                    {
                        var user = item as TLUser;
                        if (user.IsSelf)
                        {
                            continue;
                        }

                        Items.Add(user);
                    }
                });

                if (ApplicationSettings.Current.IsContactsSyncEnabled)
                {
                    await _contactsService.ExportAsync(result);
                }
            }

            await _contactsService.ImportAsync();

            Aggregator.Subscribe(this);
        }
        public override async void RaisePropertyChanged([CallerMemberName] string propertyName = null)
        {
            base.RaisePropertyChanged(propertyName);

            if (propertyName.Equals(nameof(IsContactsSyncEnabled)))
            {
                if (IsContactsSyncEnabled)
                {
                    var contacts = CacheService.GetContacts();
                    var response = new TLContactsContacts {
                        Users = new TLVector <TLUserBase>(contacts)
                    };

                    await _contactsService.ExportAsync(response);
                }
                else
                {
                    await _contactsService.RemoveAsync();
                }
            }
        }
Ejemplo n.º 4
0
        public void LoadContacts()
        {
            ProtoService.Send(new SearchContacts(string.Empty, int.MaxValue), async result =>
            {
                if (result is TdWindows.Users users)
                {
                    BeginOnUIThread(() =>
                    {
                        foreach (var id in users.UserIds)
                        {
                            var user = ProtoService.GetUser(id);
                            if (user != null)
                            {
                                Items.Add(user);
                            }
                        }
                    });

                    await _contactsService.ExportAsync(users);
                }
            });
        }