Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.wordpress.android.fluxc.store.PostStore.FetchPostListResponsePayload
import org.wordpress.android.fluxc.store.PostStore.PostError
import org.wordpress.android.fluxc.store.PostStore.PostErrorType.GENERIC_ERROR
import org.wordpress.android.fluxc.store.PostStore.PostListItem
import org.wordpress.android.fluxc.store.PostStore.PostListItem.PostListAutoSave

@RunWith(MockitoJUnitRunner::class)
class PostStoreTest {
Expand Down Expand Up @@ -241,6 +242,6 @@ class PostStoreTest {
post: PostModel,
status: String = post.status,
lastModified: String = post.lastModified,
autoSaveModified: String = post.autoSaveModified
) = PostListItem(post.remotePostId, lastModified, status, autoSaveModified)
autoSave: PostListAutoSave = mock()
) = PostListItem(post.remotePostId, lastModified, status, autoSave)
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public class PostModel extends Payload<BaseNetworkError> implements Cloneable, I
@Column private String mAutoSaveModified; // ISO 8601-formatted date in UTC, e.g. 1955-11-05T14:15:00Z
@Column private String mRemoteAutoSaveModified; // ISO 8601-formatted date in UTC, e.g. 1955-11-05T14:15:00Z
@Column private String mAutoSavePreviewUrl;

@Column private String mAutoSaveTitle;
@Column private String mAutoSaveContent;
@Column private String mAutoSaveExcerpt;

// Local only
@Column private boolean mIsLocalDraft;
Expand Down Expand Up @@ -396,6 +398,30 @@ public void setAutoSavePreviewUrl(String autoSavePreviewUrl) {
mAutoSavePreviewUrl = autoSavePreviewUrl;
}

public String getAutoSaveTitle() {
return mAutoSaveTitle;
}

public void setAutoSaveTitle(String autoSaveTitle) {
mAutoSaveTitle = autoSaveTitle;
}

public String getAutoSaveContent() {
return mAutoSaveContent;
}

public void setAutoSaveContent(String autoSaveContent) {
mAutoSaveContent = autoSaveContent;
}

public String getAutoSaveExcerpt() {
return mAutoSaveExcerpt;
}

public void setAutoSaveExcerpt(String autoSaveExcerpt) {
mAutoSaveExcerpt = autoSaveExcerpt;
}

