Ejemplo n.º 1
0
        private async void SendButton_Click(object sender,
                                            RoutedEventArgs e)
        {
            SendButton.IsEnabled = false;

            SendButton.Focus();

            var result = await PostApi.AddComment(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                PostId, ContentTextBox.Text, IsAnonymous)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                await DialogManager.ShowErrorDialog(result.Message)
                .ConfigureAwait(true);

                SendButton.IsEnabled = true;
                return;
            }

            ContentTextBox.Text = string.Empty;

            RaiseEvent(new RoutedEventArgs(CommentAddEvent));

            ContentTextBox.Focus();

            SendButton.IsEnabled = true;
        }
Ejemplo n.º 2
0
        public async Task GetPostFromApiTest()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("{'Text':'This is a post'}"),
            })
            .Verifiable();

            var httpClient = new HttpClient(handlerMock.Object)
            {
                BaseAddress = new Uri("http://test.com/"),
            };

            var unit           = new PostApi(httpClient);
            var postCollection = await unit.GetPostAsync();

            Assert.AreEqual(typeof(Post), postCollection.GetType());
        }
        private async void btnViewsBoost_Click(object sender, RoutedEventArgs e)
        {
            btnViewsBoost.IsEnabled = false;

            try
            {
                for (int i = 0; i < Convert.ToInt32(txtViewsCount.Value); ++i)
                {
                    await PostApi.GetById(Convert.ToInt32(txtPostsPostId.Value))
                    .ConfigureAwait(true);
                }

                await DialogManager.ShowDialog("Success", "BOOOOSTED")
                .ConfigureAwait(true);
            }
            catch (Exception ex)
            {
                await DialogManager.ShowDialog("Some rtarded shit happened", ex.Message)
                .ConfigureAwait(true);
            }
            finally
            {
                btnViewsBoost.IsEnabled = true;
            }
        }
Ejemplo n.º 4
0
        private async Task <int> GetAllPostsCount(int countPerTime, int offset)
        {
            return(await Task.Run(async() =>
            {
                int countNew = 0;

                while (true)
                {
                    var result = await PostApi.GetByUserId(
                        ViewModel.UserId,
                        countPerTime, offset)
                                 .ConfigureAwait(false);

                    if (result?.IsError != false)
                    {
                        continue;
                    }

                    if (result.Data == null)
                    {
                        result.Data = new List <PostSchema>();
                    }

                    if (result.Data.Count == 0)
                    {
                        break;
                    }

                    countNew += result.Data.Count;
                    offset += countPerTime;
                }

                return countNew;
            }).ConfigureAwait(true));
        }
        private async void Delete_Click(object sender, RoutedEventArgs e)
        {
            btnDelete.IsEnabled = false;

            var confirmResult = await DialogManager.ShowConfirmationDialog()
                                .ConfigureAwait(true);

            if (confirmResult != MahApps.Metro.Controls.Dialogs.MessageDialogResult.Affirmative)
            {
                btnDelete.IsEnabled = true;
                return;
            }

            var result = await PostApi.Remove(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                CurrentPostData.Id)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                await DialogManager.ShowErrorDialog(result.Message)
                .ConfigureAwait(true);

                btnDelete.IsEnabled = true;
                return;
            }

            Visibility = Visibility.Collapsed;

            RaiseEvent(new RoutedEventArgs(OnPostDeleted));

            btnDelete.IsEnabled = true;
        }
        private async void btnSpamComments_Click(object sender, RoutedEventArgs e)
        {
            if (_spamCommentsList == null || _spamCommentsList.Length == 0)
            {
                return;
            }

            btnSpamComments.IsEnabled = false;

            try
            {
                for (int i = 0; i < txtCommentsCount.Value; ++i)
                {
                    await PostApi.AddComment(SettingsManager.PersistentSettings.CurrentUser.Token,
                                             int.Parse(txtCommentsPostId?.Value?.ToString() ?? string.Empty),
                                             _spamCommentsList[Random.Next(0, _spamCommentsList.Length - 1)],
                                             chkAnonymousComments.IsChecked)
                    .ConfigureAwait(true);
                }

                await DialogManager.ShowDialog("Success", "Comment section destroyed ;)")
                .ConfigureAwait(true);
            }
            catch (Exception ex)
            {
                await DialogManager.ShowDialog("Some rtarded shit happened", ex.Message)
                .ConfigureAwait(true);
            }
            finally
            {
                btnSpamComments.IsEnabled = true;
            }
        }
