public override void Clear(bool isNotify = true)
 {
     lock (Items)
     {
         CashPresenterManager.RemoveAll(Items);
     }
     base.Clear(isNotify);
 }
Beispiel #2
0
        protected bool ResponseProcessing(OperationResult <ListResponse <Post> > response, int itemsLimit, out ErrorBase error, string sender, bool isNeedClearItems = false, bool enableEmptyMedia = false)
        {
            error = null;
            if (response == null)
            {
                return(false);
            }

            if (response.IsSuccess)
            {
                var results = response.Result.Results;
                if (results.Count > 0)
                {
                    var isAdded = false;
                    lock (Items)
                    {
                        if (isNeedClearItems)
                        {
                            Clear(false);
                        }

                        foreach (var item in results)
                        {
                            if (User.PostBlackList.Contains(item.Url))
                            {
                                continue;
                            }

                            if (!Items.Any(itm => itm.Url.Equals(item.Url, StringComparison.OrdinalIgnoreCase)) &&
                                (enableEmptyMedia || IsValidMedia(item)))
                            {
                                var refItem = CashPresenterManager.Add(item);
                                Items.Add(refItem);
                                isAdded = true;
                            }
                        }
                    }

                    if (isAdded)
                    {
                        OffsetUrl = response.Result.Offset;
                    }
                    else if (!string.Equals(OffsetUrl, response.Result.Offset, StringComparison.OrdinalIgnoreCase))
                    {
                        OffsetUrl = response.Result.Offset;
                        return(true);
                    }

                    NotifySourceChanged(sender, isAdded);
                }
                if (results.Count < Math.Min(ServerMaxCount, itemsLimit))
                {
                    IsLastReaded = true;
                }
            }
            error = response.Error;
            return(false);
        }
Beispiel #3
0
        private async Task <ErrorBase> DeletePost(Post post, CancellationToken ct)
        {
            var request  = new DeleteModel(User.UserInfo, post);
            var response = await Api.DeletePostOrComment(request, ct);

            if (response.IsSuccess)
            {
                lock (Items)
                {
                    Items.Remove(post);
                    CashPresenterManager.RemoveRef(post);
                }
            }
            return(response.Error);
        }
        private async Task <ErrorBase> Follow(UserFriend item, CancellationToken ct)
        {
            var hasFollowed = item.HasFollowed;
            var request     = new FollowModel(AppSettings.User.UserInfo, item.HasFollowed ? Models.Enums.FollowType.UnFollow : Models.Enums.FollowType.Follow, item.Author);
            var response    = await Api.Follow(request, ct);

            if (response.IsSuccess)
            {
                item.HasFollowed = !hasFollowed;
            }

            CashPresenterManager.Update(item);

            return(response.Error);
        }
        private bool _disposedValue = false; // To detect redundant calls

        private void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    CashPresenterManager.Remove(UserProfileResponse);
                }

                // free unmanaged resources (unmanaged objects) and override a finalizer below.
                // set large fields to null.

                _disposedValue = true;
            }
        }
        public async Task <ErrorBase> TryFollow()
        {
            if (UserProfileResponse.FollowedChanging)
            {
                return(null);
            }

            UserProfileResponse.FollowedChanging = true;
            NotifySourceChanged(nameof(TryFollow), true);

            var error = await TryRunTask(Follow, OnDisposeCts.Token, UserProfileResponse);

            UserProfileResponse.FollowedChanging = false;
            CashPresenterManager.Update(UserProfileResponse);
            NotifySourceChanged(nameof(TryFollow), true);
            return(error);
        }
Beispiel #7
0
        private async Task <ErrorBase> LoadPostInfo(string url, CancellationToken ct)
        {
            var request = new NamedInfoModel(url)
            {
                Login = User.Login
            };

            var response = await Api.GetPostInfo(request, ct);

            if (response.IsSuccess)
            {
                PostInfo = response.Result;
                CashPresenterManager.Add(PostInfo);
                NotifySourceChanged(nameof(TryLoadPostInfo), true);
            }
            return(response.Error);
        }