@Deprecated
public long getLastKnownRemoteFeaturedImageId() {
return mLastKnownRemoteFeaturedImageId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.wordpress.android.fluxc.network.rest.wpcom.revisions.RevisionsResponse.DiffResponsePart;
import org.wordpress.android.fluxc.network.rest.wpcom.revisions.RevisionsResponse.RevisionResponse;
import org.wordpress.android.fluxc.network.rest.wpcom.taxonomy.TermWPComRestResponse;
import org.wordpress.android.fluxc.store.PostStore.RemoteAutoSavePostPayload;
import org.wordpress.android.fluxc.store.PostStore.DeletedPostPayload;
import org.wordpress.android.fluxc.store.PostStore.FetchPostListResponsePayload;
import org.wordpress.android.fluxc.store.PostStore.FetchPostResponsePayload;
Expand All @@ -48,6 +47,8 @@
import org.wordpress.android.fluxc.store.PostStore.PostDeleteActionType;
import org.wordpress.android.fluxc.store.PostStore.PostError;
import org.wordpress.android.fluxc.store.PostStore.PostListItem;
import org.wordpress.android.fluxc.store.PostStore.PostListItem.PostListAutoSave;
import org.wordpress.android.fluxc.store.PostStore.RemoteAutoSavePostPayload;
import org.wordpress.android.fluxc.store.PostStore.RemotePostPayload;
import org.wordpress.android.util.StringUtils;

Expand Down Expand Up @@ -125,13 +126,17 @@ public void fetchPostList(final PostListDescriptorForRestSite listDescriptor, fi
public void onResponse(PostsResponse response) {
List<PostListItem> postListItems = new ArrayList<>(response.getPosts().size());
for (PostWPComRestResponse postResponse : response.getPosts()) {
String autoSaveModified = null;
PostListAutoSave postListAutoSave = new PostListAutoSave();
if (postResponse.getPostAutoSave() != null) {
autoSaveModified = postResponse.getPostAutoSave().getModified();
postListAutoSave.revisionId = postResponse.getPostAutoSave().getRevisionId();
postListAutoSave.title = postResponse.getPostAutoSave().getTitle();
postListAutoSave.content = postResponse.getPostAutoSave().getContent();
postListAutoSave.excerpt = postResponse.getPostAutoSave().getExcerpt();
postListAutoSave.previewUrl = postResponse.getPostAutoSave().getPreviewUrl();
}
postListItems
.add(new PostListItem(postResponse.getRemotePostId(), postResponse.getModified(),
postResponse.getStatus(), autoSaveModified));
postResponse.getStatus(), postListAutoSave));
}
boolean canLoadMore = postListItems.size() == pageSize;
FetchPostListResponsePayload responsePayload =
Expand Down Expand Up @@ -418,6 +423,9 @@ private PostModel postResponseToPostModel(PostWPComRestResponse from) {
post.setAutoSaveModified(autoSave.getModified());
post.setRemoteAutoSaveModified(autoSave.getModified());
post.setAutoSavePreviewUrl(autoSave.getPreviewUrl());
post.setAutoSaveTitle(autoSave.getTitle());
post.setAutoSaveContent(autoSave.getContent());
post.setAutoSaveExcerpt(autoSave.getExcerpt());
}

if (from.getCapabilities() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ data class PostWPComRestResponse(
data class PostAutoSave(
@SerializedName("ID") var revisionId: Long = 0,
@SerializedName("modified") var modified: String? = null,
@SerializedName("preview_URL") var previewUrl: String? = null
@SerializedName("preview_URL") var previewUrl: String? = null,
@SerializedName("title") var title: String? = null,
@SerializedName("content") var content: String? = null,
@SerializedName("excerpt") var excerpt: String? = null
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.wordpress.android.fluxc.store.PostStore.PostError;
import org.wordpress.android.fluxc.store.PostStore.PostErrorType;
import org.wordpress.android.fluxc.store.PostStore.PostListItem;
import org.wordpress.android.fluxc.store.PostStore.PostListItem.PostListAutoSave;
import org.wordpress.android.fluxc.store.PostStore.RemotePostPayload;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
Expand Down Expand Up @@ -347,7 +348,8 @@ public void onErrorResponse(@NonNull BaseNetworkError error) {
Date lastModifiedGmt = MapUtils.getMapDate(postMap, "post_modified_gmt");
String lastModifiedAsIso8601 = DateTimeUtils.iso8601UTCFromDate(lastModifiedGmt);

postListItems.add(new PostListItem(Long.parseLong(postID), lastModifiedAsIso8601, postStatus, null));
postListItems.add(new PostListItem(Long.parseLong(postID), lastModifiedAsIso8601, postStatus,
new PostListAutoSave()));
}
return postListItems;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ public void onUpgrade(SQLiteDatabase db, WellTableManager helper, int oldVersion
db.execSQL("ALTER TABLE PostModel ADD AUTO_SAVE_MODIFIED TEXT");
db.execSQL("ALTER TABLE PostModel ADD REMOTE_AUTO_SAVE_MODIFIED TEXT");
db.execSQL("ALTER TABLE PostModel ADD AUTO_SAVE_PREVIEW_URL TEXT");
db.execSQL("ALTER TABLE PostModel ADD AUTO_SAVE_TITLE TEXT");
db.execSQL("ALTER TABLE PostModel ADD AUTO_SAVE_CONTENT TEXT");
db.execSQL("ALTER TABLE PostModel ADD AUTO_SAVE_EXCERPT TEXT");
oldVersion++;
}
db.setTransactionSuccessful();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,24 @@ public FetchPostListPayload(PostListDescriptor listDescriptor, long offset) {
}

public static class PostListItem {
public static class PostListAutoSave {
public long revisionId = 0;
public String previewUrl;
public String title;
public String content;
public String excerpt;
}

public Long remotePostId;
public String lastModified;
public String status;
public String autoSaveModified;
public PostListAutoSave autoSave;

public PostListItem(Long remotePostId, String lastModified, String status, String autoSaveModified) {
public PostListItem(Long remotePostId, String lastModified, String status, PostListAutoSave autoSave) {
this.remotePostId = remotePostId;
this.lastModified = lastModified;
this.status = status;
this.autoSaveModified = autoSaveModified;
this.autoSave = autoSave;
}
}

Expand Down Expand Up @@ -708,7 +716,8 @@ private void handleFetchedPostList(FetchPostListResponsePayload payload) {
// will not be updated.
boolean isPostChanged =
!post.getLastModified().equals(item.lastModified)
|| !post.getStatus().equals(item.status);
|| !post.getStatus().equals(item.status)
|| item.autoSave.revisionId != post.getAutoSaveRevisionId();

/*
* This is a hacky workaround. When `/autosave` endpoint is invoked on a draft, the server
Expand All @@ -721,8 +730,7 @@ private void handleFetchedPostList(FetchPostListResponsePayload payload) {
* was updated. However, if we know the last modified date is equal to the date we have in local
* autosave object we are sure that our invocation of /autosave updated the post directly.
*/
if (isPostChanged && item.lastModified.equals(post.getAutoSaveModified())
&& item.autoSaveModified == null) {
if (isPostChanged && item.lastModified.equals(post.getAutoSaveModified())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not intentional 🤦‍♂ but I actually found why it was removed (removed a field from PostListItem). Did an extra commit (quite useless since you'll open a followup) 57cc768

isPostChanged = false;
}

Expand All @@ -736,6 +744,11 @@ private void handleFetchedPostList(FetchPostListResponsePayload payload) {
// both locally and on the remote), so flag the local version of the Post so the
// hosting app can inform the user and the user can decide and take action
post.setRemoteLastModified(item.lastModified);
post.setAutoSaveRevisionId(item.autoSave.revisionId);
post.setAutoSaveTitle(item.autoSave.title);
post.setAutoSaveContent(item.autoSave.content);
post.setAutoSaveExcerpt(item.autoSave.excerpt);
post.setAutoSavePreviewUrl(item.autoSave.previewUrl);
mDispatcher.dispatch(PostActionBuilder.newUpdatePostAction(post));
}
}
Expand Down