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

Fix/post scheduling hotfix #13726

Merged
merged 6 commits into from
Mar 27, 2020
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
2 changes: 1 addition & 1 deletion WordPress/Classes/Models/AbstractPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ - (void)publishImmediately

- (BOOL)shouldPublishImmediately
{
return [self originalIsDraft] && ![self hasFuturePublishDate];
return [self originalIsDraft] && [self dateCreatedIsNilOrEqualToDateModified];
}

- (NSString *)authorNameForDisplay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extension PostEditor where Self: UIViewController {
!UserDefaults.standard.asyncPromoWasDisplayed {
promoBlock()
} else if action.isAsync,
let postStatus = self.post.status,
let postStatus = self.post.original?.status ?? self.post.status,
![.publish, .publishPrivate].contains(postStatus) {
// Only display confirmation alert for unpublished posts
displayPublishConfirmationAlert(for: action, onPublish: publishBlock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ struct PublishSettingsViewModel {
mutating func setDate(_ date: Date?) {
if let date = date {
post.dateCreated = date
if post.hasFuturePublishDate() {
post.status = .scheduled
} else {
post.status = .publish
}
} else {
post.publishImmediately()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ class PublishSettingsViewControllerTests: XCTestCase {
func testViewModelDateImmediately() {
let testDate = Date()

let post = PostBuilder(context).with(dateCreated: testDate).drafted().withRemote().build()
let post = PostBuilder(context).drafted().withRemote().build()

var viewModel = PublishSettingsViewModel(post: post)
XCTAssertNil(viewModel.date, "Date should not exist in view model")

if case PublishSettingsViewModel.State.immediately = viewModel.state {
// Success
} else {
XCTFail("View model should be immediately")
XCTFail("View model should be immediately instead of \(viewModel.state)")
}

viewModel.setDate(testDate)

if case PublishSettingsViewModel.State.immediately = viewModel.state {
if case PublishSettingsViewModel.State.published(_) = viewModel.state {
// Success
} else {
XCTFail("View model should be immediately instead of \(viewModel.state)")
XCTFail("View model should be published instead of \(viewModel.state)")
}
}

Expand Down