Ejemplo n.º 7
0
        public async Task LoadMorePosts(
            PostType type, int count, int offset)
        {
            ShowLoadingMoreGrid();

            try
            {
                var result = await PostApi.Get(
                    SettingsManager.PersistentSettings.CurrentUser.Token,
                    type, count, offset)
                             .ConfigureAwait(true);

                if (result == null)
                {
                    return;
                }

                result.Data ??= new List <PostSchema>();

                await AddMorePosts(result.Data)
                .ConfigureAwait(true);
            }
            finally
            {
                HideLoadingMoreGrid();
            }
        }
Ejemplo n.º 8
0
        public async Task UpdatePost()
        {
            var result = await PostApi.GetById(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                CurrentPostData.Id)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                await DialogManager.ShowErrorDialog(result.Message)
                .ConfigureAwait(true);

                return;
            }

            if (result.Data == null)
            {
                await DialogManager.ShowErrorDialog(result.Message)
                .ConfigureAwait(true);

                return;
            }

            CurrentPostData = result.Data;

            UpdateContextMenus();
        }
        public async Task <PostSchema> GetUpdatedPostData()
        {
            PostSchema postData = null;

            Dispatcher.Invoke(() =>
            {
                postData = ViewModel.CurrentPostData;
            });

            if (postData == null)
            {
                return(postData);
            }

            var result = await PostApi.GetById(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                postData.Id)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                return(postData);
            }

            return(result.Data ?? postData);
        }
Ejemplo n.º 10
0
        private async void btnSend_Click(object sender, RoutedEventArgs e)
        {
            btnSend.IsEnabled = false;

            btnSend.Focus();

            var result = await PostApi.AddComment(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                PostId, txtContent.Text, IsAnonymous)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                await DialogManager.ShowErrorDialog(result.Message)
                .ConfigureAwait(true);

                btnSend.IsEnabled = true;
                return;
            }

            txtContent.Text = string.Empty;

            RaiseEvent(new RoutedEventArgs(OnCommentAdded));

            txtContent.Focus();

            btnSend.IsEnabled = true;
        }
Ejemplo n.º 11
0
        public PostsViewModel(PostApi postApi)
        {
            _postApi = postApi;
            Items    = new ObservableCollection <Post>();

            Task.Run(async() => { await FetchItems(); });
            LoadItemsCommand = new Command(async() => await FetchItems());
        }
Ejemplo n.º 12
0
 public MainViewModel(IMvxNavigationService navigationService, IUserDialogs userDialogs)
 {
     _userDialogs       = userDialogs;
     _navigationService = navigationService;
     _apiPost           = new PostApi <PostModel>("post");
     _apiBanner         = new Api <BannerModel>("banner");
     _apiCategory       = new CategoryApi <CategoryModel>("category");
 }
Ejemplo n.º 13
0
        public PostViewModel(AlbumModel albumSelected)
        {
            postDatabase = App.Container.Resolve <PostDatabase>();
            postApi      = App.Container.Resolve <PostApi>();

            albumModel = albumSelected;

            GetDatabase();
        }
