Skip to content

Check for upload changes to determine need to update Post content#6655

Merged
nbradbury merged 3 commits intodevelopfrom
issue/6654-look-for-completed-uploads-and-update-post-when-exiting
Sep 22, 2017
Merged

Check for upload changes to determine need to update Post content#6655
nbradbury merged 3 commits intodevelopfrom
issue/6654-look-for-completed-uploads-and-update-post-when-exiting

Conversation

@mzorz
Copy link
Copy Markdown
Contributor

@mzorz mzorz commented Sep 22, 2017

Fixes #6654

The reason it was failing as described in #6654 is because we look for changes only by checking whether the Aztec editor has a Change History (change introduced in #6610). Given the completed uploads actually do change the URL but they do so in the background, thus not affecting Aztec’s Change History, we think there’s nothing new and thus we don’t save the latest Post content (with the updated remote URLS for media that have been uploaded).

It is not trivial to understand which changes need to be saved, given a dumb string comparison can return different strings for semantically identical HTML content (for instance, the order in which a div class appears makes the string different but the HTML piece is no different from each other).

So, this PR tackles this by relying on what we do know: when the Editor is opened, we know which media items in the Post content are marked as being uploaded. Same thing when the Editor is closed: when the user exits the editor, and we have any change in uploads for this Post (i.e. the existing uploads when we opened the Editor have now completed when we try to exit the Editor), then we need to save the Post content as a change in the media items URL has happened.

To test:

FOR IMAGES:

  1. start a new draft
  2. insert an image
  3. while the image is uploading, exit the editor
  4. enter the editor again
  5. confirm the progress gets re-attached
  6. wait until the image is finished uploading
  7. tap on the image, confirm the image settings screen is displayed
  8. exit the editor
  9. enter the editor for that post again
  10. tap on the image, observe the image settings screen is displayed

FOR VIDEOS:

  1. start a new draft
  2. insert a video
  3. while the video is uploading, exit the editor
  4. enter the editor again
  5. confirm the progress gets re-attached
  6. wait until the video is finished uploading
  7. tap on the video, confirm the player is executed
  8. exit the editor
  9. enter the editor for that post again
  10. observe it's there and can be played - also observe the URL to it is the remote one.

cc @nbradbury

…ned in the edditor, and compares to a current list when the user exits, to determine if contents have changed and post needs be saved
} else if (!((AztecEditorFragment)mEditorFragment).isHistoryEnabled()){
// if history is not enabled, then we can only confirm whether there's been a content change
// by comparing content
boolean contentChanged = compareCurrentMediaMarkedUploadingToOriginal(content);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like this whole block could be simplified to:

boolean contentChanged;
if (compareCurrentMediaMarkedUploadingToOriginal(content)) {
    contentChanged = true;
} else if (mEditorFragment instanceof AztecEditorFragment 
        && ((AztecEditorFragment) mEditorFragment).isHistoryEnabled()) {
    contentChanged = ((AztecEditorFragment) mEditorFragment).hasHistory();
} else {
    contentChanged = mPost.getContent().compareTo(content) != 0;
}
if (contentChanged) {
    mPost.setContent(content);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent - just tested it in all 3 cases (images, video, and just user changes through the editor). Replaced the code with your block in ccf116b

@nbradbury nbradbury self-assigned this Sep 22, 2017
private boolean compareCurrentMediaMarkedUploadingToOriginal(String newContent) {
List<String> currentUploadingMedia = AztecEditorFragment.getMediaMarkedUploadingInPostContent(this, newContent);
Collections.sort(currentUploadingMedia);
return !mMediaMarkedUploadingOnStartIds.equals(currentUploadingMedia);
Copy link
Copy Markdown
Contributor

@nbradbury nbradbury Sep 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since mMediaMarkedUploadingOnStartIds is left unchanged here, won't this method return true every time it's called if changes were detected the first time this is called?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as changes happen in between the user opened the Editor (which is when mMediaMarkedUploadingOnStartIds is populated) and exiting the Editor, that's exactly the window we want to cover, so yes it'd be fine. Unless I'm not seeing some side effect of it that could potentially be harmful?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a media item finished uploading between the start of the activity and the first time updatePostContentNewEditor is called, then every time it's called afterwards it will also return true. Looking at the flow from savePostAsync > updatePostObject > updatePostContentNewEditor, won't this mean that the post could be updated (and uploaded) unnecessarily?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok good catch, addressed in 9015bff

@nbradbury
Copy link
Copy Markdown
Contributor

:shipit:

@nbradbury nbradbury merged commit 5000162 into develop Sep 22, 2017
@nbradbury nbradbury deleted the issue/6654-look-for-completed-uploads-and-update-post-when-exiting branch September 22, 2017 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async media: broken reattachment identification

2 participants