/// <summary> /// Called when the send button is tapped. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Send_Click(object sender, RoutedEventArgs e) { // Make sure we have a string unless we are editing a post selftext, then we can have an empty comment. string comment = ui_textBox.Text; if (String.IsNullOrWhiteSpace(comment) && !m_itemRedditId.StartsWith("t3_") && !m_isEdit) { App.BaconMan.MessageMan.ShowMessageSimple("\"Silence is a source of great strength.\" - Lao Tzu", "Except on reddit. Go on, say something."); return; } // Show loading ui_sendingOverlayProgress.IsActive = true; VisualStateManager.GoToState(this, "ShowOverlay", true); // Try to send the comment string response = await Task.Run(() => MiscellaneousHelper.SendRedditComment(App.BaconMan, m_itemRedditId, comment, m_isEdit)); if (response != null) { // Now fire the event that a comment was submitted. try { OnCommentSubmittedArgs args = new OnCommentSubmittedArgs() { Response = response, IsEdit = m_isEdit, RedditId = m_itemRedditId, Context = m_context, }; m_onCommentSubmitted.Raise(this, args); } catch (Exception ex) { App.BaconMan.MessageMan.DebugDia("failed to fire OnCommentSubmitted", ex); App.BaconMan.TelemetryMan.ReportUnexpectedEvent(this, "OnCommentSubmittedFireFailed", ex); } } else { // The network call failed. App.BaconMan.MessageMan.ShowMessageSimple("Can't Submit", "We can't seem to submit this right now, check your internet connection."); HideLoadingOverlay(); } }
/// <summary> /// Fired when content has been submitted in the comment box. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CommentBox_OnCommentSubmitted(object sender, OnCommentSubmittedArgs e) { OnOpenCommentBox openBoxContext = (OnOpenCommentBox)e.Context; if (openBoxContext != null) { // Replace the context e.Context = openBoxContext.Context; bool wasActionSuccessful = openBoxContext.CommentBoxSubmitted(sender, e); // Hide the box if good if (wasActionSuccessful) { ui_commentBox.HideBox(true); } else { ui_commentBox.HideLoadingOverlay(); } } }
/// <summary> /// Fired when the comment in the comment box was submitted /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private bool CommentBox_OnCommentSubmitted(object sender, OnCommentSubmittedArgs e) { bool wasActionSuccessful = false; FlipViewPostContext context = GetContext(); if(context == null) { return wasActionSuccessful; } if (e.RedditId.StartsWith("t3_")) { Post post = (Post)e.Context; if (post != null) { if (e.IsEdit) { // We edited selftext wasActionSuccessful = context.Collector.EditSelfPost(post, e.Response); if (wasActionSuccessful) { // If we are successful to update the UI we will remove the post // and reallow it. ContentPanelMaster.Current.RemoveAllowedContent(post.Id); // Now ask the host to reallow it. m_onContentLoadRequest.Raise(this, new OnContentLoadRequestArgs() { SourceId = post.Id }); } } else { // We added a new comment FlipViewPostCommentManager manager = GetCommentManger(); if (manager != null) { wasActionSuccessful = manager.CommentAddedOrEdited("t3_" + post.Id, e); } else { App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "CommentSubmitManagerObjNull"); } } } else { App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "CommentSubmitPostObjNull"); } } else if (e.RedditId.StartsWith("t1_")) { Comment comment = (Comment)e.Context; if (comment != null) { // Comment added or edited. FlipViewPostCommentManager manager = GetCommentManger(); if (manager != null) { wasActionSuccessful = manager.CommentAddedOrEdited("t1_" + comment.Id, e); } else { App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "CommentSubmitManagerObjNull"); } } else { App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "CommentSubmitCommentObjNull"); } } return wasActionSuccessful; }
/// <summary> /// Fired when a new message has been submitted. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ReplyBox_OnCommentSubmitted(object sender, OnCommentSubmittedArgs e) { // Validate the response, this isn't 100% fool proof but it is close. if(e.Response.Contains("\"author\":")) { // We are good, hide the box ui_replyBox.HideBox(); } else { ui_replyBox.HideLoadingOverlay(); App.BaconMan.MessageMan.ShowMessageSimple("That's Not Good", "We can't send this message right now, reddit returned an unexpected result. Try again later."); } }
/// <summary> /// Called when is added or edited /// </summary> public bool CommentAddedOrEdited(string parentOrOrgionalId, OnCommentSubmittedArgs args) { return ((CommentCollector)m_commentCollector.GetCollector()).CommentAddedOrEdited(parentOrOrgionalId, args.Response, args.IsEdit); }
/// <summary> /// Called when the send button is tapped. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Send_Click(object sender, RoutedEventArgs e) { // Make sure we have a string unless we are editing a post selftext, then we can have an empty comment. string comment = ui_textBox.Text; if(String.IsNullOrWhiteSpace(comment) && !m_itemRedditId.StartsWith("t3_") && !m_isEdit) { App.BaconMan.MessageMan.ShowMessageSimple("\"Silence is a source of great strength.\" - Lao Tzu", "Except on reddit. Go on, say something."); return; } // Show loading ui_sendingOverlayProgress.IsActive = true; VisualStateManager.GoToState(this, "ShowOverlay", true); // Try to send the comment string response = await Task.Run(() => MiscellaneousHelper.SendRedditComment(App.BaconMan, m_itemRedditId, comment, m_isEdit)); if (response != null) { // Now fire the event that a comment was submitted. try { OnCommentSubmittedArgs args = new OnCommentSubmittedArgs() { Response = response, IsEdit = m_isEdit, RedditId = m_itemRedditId, Context = m_context, }; m_onCommentSubmitted.Raise(this, args); } catch (Exception ex) { App.BaconMan.MessageMan.DebugDia("failed to fire OnCommentSubmitted", ex); App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "OnCommentSubmittedFireFailed", ex); } } else { // The network call failed. App.BaconMan.MessageMan.ShowMessageSimple("Can't Submit", "We can't seem to submit this right now, check your internet connection."); HideLoadingOverlay(); } }
/// <summary> /// Fired when the comment in the comment box was submitted /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CommentBox_OnCommentSubmitted(object sender, OnCommentSubmittedArgs e) { bool wasActionSuccessful = false; if(e.RedditId.StartsWith("t3_")) { Post post = (Post)e.Context; if(post != null) { if (e.IsEdit) { // We edited selftext wasActionSuccessful = m_collector.EditSelfPost(post, e.Response); if(wasActionSuccessful) { // If we are successful to update the UI we will remove the post // and reallow it. ContentPanelMaster.Current.RemoveAllowedContent(post.Id); ContentPanelSource soruce = ContentPanelSource.CreateFromPost(post); ContentPanelMaster.Current.AddAllowedContent(soruce, m_uniqueId); } } else { // We added a new comment FlipViewPostCommentManager manager = FindCommentManager(post.Id); if (manager != null) { wasActionSuccessful = manager.CommentAddedOrEdited("t3_"+post.Id, e); } else { App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "CommentSubmitManagerObjNull"); } } } else { App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "CommentSubmitPostObjNull"); } } else if(e.RedditId.StartsWith("t1_")) { Comment comment = (Comment)e.Context; if(comment != null) { // Comment added or edited. FlipViewPostCommentManager manager = FindCommentManager(comment.LinkId); if (manager != null) { wasActionSuccessful = manager.CommentAddedOrEdited("t1_"+comment.Id, e); } else { App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "CommentSubmitManagerObjNull"); } } else { App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "CommentSubmitCommentObjNull"); } } // Hide the box if good if(wasActionSuccessful) { ui_commentBox.HideBox(true); } else { ui_commentBox.HideLoadingOverlay(); } }
/// <summary> /// Called when is added or edited /// </summary> public bool CommentAddedOrEdited(string parentOrOrgionalId, OnCommentSubmittedArgs args) { DeferredCollector<Comment> collector = EnsureCollector(); return ((CommentCollector)collector.GetCollector()).CommentAddedOrEdited(parentOrOrgionalId, args.Response, args.IsEdit); }