Skip to content

Commit

Permalink
Add documentation for auto-save use case
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzkocer committed Feb 13, 2020
1 parent 63fd0fe commit 1268a78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,19 @@ sealed class AutoSavePostIfNotDraftResult(open val post: PostModel) {
AutoSavePostIfNotDraftResult(post)
}

// TODO: Add documentation (add shortcode for the p2 discussion)
// TODO: Add unit tests
/**
* This is a use case that auto-saves a post if it's not a DRAFT in remote and returns various results depending
* on the remote post status and whether network requests were successful.
*
* The reason auto-save is tied to post status is that the `/autosave` REST endpoint will override the changes to
* a `DRAFT` directly rather than auto-saving it. While doing so, it'll also disable comments for the post due to
* a bug. Both the fact that the endpoint does something we are not expecting and the bug that results from it is
* avoided by only calling the `/autosave` endpoint for posts that are not in DRAFT status. We update DRAFTs directly
* just as the endpoint would have, but that makes the logic more clear on the client side while avoiding the
* comments getting disabled bug.
*
* See p3hLNG-15Z-p2 for more info.
*/
class AutoSavePostIfNotDraftUseCase @Inject constructor(
private val dispatcher: Dispatcher,
private val postStore: PostStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,16 @@ private String uploadImageFile(MediaFile mediaFile, SiteModel site) {
}
}

// TODO: document?
@Override
public void handleAutoSavePostIfNotDraftResult(@NotNull AutoSavePostIfNotDraftResult result) {
PostModel post = result.getPost();
if (result instanceof FetchPostStatusFailed
|| result instanceof PostAutoSaveFailed
|| result instanceof PostAutoSaved) {
/*
* If we fail to check the status of the post or auto-save fails, we deliberately don't show an error
* notification since it's not a user initiated action. We'll retry the action later on.
*/
mPostUploadNotifier.incrementUploadedPostCountFromForegroundNotification(post);
finishUpload();
} else if (result instanceof PostIsDraftInRemote) {
Expand Down

0 comments on commit 1268a78

Please sign in to comment.