-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add new "Publishing" sheet #24855
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
Add new "Publishing" sheet #24855
Changes from all commits
6a35a45
60fe6f6
3e66947
3444865
82566d0
b99cca2
d11b2f7
a00f718
0c394ff
91ee556
63fd4c7
bd140e8
3aad454
5158a32
c33eea5
c77cc82
6c05fec
8957da2
1a0e244
fea38bf
e26d8c3
b48cd96
ac21b47
957d1bc
02a9b8f
21a503f
bed2444
35bd98b
ce85c78
df872d4
5f5a0d6
bca323b
1bcae82
258f4b8
5eee225
accc2e5
bd02f28
c855e06
ead649d
1e79d33
9b1648d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,43 @@ class PostCoordinator: NSObject { | |
} | ||
} | ||
|
||
/// Publishes the post according to the current settings and user capabilities. | ||
/// | ||
/// - warning: Before publishing, ensure that the media for the post got | ||
/// uploaded. Managing media is not the responsibility of `PostRepository.` | ||
/// | ||
/// - parameter changes: The set of changes apply to the post together | ||
/// with the publishing options. | ||
@MainActor | ||
func publish_v2(_ post: AbstractPost, parameters: RemotePostUpdateParameters) async throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I plan to remove the previous version in the next PR where the legacy screen is removed. |
||
wpAssert(post.isOriginal()) | ||
wpAssert(post.isStatus(in: [.draft, .pending])) | ||
|
||
await pauseSyncing(for: post) | ||
defer { resumeSyncing(for: post) } | ||
|
||
var parameters = parameters | ||
if parameters.status == nil { | ||
parameters.status = Post.Status.publish.rawValue | ||
} | ||
if parameters.date == nil { | ||
// If the post was previously scheduled for a different date, | ||
// the app has to send a new value to override it. | ||
parameters.date = post.shouldPublishImmediately() ? nil : Date() | ||
} | ||
|
||
do { | ||
let repository = PostRepository(coreDataStack: coreDataStack) | ||
try await repository.save(post, changes: parameters) | ||
didPublish(post) | ||
show(PostCoordinator.makeUploadSuccessNotice(for: post)) | ||
} catch { | ||
trackError(error, operation: "post-publish", post: post) | ||
handleError(error, for: post) | ||
throw error | ||
} | ||
} | ||
|
||
@MainActor | ||
private func didPublish(_ post: AbstractPost) { | ||
if post.status == .scheduled { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ struct PostSettings: Hashable { | |
// MARK: - Post-specific | ||
var postFormat: String? | ||
var isStickyPost = false | ||
var sharing: PostSocialSharingSettings? | ||
|
||
// MARK: - Page-specific | ||
var parentPageID: Int? | ||
|
@@ -36,7 +37,7 @@ struct PostSettings: Hashable { | |
excerpt = post.mt_excerpt ?? "" | ||
slug = post.wp_slug ?? "" | ||
status = post.status ?? .draft | ||
publishDate = post.dateCreated | ||
publishDate = post.shouldPublishImmediately() ? nil : post.dateCreated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lore: #23333 (comment) |
||
password = post.password | ||
|
||
if let authorID = post.authorID?.intValue, authorID > 0 { | ||
|
@@ -57,6 +58,7 @@ struct PostSettings: Hashable { | |
categoryIDs = Set((post.categories ?? []).compactMap { | ||
$0.categoryID?.intValue | ||
}) | ||
sharing = PostSocialSharingSettings.make(for: post) | ||
case let page as Page: | ||
parentPageID = page.parentID?.intValue | ||
default: | ||
|
@@ -129,6 +131,22 @@ struct PostSettings: Hashable { | |
if post.isStickyPost != isStickyPost { | ||
post.isStickyPost = isStickyPost | ||
} | ||
|
||
if let sharing { | ||
for connection in sharing.services.flatMap(\.connections) { | ||
let keyringID = NSNumber(value: connection.keyringID) | ||
if !post.publicizeConnectionDisabledForKeyringID(keyringID) != connection.enabled { | ||
if connection.enabled { | ||
post.enablePublicizeConnectionWithKeyringID(keyringID) | ||
} else { | ||
post.disablePublicizeConnectionWithKeyringID(keyringID) | ||
} | ||
} | ||
} | ||
if post.publicizeMessage != sharing.message { | ||
post.publicizeMessage = sharing.message | ||
} | ||
} | ||
case let page as Page: | ||
if page.parentID?.intValue != parentPageID { | ||
page.parentID = parentPageID.map { NSNumber(value: $0) } | ||
|
@@ -186,3 +204,70 @@ extension PostSettings { | |
.map { $0.stringByDecodingXMLCharacters() } | ||
} | ||
} | ||
|
||
/// A value-type representation of `PublicizeService` for the current blog that's simplified for the auto-sharing flow. | ||
struct PostSocialSharingSettings: Hashable { | ||
var services: [Service] | ||
var message: String | ||
var sharingLimit: PublicizeInfo.SharingLimit? | ||
|
||
struct Service: Hashable { | ||
let name: PublicizeService.ServiceName | ||
var connections: [Connection] | ||
} | ||
|
||
struct Connection: Hashable { | ||
let account: String | ||
let keyringID: Int | ||
var enabled: Bool | ||
} | ||
|
||
static func make(for post: Post) -> PostSocialSharingSettings? { | ||
guard let context = post.managedObjectContext else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied most of the social-sharing code from the existing |
||
wpAssertionFailure("missing moc") | ||
return nil | ||
} | ||
|
||
let connections = post.blog.sortedConnections | ||
|
||
// first, build a dictionary to categorize the connections. | ||
var connectionsMap = [PublicizeService.ServiceName: [PublicizeConnection]]() | ||
connections.filter { !$0.requiresUserAction() }.forEach { connection in | ||
let name = PublicizeService.ServiceName(rawValue: connection.service) ?? .unknown | ||
var serviceConnections = connectionsMap[name] ?? [] | ||
serviceConnections.append(connection) | ||
connectionsMap[name] = serviceConnections | ||
} | ||
|
||
let publicizeServices: [PublicizeService] | ||
do { | ||
publicizeServices = try PublicizeService.allPublicizeServices(in: context) | ||
} catch { | ||
wpAssertionFailure("failed to fetch services", userInfo: ["error": error.localizedDescription]) | ||
return nil | ||
} | ||
|
||
let services = publicizeServices.compactMap { service -> PostSocialSharingSettings.Service? in | ||
// skip services without connections. | ||
guard let serviceConnections = connectionsMap[service.name], | ||
!serviceConnections.isEmpty else { | ||
return nil | ||
} | ||
|
||
return PostSocialSharingSettings.Service( | ||
name: service.name, | ||
connections: serviceConnections.map { | ||
.init(account: $0.externalDisplay, | ||
keyringID: $0.keyringConnectionID.intValue, | ||
enabled: !post.publicizeConnectionDisabledForKeyringID($0.keyringConnectionID)) | ||
} | ||
) | ||
} | ||
|
||
return PostSocialSharingSettings( | ||
services: services, | ||
message: post.publicizeMessage ?? post.titleForDisplay(), | ||
sharingLimit: post.blog.sharingLimit | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small change to make the corner radius work better with the larger radius on iOS 26.