-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Translate AbstractPost to Swift #25040
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
Changes from 12 commits
330e8d1
f52edc9
9ac6b97
1bc7975
9ef8896
a21936d
768909f
cc1f476
2c07371
18c339d
2ffffa6
086eca5
31ff198
0560fac
8f80ed0
83c8cc0
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 |
|---|---|---|
|
|
@@ -328,4 +328,114 @@ | |
| func hasRevision() -> Bool { | ||
| revision != nil | ||
| } | ||
|
|
||
| /// Returns YES if the post is has a `future` post status | ||
| @objc | ||
| func isScheduled() -> Bool { | ||
| status == .scheduled | ||
| } | ||
|
|
||
| /// Returns YES if the post is a draft | ||
| @objc | ||
| func isDraft() -> Bool { | ||
| status == .draft | ||
| } | ||
|
|
||
| /// Returns YES if the post is a published. | ||
| @objc | ||
| func isPublished() -> Bool { | ||
| status == .publish | ||
| } | ||
|
|
||
| /// Returns YES if the original post is a draft | ||
| @objc | ||
| func originalIsDraft() -> Bool { | ||
| if status == .draft { | ||
| return true | ||
| } else if isRevision(), original?.status == .draft { | ||
| return true | ||
| } | ||
|
Check warning on line 357 in Sources/WordPressData/Swift/AbstractPost.swift
|
||
| return false | ||
| } | ||
|
|
||
| @objc | ||
| func shouldPublishImmediately() -> Bool { | ||
|
Contributor
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.
|
||
| // - warning: Yes, this is WordPress logic and it matches the behavior on | ||
| // the web. If `dateCreated` is the same as `dateModified`, the system | ||
| // uses it to represent a "no publish date selected" scenario. | ||
| originalIsDraft() && (date_created_gmt == nil || date_created_gmt == dateModified) | ||
| } | ||
|
|
||
| @objc | ||
| func hasPhoto() -> Bool { | ||
|
||
| if media.isEmpty { | ||
| return false | ||
| } | ||
|
|
||
| if featuredImage != nil { | ||
| return true | ||
| } | ||
|
|
||
| return media.contains { $0.mediaType == .image } | ||
| } | ||
|
|
||
| @objc | ||
| func hasVideo() -> Bool { | ||
| if media.isEmpty { | ||
| return false | ||
| } | ||
|
|
||
| return media.contains { $0.mediaType == .video } | ||
| } | ||
|
|
||
| /// Does the post exist on the blog? | ||
| @objc | ||
| func hasRemote() -> Bool { | ||
| (postID?.int64Value ?? 0) > 0 | ||
| } | ||
|
|
||
| @objc | ||
| var parsedOtherTerms: [String: [String]] { | ||
| get { | ||
| guard let rawOtherTerms else { | ||
| return [:] | ||
| } | ||
|
|
||
| return (try? JSONSerialization.jsonObject(with: rawOtherTerms) as? [String: [String]]) ?? [:] | ||
| } | ||
| set { | ||
| rawOtherTerms = try? JSONSerialization.data(withJSONObject: newValue) | ||
| } | ||
| } | ||
|
|
||
| /// Updates the path for the display image by looking at the post content and trying to find an good image to use. | ||
| /// If no appropiated image is found the path is set to nil. | ||
| @objc | ||
| func updatePathForDisplayImageBasedOnContent() { | ||
| guard let content else { | ||
| return | ||
| } | ||
|
|
||
| if let result = DisplayableImageHelper.searchPostContentForImage(toDisplay: content), !result.isEmpty { | ||
| pathForDisplayImage = result | ||
| return | ||
| } | ||
|
|
||
| guard let allMedia = blog.media, !allMedia.isEmpty else { return } | ||
|
|
||
| let mediaIDs = DisplayableImageHelper.searchPostContentForAttachmentIds(inGalleries: content) as? Set<NSNumber> ?? [] | ||
| for media in allMedia { | ||
| guard let media = media as? Media else { continue } | ||
|
|
||
| guard let mediaID = media.mediaID, | ||
| mediaIDs.contains(mediaID) else { | ||
| continue | ||
| } | ||
|
|
||
| if let remoteURL = media.remoteURL { | ||
| pathForDisplayImage = remoteURL | ||
| break | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,7 +139,7 @@ class EditorMediaUtility { | |
| let requestURL: URL | ||
| if url.isFileURL { | ||
| requestURL = url | ||
| } else if post.isPrivateAtWPCom() && url.isHostedAtWPCom { | ||
| } else if post.blog.isPrivateAtWPCom() && url.isHostedAtWPCom { | ||
|
Contributor
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. Nice, I like the removal of these excessive convenience methods that proxy to blog. |
||
| // private wpcom image needs special handling. | ||
| // the size that WPImageHelper expects is pixel size | ||
| size.width = size.width * scale | ||
|
|
||
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.
This method is used in a single place. Let's remove it and review other similar methods that are one-liners and don't create much value.