Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only extract author info on a new Post / Page if the user can query for authors. #16870

Merged
merged 1 commit into from
Jul 16, 2021
Merged
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
8 changes: 4 additions & 4 deletions WordPress/Classes/Services/PostService.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ - (Post *)createPostForBlog:(Blog *)blog {
post.postType = Post.typeDefaultIdentifier;

BlogAuthor *author = [blog getAuthorWithId:blog.userID];
post.authorID = author.userID ?: blog.account.userID;
post.author = author.displayName ?: blog.account.displayName;
post.authorID = author.userID;
Copy link
Contributor Author

@twstokes twstokes Jul 15, 2021

Choose a reason for hiding this comment

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

Originally we fell back on the blog.account.userID if we had no hit with getAuthorWithId, but I don't believe this was necessary. Tracking the author ID and display name is only needed to have for the UI to switch authors.

Therefore if we don't have authors to choose from, we won't be doing any switching. When authorID is nil here, it won't be passed to the API and the update will be done "as the current user".

post.author = author.displayName;

[blog.managedObjectContext obtainPermanentIDsForObjects:@[post] error:nil];
NSAssert(![post.objectID isTemporaryID], @"The new post for this blog must have a permanent ObjectID");
Expand All @@ -77,8 +77,8 @@ - (Page *)createPageForBlog:(Blog *)blog {
page.remoteStatus = AbstractPostRemoteStatusSync;

BlogAuthor *author = [blog getAuthorWithId:blog.userID];
page.authorID = author.userID ?: blog.account.userID;
page.author = author.displayName ?: blog.account.displayName;
page.authorID = author.userID;
page.author = author.displayName;

[blog.managedObjectContext obtainPermanentIDsForObjects:@[page] error:nil];
NSAssert(![page.objectID isTemporaryID], @"The new page for this blog must have a permanent ObjectID");
Expand Down