-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Move some functions in post models to Swift #25003
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
de00875
142eb43
fe1113f
bbfb46f
06f5f35
f200c12
d05efcb
7e66c7c
0c20429
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 |
|---|---|---|
|
|
@@ -2,6 +2,14 @@ import Foundation | |
| import WordPressShared | ||
|
|
||
| extension ReaderPost { | ||
| public var isCrossPost: Bool { | ||
| crossPostMeta != nil | ||
| } | ||
|
|
||
| public var isP2Type: Bool { | ||
| guard let id = organizationID?.intValue, let type = SiteOrganizationType(rawValue: id) else { return false } | ||
| return type == .p2 || type == .automattic | ||
| } | ||
|
|
||
| @objc public override var featuredImageURL: URL? { | ||
| if !self.featuredImage.isEmpty { | ||
|
|
@@ -38,7 +46,11 @@ extension ReaderPost { | |
| } | ||
|
|
||
| public func authorForDisplay() -> String? { | ||
| return authorString() | ||
| if let name = self.authorDisplayName, !name.isEmpty { | ||
| return name | ||
| } | ||
|
|
||
| return author | ||
| } | ||
|
|
||
| public func dateForDisplay() -> Date? { | ||
|
|
@@ -56,4 +68,31 @@ extension ReaderPost { | |
| public func avatarURLForDisplay() -> URL? { | ||
| authorAvatarURL.flatMap(URL.init(string:)) | ||
| } | ||
|
|
||
| public func sourceAuthorNameForDisplay() -> String? { | ||
| sourceAttribution?.authorName | ||
| } | ||
|
|
||
| public func sourceAttributionStyle() -> SourceAttributionStyle { | ||
|
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. Because this takes no params, I wonder if it should be a
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. Same note for the other |
||
| guard let sourceAttribution else { | ||
| return .none | ||
| } | ||
|
|
||
| if sourceAttribution.attributionType == SourcePostAttribution.post { | ||
| return .post | ||
| } else if sourceAttribution.attributionType == SourcePostAttribution.site { | ||
| return .site | ||
| } | ||
|
|
||
| return .none | ||
| } | ||
|
|
||
| public func sourceAvatarURLForDisplay() -> URL? { | ||
| sourceAttribution?.avatarURL.flatMap(URL.init(string:)) | ||
| } | ||
|
|
||
| public func sourceBlogNameForDisplay() -> String? { | ||
| return sourceAttribution?.blogName | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,7 @@ final class PostSettingsViewModel: NSObject, ObservableObject { | |
| } | ||
|
|
||
| var authorDisplayName: String { | ||
| settings.author?.displayName ?? post.authorNameForDisplay() | ||
| settings.author?.displayName ?? post.author?.makePlainText() ?? "" | ||
|
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. Same issue here – any reason the author should be nullable? |
||
| } | ||
|
|
||
| var authorAvatarURL: URL? { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1329,7 +1329,7 @@ extension ReaderStreamViewController: WPTableViewHandlerDelegate { | |
| return cell | ||
| } | ||
|
|
||
| if post.isCross() { | ||
|
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. What a weird auto-ObjC translation – I had to check that |
||
| if post.isCrossPost { | ||
| let cell = tableConfiguration.crossPostCell(tableView) | ||
| cell.isCompact = isCompact | ||
| cell.isSeparatorHidden = !showsSeparator | ||
|
|
||
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.
It's super rough that
dateCreatedcan benil– do we know of any scenario where it should be?