private async void Like_Click(object sender, RoutedEventArgs e) { LikeButton.IsEnabled = false; try { ApiResponse <CountSchema> result; if (CurrentCommentData.Likes.MyCount == 0) { result = await PostApi.AddLikeComment( SettingsManager.PersistentSettings.CurrentUser.Token, CurrentCommentData.Id) .ConfigureAwait(true); } else { result = await PostApi.RemoveLikeComment( SettingsManager.PersistentSettings.CurrentUser.Token, CurrentCommentData.Id) .ConfigureAwait(true); } if (result.IsError) { await DialogManager.ShowErrorDialog(result.Message) .ConfigureAwait(true); return; } if (CurrentCommentData.Likes.MyCount == 0) { ++CurrentCommentData.Likes.MyCount; } else { --CurrentCommentData.Likes.MyCount; } CurrentCommentData.Likes.TotalCount = result.Data.Count; } finally { LikeButton.IsEnabled = true; } }
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; } } }
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; } } }