Ejemplo n.º 14
0
        private async void Edit_Click(object sender,
                                      RoutedEventArgs e)
        {
            EditButton.IsEnabled = false;

            try
            {
                if (!CurrentCommentData.User.Id.HasValue || CurrentCommentData.User.Id == -1)
                {
                    return;
                }
                if (CurrentCommentData.User.Id != SettingsManager.PersistentSettings.CurrentUser.Id)
                {
                    return;
                }

                var title   = LocalizationUtils.GetLocalized("EditingCommentTitle");
                var message = LocalizationUtils.GetLocalized("EditingCommentMessage");

                var oldValue = CurrentCommentData.Text;
                var value    = await DialogManager.ShowMultilineTextDialog(
                    title, message, oldValue)
                               .ConfigureAwait(true);

                if (value == null)
                {
                    return;
                }

                var request = await PostApi.EditComment(
                    SettingsManager.PersistentSettings.CurrentUser.Token,
                    CurrentCommentData.Id,
                    value)
                              .ConfigureAwait(true);

                if (request.IsError)
                {
                    await DialogManager.ShowErrorDialog(request.Message)
                    .ConfigureAwait(true);

                    return;
                }

                CurrentCommentData.Text = value;
            }
            finally
            {
                EditButton.IsEnabled = true;
            }
        }
        private async void Edit_Click(object sender, RoutedEventArgs e)
        {
            btnEdit.IsEnabled = false;

            var title   = LocalizationUtils.GetLocalized("EditingPostTitle");
            var message = LocalizationUtils.GetLocalized("EditingPostMessage");

            string oldValue = CurrentPostData.Text;
            string value    = await DialogManager.ShowMultilineTextDialog(
                title, message, oldValue)
                              .ConfigureAwait(true);

            if (value == null)
            {
                btnEdit.IsEnabled = true;
                return;
            }

            PostEditSchema postEditData = new PostEditSchema
            {
                Id             = CurrentPostData.Id,
                Text           = value,
                IsAdult        = CurrentPostData.IsAdult,
                IsAnonymous    = CurrentPostData.IsAnonymous,
                CategoryId     = CurrentPostData.CategoryId,
                Filter         = CurrentPostData.Filter,
                IsHidden       = CurrentPostData.IsHidden,
                IsCommentsOpen = CurrentPostData.IsCommentsOpen,
                Type           = CurrentPostData.Type
            };

            var request = await PostApi.Edit(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                postEditData)
                          .ConfigureAwait(true);

            if (request.IsError)
            {
                await DialogManager.ShowErrorDialog(request.Message)
                .ConfigureAwait(true);

                btnEdit.IsEnabled = true;
                return;
            }

            CurrentPostData.Text = value;

            btnEdit.IsEnabled = true;
        }
Ejemplo n.º 16
0
        private async void Like_Click(object sender,
                                      RoutedEventArgs e)
        {
            LikeButton.IsEnabled = false;

            try
            {
                ApiResponse <CountSchema> result;

                if (CurrentPostData.Likes.MyCount == 0)
                {
                    result = await PostApi.AddLike(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        CurrentPostData.Id)
                             .ConfigureAwait(true);
                }
                else
                {
                    result = await PostApi.RemoveLike(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        CurrentPostData.Id)
                             .ConfigureAwait(true);
                }

                if (result.IsError)
                {
                    await DialogManager.ShowErrorDialog(result.Message)
                    .ConfigureAwait(true);

                    return;
                }

                if (CurrentPostData.Likes.MyCount == 0)
                {
                    ++CurrentPostData.Likes.MyCount;
                }
                else
                {
                    --CurrentPostData.Likes.MyCount;
                }

                CurrentPostData.Likes.TotalCount = result.Data.Count;
            }
            finally
            {
                LikeButton.IsEnabled = true;
            }
        }
