Пример #1
0
 /// <summary>
 /// 
 /// </summary>
 public void LoadMoreDialogs()
 {
     var getDialogs = new ExecuteDialogs(Dialogs.Count, _UpdateDialogsList);//new DialogsGet(DIALOGS_COUNT, Dialogs.Count, _friendsCache.GetItems(), _UpdateDialogsList);
     getDialogs.Execute();
 }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        public void UpdateDialogs()
        {
            // Get MAX of latest dialogs (because of offset 0).

            var getDialogs = new ExecuteDialogs(0, (dialogs, profiles) => //new DialogsGet(DIALOGS_COUNT, 0, _friendsCache.GetItems(), dialogs =>
            {
                try
                {
                    _AddDistinctUserInfo(profiles);

                    var cached = _dialogsCache.GetItems();

                    // Find dialogs which should be added or updated.
                    foreach (var dialog in dialogs)
                    {
                        Dialog current_cached = cached.FirstOrDefault(x => (x.Uid == dialog.Uid && !x.IsConference && !dialog.IsConference) ||
                                                                      (x.ChatId == dialog.ChatId && x.IsConference && dialog.IsConference));

                        if (current_cached == null) // Completely new dialog.
                            _dialogsCache.AddItem(dialog);
                        else // Replace with latest one
                            _dialogsCache.RenewItem(current_cached, dialog);
                    }

                    _dialogsCache.Save();

                    _ReinitializeCounters();

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        try
                        {
                            _PushDialogsToView();
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("UpdateDialogs->_PushDialogsToView failed in EntityService: " + ex.Message);
                        }
                    });
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("EntityService _UpdateDialogsList failed: " + ex.Message);
                }
            });
            getDialogs.Execute();
        }
Пример #3
0
        private void _InitializeDialogsList()
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                try
                {
                    var cachedDialogs = _dialogsCache.GetItems();

                    if (cachedDialogs.Any())
                    {
                        _PushDialogsToView();

                        //int maxMid = cachedDialogs.Where(x => !x.IsConference).Max(y => y.ChatId); // Find max message Id in dialogs, since dialogs contains LATEST messages.
                        //App.Current.LongPollService.GetHistory(maxMid);

                        _waitHandle.Set();
                    }
                    else
                    {
                        // Get only and only if cache is empty, because initially we load only 100-200 dialogs until use scrolled down
                        // (so, probably, there may be situation where user never load all history).
                        var getDialogs = new ExecuteDialogs(0, _UpdateDialogsList);// new DialogsGet(DIALOGS_COUNT, 0, _friendsCache.GetItems(), _UpdateDialogsList);//
                        getDialogs.Execute();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("_InitializeDialogsList failed: " + ex.Message);
                    _waitHandle.Set();
                }
            });
        }