Beispiel #8
0
        private bool _disposedValue = false; // To detect redundant calls

        private void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    lock (Items)
                    {
                        CashPresenterManager.RemoveAll(Items);
                    }
                }

                // free unmanaged resources (unmanaged objects) and override a finalizer below.
                // set large fields to null.

                _disposedValue = true;
            }
        }
        private async Task <ErrorBase> GetUserInfo(string user, CancellationToken ct)
        {
            var req = new UserProfileModel(user)
            {
                Login        = AppSettings.User.Login,
                ShowNsfw     = AppSettings.User.IsNsfw,
                ShowLowRated = AppSettings.User.IsLowRated
            };
            var response = await Api.GetUserProfile(req, ct);

            if (response.IsSuccess)
            {
                UserProfileResponse = response.Result;
                CashPresenterManager.Add(UserProfileResponse);
                NotifySourceChanged(nameof(TryGetUserInfo), true);
            }
            return(response.Error);
        }
        private async Task <ErrorBase> LoadNextUserFriends(string username, CancellationToken ct)
        {
            if (!FollowType.HasValue)
            {
                return(null);
            }

            var request = new UserFriendsModel(username, FollowType.Value)
            {
                Login  = AppSettings.User.Login,
                Offset = OffsetUrl,
                Limit  = ItemsLimit
            };

            var response = await Api.GetUserFriends(request, ct);

            if (response.IsSuccess)
            {
                var result = response.Result.Results;
                if (result.Count > 0)
                {
                    lock (Items)
                    {
                        Items.AddRange(Items.Count == 0 ? result : result.Skip(1));
                        CashPresenterManager.Add(Items.Count == 0 ? result : result.Skip(1));
                    }

                    OffsetUrl = result.Last().Author;
                }

                if (result.Count < Math.Min(ServerMaxCount, ItemsLimit))
                {
                    IsLastReaded = true;
                }
                NotifySourceChanged(nameof(TryLoadNextUserFriends), true);
            }

            return(response.Error);
        }
        protected Exception ResponseProcessing(OperationResult <Post> response, string sender)
        {
            if (response == null)
            {
                return(null);
            }

            if (response.IsSuccess)
            {
                var isAdded = false;
                var item    = response.Result;
                if (IsValidMedia(item))
                {
                    CashPresenterManager.Add(item);
                    PostInfo = item;
                    isAdded  = true;
                }

                NotifySourceChanged(sender, isAdded);
            }
            return(response.Exception);
        }
        private async Task <ErrorBase> LoadNextPostVoters(string url, CancellationToken ct)
        {
            if (!VotersType.HasValue)
            {
                return(null);
            }

            var request = new VotersModel(url, VotersType.Value)
            {
                Offset = OffsetUrl,
                Limit  = ItemsLimit,
                Login  = AppSettings.User.Login
            };

            var response = await Api.GetPostVoters(request, ct);

            if (response.IsSuccess)
            {
                var voters = response.Result.Results;
                if (voters.Count > 0)
                {
                    lock (Items)
                    {
                        Items.AddRange(Items.Count == 0 ? voters : voters.Skip(1));
                        CashPresenterManager.Add(Items.Count == 0 ? voters : voters.Skip(1));
                    }

                    OffsetUrl = voters.Last().Author;
                }

                if (voters.Count < Math.Min(ServerMaxCount, ItemsLimit))
                {
                    IsLastReaded = true;
                }
                NotifySourceChanged(nameof(TryLoadNextPostVoters), true);
            }
            return(response.Error);
        }
        private async Task <Exception> LoadNextSearchUser(string query, CancellationToken ct)
        {
            if (string.IsNullOrEmpty(query) || query.Length <= 2)
            {
                return(new OperationCanceledException());
            }

            var request = new SearchWithQueryModel(query)
            {
                Limit  = ItemsLimit,
                Offset = OffsetUrl,
                Login  = AppSettings.User.Login
            };

            var response = await Api.SearchUser(request, ct);

            if (response.IsSuccess)
            {
                var result = response.Result.Results;
                if (result.Count > 0)
                {
                    lock (Items)
                    {
                        Items.AddRange(Items.Count == 0 ? result : result.Skip(1));
                        CashPresenterManager.Add(Items.Count == 0 ? result : result.Skip(1));
                    }

                    OffsetUrl = result.Last().Author;
                }

                if (result.Count < Math.Min(ServerMaxCount, ItemsLimit))
                {
                    IsLastReaded = true;
                }
                NotifySourceChanged(nameof(TryLoadNextSearchUser), true);
            }
            return(response.Exception);
        }
 public override void Clear(bool isNotify = true)
 {
     CashPresenterManager.Remove(UserProfileResponse);
     base.Clear(isNotify);
 }