Ejemplo n.º 17
0
        private async void Delete_Click(object sender,
                                        RoutedEventArgs e)
        {
            DeleteButton.IsEnabled = false;

            try
            {
                if (!CurrentPostData.OwnerId.HasValue || CurrentPostData.OwnerId == -1)
                {
                    return;
                }
                if (CurrentPostData.OwnerId != SettingsManager.PersistentSettings.CurrentUser.Id)
                {
                    return;
                }

                var confirmResult = await DialogManager.ShowConfirmationDialog()
                                    .ConfigureAwait(true);

                if (confirmResult != MahApps.Metro.Controls.Dialogs.MessageDialogResult.Affirmative)
                {
                    return;
                }

                var result = await PostApi.Remove(
                    SettingsManager.PersistentSettings.CurrentUser.Token,
                    CurrentPostData.Id)
                             .ConfigureAwait(true);

                if (result.IsError)
                {
                    await DialogManager.ShowErrorDialog(result.Message)
                    .ConfigureAwait(true);

                    return;
                }

                Visibility = Visibility.Collapsed;

                RaiseEvent(new RoutedEventArgs(PostDeleteEvent, sender));
            }
            finally
            {
                DeleteButton.IsEnabled = true;
            }
        }
Ejemplo n.º 18
0
        private async void SubmitButton_Click(object sender,
                                              RoutedEventArgs e)
        {
            SubmitButton.IsEnabled = false;

            SubmitButton.Focus();

            try
            {
                var result = await PostApi.Add(
                    SettingsManager.PersistentSettings.CurrentUser.Token,
                    ViewModel.CurrentPostData)
                             .ConfigureAwait(true);

                if (result.IsError)
                {
                    await DialogManager.ShowErrorDialog(result.Message)
                    .ConfigureAwait(true);
                }
                else
                {
                    var message = LocalizationUtils
                                  .GetLocalized("PostSubmittedMessage");

                    await DialogManager.ShowSuccessDialog(message)
                    .ConfigureAwait(true);

                    ClearText();
                    ClearImage();
                }
            }
            catch (Exception ex)
            {
                await DialogManager.ShowErrorDialog(ex.Message)
                .ConfigureAwait(true);
            }
            finally
            {
                SubmitButton.IsEnabled = true;
            }
        }
Ejemplo n.º 19
0
        private async Task <int> GetAllPostsCount(PostType type, int countPerTime, int offset)
        {
            if (!(type == PostType.My || type == PostType.Favorite))
            {
                return(0);
            }

            return(await Task.Run(async() =>
            {
                int countNew = 0;

                while (true)
                {
                    var result = await PostApi.Get(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        type, countPerTime, offset)
                                 .ConfigureAwait(false);

                    if (result?.IsError != false)
                    {
                        continue;
                    }

                    if (result.Data == null)
                    {
                        result.Data = new List <PostSchema>();
                    }

                    if (result.Data.Count == 0)
                    {
                        break;
                    }

                    countNew += result.Data.Count;
                    offset += countPerTime;
                }

                return countNew;
            }).ConfigureAwait(true));
        }
Ejemplo n.º 20
0
        public async Task LoadMoreComments(int count, int offset)
        {
            var result = await PostApi.GetComments(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                PostId, count, offset)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                var message = LocalizationUtils.GetLocalized("CouldNotLoadCommentsMessage");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            await AddMoreComments(result.Data)
            .ConfigureAwait(true);

            RaiseEvent(new RoutedEventArgs(OnCommentsUpdated));
        }
Ejemplo n.º 21
0
        public async Task Share()
        {
            ShareButton.IsEnabled = false;

            try
            {
                if (CurrentPostData.Id == -1)
                {
                    return;
                }

                var link = MemenimProtocolApiUtils.GetPostLink(
                    CurrentPostData.Id);

                Clipboard.SetText(link);

                var result = await PostApi.AddRepost(
                    SettingsManager.PersistentSettings.CurrentUser.Token,
                    CurrentPostData.Id)
                             .ConfigureAwait(true);

                if (result.IsError)
                {
                    await DialogManager.ShowErrorDialog(result.Message)
                    .ConfigureAwait(true);

                    return;
                }

                ++CurrentPostData.Shares;
            }
            finally
            {
                ShareButton.IsEnabled = true;
            }
        }
        public async Task Share()
        {
            stShares.IsEnabled = false;

            Clipboard.SetText($"memenim://app/post/id/{CurrentPostData.Id}");

            var result = await PostApi.AddRepost(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                CurrentPostData.Id)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                await DialogManager.ShowErrorDialog(result.Message)
                .ConfigureAwait(true);

                stShares.IsEnabled = true;
                return;
            }

            ++CurrentPostData.Shares;

            stShares.IsEnabled = true;
        }
Ejemplo n.º 23
0
        public async Task LoadMorePosts(int count, int offset)
        {
            ShowLoadingMoreGrid(true);

            var result = await PostApi.GetByUserId(
                ViewModel.UserId,
                count, offset)
                         .ConfigureAwait(true);

            if (result == null)
            {
                return;
            }

            if (result.Data == null)
            {
                result.Data = new List <PostSchema>();
            }

            await AddMorePosts(result.Data)
            .ConfigureAwait(true);

            ShowLoadingMoreGrid(false);
        }
        public async Task UpdatePost(int id)
        {
            if (id < 1)
            {
                if (!NavigationController.Instance.IsCurrentPage <PostOverlayPage>())
                {
                    return;
                }

                NavigationController.Instance.GoBack(true);

                string message = LocalizationUtils.GetLocalized("PostNotFound");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            ViewModel.CurrentPostData.Id = id;

            var result = await PostApi.GetById(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                ViewModel.CurrentPostData.Id)
                         .ConfigureAwait(true);

            if (result.IsError)
            {
                if (!NavigationController.Instance.IsCurrentPage <PostOverlayPage>())
                {
                    return;
                }

                NavigationController.Instance.GoBack(true);

                await DialogManager.ShowErrorDialog(result.Message)
                .ConfigureAwait(true);

                return;
            }

            if (result.Data == null)
            {
                if (!NavigationController.Instance.IsCurrentPage <PostOverlayPage>())
                {
                    return;
                }

                NavigationController.Instance.GoBack(true);

                string message = LocalizationUtils.GetLocalized("PostNotFound");

                await DialogManager.ShowErrorDialog(message)
                .ConfigureAwait(true);

                return;
            }

            ViewModel.CurrentPostData = result.Data;

            wdgPost.UpdateContextMenus();

            if (ViewModel.SourcePostWidget?.CurrentPostData.Id == ViewModel.CurrentPostData.Id)
            {
                ViewModel.SourcePostWidget?.SetValue(
                    PostWidget.CurrentPostDataProperty,
                    ViewModel.CurrentPostData);
            }
        }
Ejemplo n.º 25
0
        private async void Dislike_Click(object sender,
                                         RoutedEventArgs e)
        {
            DislikeButton.IsEnabled = false;

            try
            {
                ApiResponse <CountSchema> result;

                if (CurrentPostData.Dislikes.MyCount == 0)
                {
                    result = await PostApi.AddDislike(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        CurrentPostData.Id)
                             .ConfigureAwait(true);
                }
                else
                {
                    result = await PostApi.RemoveDislike(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        CurrentPostData.Id)
                             .ConfigureAwait(true);
                }

                if (result.IsError)
                {
                    if (string.Compare(result.Message, "id is not defined", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (CurrentPostData.Dislikes.MyCount == 0)
                        {
                            ++CurrentPostData.Dislikes.MyCount;
                            ++CurrentPostData.Dislikes.TotalCount;
                        }
                        else
                        {
                            --CurrentPostData.Dislikes.MyCount;
                            --CurrentPostData.Dislikes.TotalCount;
                        }

                        return;
                    }

                    await DialogManager.ShowErrorDialog(result.Message)
                    .ConfigureAwait(true);

                    return;
                }

                if (CurrentPostData.Dislikes.MyCount == 0)
                {
                    ++CurrentPostData.Dislikes.MyCount;
                }
                else
                {
                    --CurrentPostData.Dislikes.MyCount;
                }

                CurrentPostData.Dislikes.TotalCount = result.Data.Count;
            }
            finally
            {
                DislikeButton.IsEnabled = true;
            }
        }
Ejemplo n.º 26
0
        public async Task <int> GetNewPostsCount(
            PostType type, int countPerTime, int offset)
        {
            var postsCount = 0;

            Dispatcher.Invoke(() =>
            {
                postsCount = PostsWrapPanel.Children.Count;
            });

            if (postsCount == 0)
            {
                if (type == PostType.My || type == PostType.Favorite)
                {
                    return(await GetAllPostsCount(
                               type, countPerTime, offset)
                           .ConfigureAwait(true));
                }

                return(0);
            }

            var headOldId = -1;

            Dispatcher.Invoke(() =>
            {
                headOldId = ViewModel.LastNewHeadPostId;
            });

            if (headOldId == -1)
            {
                return(0);
            }

            return(await Task.Run(async() =>
            {
                var countNew = 0;
                var headNewId = -1;
                var headOldIsFound = false;
                var isFirstRequest = true;

                while (!headOldIsFound)
                {
                    var result = await PostApi.Get(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        type, countPerTime, offset)
                                 .ConfigureAwait(false);

                    if (result?.IsError != false)
                    {
                        continue;
                    }

                    result.Data ??= new List <PostSchema>();

                    if (result.Data.Count == 0)
                    {
                        await Dispatcher.Invoke(() =>
                        {
                            return UpdatePosts();
                        }).ConfigureAwait(true);

                        return 0;
                    }

                    if (isFirstRequest)
                    {
                        headNewId = result.Data[0].Id;
                        isFirstRequest = false;
                    }

                    foreach (var post in result.Data)
                    {
                        if (post.Id == headOldId)
                        {
                            headOldIsFound = true;

                            break;
                        }

                        ++countNew;
                    }

                    if (countNew >= 500)
                    {
                        await Dispatcher.Invoke(() =>
                        {
                            return UpdatePosts();
                        }).ConfigureAwait(true);

                        return 0;
                    }

                    offset += countPerTime;
                }

                Dispatcher.Invoke(() =>
                {
                    ViewModel.LastNewHeadPostId = headNewId;
                });

                return countNew;
            }).ConfigureAwait(true));
        }
Ejemplo n.º 27
0
 public PostViewModel(IMvxNavigationService navigationService, IUserDialogs userDialogs)
 {
     _userDialogs       = userDialogs;
     _navigationService = navigationService;
     _api = new PostApi <PostModel>("post");
 }
Ejemplo n.º 28
0
        private async void CommentsList_CommentReply(object sender,
                                                     RoutedEventArgs e)
        {
            if (!(sender is CommentsList))
            {
                return;
            }
            if (!(e.OriginalSource is Comment comment))
            {
                return;
            }

            var verticalOffset   = PostScrollViewer.VerticalOffset;
            var scrollableHeight = PostScrollViewer.ScrollableHeight;
            var userNickname     = !string.IsNullOrEmpty(comment.CurrentCommentData.User.Nickname)
                ? comment.CurrentCommentData.User.Nickname
                : "Unknown";

            string replyText;

            switch (SettingsManager.AppSettings.CommentReplyModeEnum)
            {
            case CommentReplyModeType.Experimental:
                replyText =
                    $">>> {userNickname}:\n\n"
                    + $"{comment.CurrentCommentData.Text}\n\n"
                    + ">>>\n\n";
                break;

            case CommentReplyModeType.Legacy:
            default:
                replyText =
                    $"{userNickname}, ";
                break;
            }

            var oldCaretIndex = WriteComment.ContentTextBox.CaretIndex;

            WriteComment.CommentText = replyText + WriteComment.CommentText;
            WriteComment.ContentTextBox.CaretIndex = replyText.Length + oldCaretIndex;
            WriteComment.ContentTextBox.ScrollToEnd();
            WriteComment.ContentTextBox.Focus();

            if (verticalOffset >= scrollableHeight - 20)
            {
                PostScrollViewer.ScrollToEnd();
            }

            if (comment.CurrentCommentData.User.Id.HasValue &&
                comment.CurrentCommentData.User.Id == SettingsManager.PersistentSettings.CurrentUser.Id)
            {
                return;
            }

            for (var i = 0; i < 2; ++i)
            {
                if (comment.CurrentCommentData.Likes.MyCount == 0)
                {
                    await PostApi.AddLikeComment(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        comment.CurrentCommentData.Id)
                    .ConfigureAwait(true);
                }
                else
                {
                    await PostApi.RemoveLikeComment(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        comment.CurrentCommentData.Id)
                    .ConfigureAwait(true);
                }

                if (comment.CurrentCommentData.Likes.MyCount == 0)
                {
                    ++comment.CurrentCommentData.Likes.MyCount;
                }
                else
                {
                    --comment.CurrentCommentData.Likes.MyCount;
                }
            }
        }
Ejemplo n.º 29
0
 public AddPostViewModel(PostApi postApi)
 {
     _postApi = postApi;
 }
        private async void CommentsList_CommentReply(object sender, RoutedEventArgs e)
        {
            CommentsList commentsList = sender as CommentsList;

            if (commentsList == null)
            {
                return;
            }

            UserComment comment = e.OriginalSource as UserComment;

            if (comment == null)
            {
                return;
            }

            double verticalOffset          = svPost.VerticalOffset;
            double scrollableHeight        = svPost.ScrollableHeight;
            CommentReplyModeType replyType = (CommentReplyModeType)SettingsManager.AppSettings.CommentReplyMode;

            string replyText;

            switch (replyType)
            {
            case CommentReplyModeType.Experimental:
                replyText =
                    //$">>> {commentsList.PostId}@{comment.CurrentCommentData.Id}@{comment.CurrentCommentData.User.Id} {comment.CurrentCommentData.User.Nickname}:\n\n"
                    $">>> {(string.IsNullOrEmpty(comment.CurrentCommentData.User.Nickname) ? "Unknown" : comment.CurrentCommentData.User.Nickname)}:\n\n"
                    + $"{comment.CurrentCommentData.Text}\n\n"
                    + ">>>\n\n";
                break;

            case CommentReplyModeType.Legacy:
            default:
                replyText =
                    $"{(string.IsNullOrEmpty(comment.CurrentCommentData.User.Nickname) ? "Unknown" : comment.CurrentCommentData.User.Nickname)}, ";
                break;
            }

            int oldCaretIndex = wdgWriteComment.txtContent.CaretIndex;

            wdgWriteComment.CommentText           = replyText + wdgWriteComment.CommentText;
            wdgWriteComment.txtContent.CaretIndex = replyText.Length + oldCaretIndex;
            wdgWriteComment.txtContent.ScrollToEnd();
            wdgWriteComment.txtContent.Focus();

            if (verticalOffset >= scrollableHeight - 20)
            {
                svPost.ScrollToEnd();
            }

            if (comment.CurrentCommentData.User.Id.HasValue &&
                comment.CurrentCommentData.User.Id == SettingsManager.PersistentSettings.CurrentUser.Id)
            {
                return;
            }

            for (int i = 0; i < 2; ++i)
            {
                if (comment.CurrentCommentData.Likes.MyCount == 0)
                {
                    await PostApi.AddLikeComment(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        comment.CurrentCommentData.Id)
                    .ConfigureAwait(true);
                }
                else
                {
                    await PostApi.RemoveLikeComment(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        comment.CurrentCommentData.Id)
                    .ConfigureAwait(true);
                }

                if (comment.CurrentCommentData.Likes.MyCount == 0)
                {
                    ++comment.CurrentCommentData.Likes.MyCount;
                }
                else
                {
                    --comment.CurrentCommentData.Likes.MyCount;
                }
            }
        }