Skip to content
Open
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
22 changes: 0 additions & 22 deletions Sources/WordPressData/Objective-C/AbstractPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -256,33 +256,11 @@ - (BOOL)shouldPublishImmediately
return [self originalIsDraft] && [self dateCreatedIsNilOrEqualToDateModified];
}

- (NSString *)authorNameForDisplay
{
return [self.author makePlainText];
}

- (NSURL *)blogURL
{
return [NSURL URLWithString:self.blog.url];
}

- (NSString *)contentPreviewForDisplay
{
return self.mt_excerpt;
}

- (NSString *)dateStringForDisplay
{
if ([self originalIsDraft] || [self.status isEqualToString:PostStatusPending]) {
return [[self dateModified] mediumString];
} else if ([self isScheduled]) {
return [[self dateCreated] mediumStringWithTime];
} else if ([self shouldPublishImmediately]) {
return NSLocalizedString(@"Publish Immediately",@"A short phrase indicating a post is due to be immedately published.");
}
return [[self dateCreated] mediumString];
}

- (BOOL)isPrivateAtWPCom
{
return self.blog.isPrivateAtWPCom;
Expand Down
11 changes: 1 addition & 10 deletions Sources/WordPressData/Objective-C/BasePost.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "BasePost.h"
#import "Media.h"
#import "WordPressData-Swift.h"

@import WordPressShared;

Expand All @@ -20,16 +21,6 @@ @implementation BasePost
@dynamic suggested_slug;
@dynamic pathForDisplayImage;

- (NSDate *)dateCreated
{
return self.date_created_gmt;
}

- (void)setDateCreated:(NSDate *)localDate
{
self.date_created_gmt = localDate;
}

- (BOOL)hasContent
{
BOOL titleIsEmpty = self.postTitle ? self.postTitle.isEmpty : YES;
Expand Down
49 changes: 0 additions & 49 deletions Sources/WordPressData/Objective-C/ReaderPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,6 @@ + (NSString *)attributionTypeFromTaxonomies:(NSArray *)taxonomies
return nil;
}

- (BOOL)isCrossPost
{
return self.crossPostMeta != nil;
}

- (BOOL)isP2Type
{
NSInteger orgID = [self.organizationID intValue];
return orgID == SiteOrganizationTypeP2 || orgID == SiteOrganizationTypeAutomattic;
}

- (NSString *)authorString
{
if ([self.authorDisplayName length] > 0) {
return self.authorDisplayName;
}

return self.author;
}

- (BOOL)contentIncludesFeaturedImage
{
NSURL *featuredImageURL = [self featuredImageURL];
Expand All @@ -279,35 +259,6 @@ - (BOOL)contentIncludesFeaturedImage
return ([content rangeOfString:featuredImage].location != NSNotFound);
}

- (SourceAttributionStyle)sourceAttributionStyle
{
if ([self.sourceAttribution.attributionType isEqualToString:SourcePostAttribution.post]) {
return SourceAttributionStylePost;
} else if ([self.sourceAttribution.attributionType isEqualToString:SourcePostAttribution.site]) {
return SourceAttributionStyleSite;
} else {
return SourceAttributionStyleNone;
}
}

- (NSString *)sourceAuthorNameForDisplay
{
return self.sourceAttribution.authorName;
}

- (NSURL *)sourceAvatarURLForDisplay
{
if (!self.sourceAttribution) {
return nil;
}
return [NSURL URLWithString:self.sourceAttribution.avatarURL];
}

- (NSString *)sourceBlogNameForDisplay
{
return self.sourceAttribution.blogName;
}

- (NSDictionary *)railcarDictionary
{
if (!self.railcar) {
Expand Down
2 changes: 0 additions & 2 deletions Sources/WordPressData/Objective-C/include/AbstractPost.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ typedef NS_ENUM(NSUInteger, AbstractPostRemoteStatus) {

#pragma mark - Conveniece Methods
- (BOOL)shouldPublishImmediately;
- (NSString *)authorNameForDisplay;
- (NSString *)dateStringForDisplay;
- (BOOL)isPrivateAtWPCom;


Expand Down
3 changes: 0 additions & 3 deletions Sources/WordPressData/Objective-C/include/BasePost.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, strong, nullable) NSString *pathForDisplayImage;

//date conversion
@property (nonatomic, strong, nullable) NSDate * dateCreated;

// Returns true if title or content is non empty
- (BOOL)hasContent;

Expand Down
7 changes: 0 additions & 7 deletions Sources/WordPressData/Objective-C/include/ReaderPost.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,7 @@ extern NSString * const ReaderPostStoredCommentTextKey;

+ (instancetype)createOrReplaceFromRemotePost:(RemoteReaderPost *)remotePost forTopic:(ReaderAbstractTopic *)topic context:(NSManagedObjectContext *) managedObjectContext;

- (BOOL)isCrossPost;
- (BOOL)isP2Type;
- (NSString *)authorString;
- (BOOL)contentIncludesFeaturedImage;
- (SourceAttributionStyle)sourceAttributionStyle;
- (NSString *)sourceAuthorNameForDisplay;
- (NSURL *)sourceAvatarURLForDisplay;
- (NSString *)sourceBlogNameForDisplay;
- (NSDictionary *)railcarDictionary;

@end
Expand Down
15 changes: 15 additions & 0 deletions Sources/WordPressData/Swift/AbstractPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,19 @@ public extension AbstractPost {
revision.deleteRevision()
}
}

func dateStringForDisplay() -> String? {
if self.originalIsDraft() || self.status == .pending {
return dateModified?.toMediumString()
} else if self.isScheduled() {
return self.dateCreated?.mediumStringWithTime()
} else if self.shouldPublishImmediately() {
return NSLocalizedString("Publish Immediately", comment: "A short phrase indicating a post is due to be immedately published.")
}
return self.dateCreated?.toMediumString()
Copy link
Contributor

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 dateCreated can be nil – do we know of any scenario where it should be?

}

override func contentPreviewForDisplay() -> String? {
mt_excerpt
}
}
9 changes: 9 additions & 0 deletions Sources/WordPressData/Swift/BasePost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,13 @@ extension BasePost {

return nil
}

@objc public var dateCreated: Date? {
get {
date_created_gmt
}
set {
date_created_gmt = newValue
}
}
}
41 changes: 40 additions & 1 deletion Sources/WordPressData/Swift/ReaderPost+PostContentProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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? {
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Because this takes no params, I wonder if it should be a var but that's a nit

Copy link
Contributor

Choose a reason for hiding this comment

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

Same note for the other func translations

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
}

}
2 changes: 1 addition & 1 deletion WordPress/Classes/Models/ReaderPost+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension ReaderPost {
if canSubscribeComments {
return true
}
if isP2Type() {
if isP2Type {
return !((topic as? ReaderSiteTopic)?.emailSubscription?.sendComments ?? false)
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class PostSettingsViewModel: NSObject, ObservableObject {
}

var authorDisplayName: String {
settings.author?.displayName ?? post.authorNameForDisplay()
settings.author?.displayName ?? post.author?.makePlainText() ?? ""
Copy link
Contributor

Choose a reason for hiding this comment

The 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? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class PostListItemViewModel {

private func makeAccessibilityLabel(for post: Post, statusViewModel: PostCardStatusViewModel) -> String? {
let titleAndDateChunk: String = {
return String(format: Strings.Accessibility.titleAndDateChunkFormat, post.titleForDisplay(), post.dateStringForDisplay())
return String(format: Strings.Accessibility.titleAndDateChunkFormat, post.titleForDisplay(), post.dateStringForDisplay() ?? "")
}()

let authorChunk: String? = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ extension ReaderStreamViewController: WPTableViewHandlerDelegate {
return cell
}

if post.isCross() {
Copy link
Contributor

Choose a reason for hiding this comment

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

What a weird auto-ObjC translation – I had to check that isCross() and isCrossPost were the same in Xcode 🙃

if post.isCrossPost {
let cell = tableConfiguration.crossPostCell(tableView)
cell.isCompact = isCompact
cell.isSeparatorHidden = !showsSeparator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ class ReaderDetailCoordinator {
let characterSet = CharacterSet(charactersIn: "/")

guard let post,
post.isCross(),
post.isCrossPost,
let crossPostMeta = post.crossPostMeta,
let crossPostURL = URL(string: crossPostMeta.postURL.trimmingCharacters(in: characterSet)),
let selectedURL = URL(string: url.absoluteString.trimmingCharacters(in: characterSet)) else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
webView.postURL = postURL
}

webView.isP2 = post.isP2Type()
webView.isP2 = post.isP2Type

if post.content?.hasSuffix("[…]") == true {
let viewMoreView = ReaderReadMoreView(post: post)
Expand Down Expand Up @@ -871,7 +871,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
post.sourceAttribution.postID != nil &&
post.sourceAttribution.blogID != nil {
return ReaderDetailViewController.controllerWithPostID(post.sourceAttribution.postID!, siteID: post.sourceAttribution.blogID!)
} else if post.isCross() {
} else if post.isCrossPost {
return ReaderDetailViewController.controllerWithPostID(post.crossPostMeta.postID, siteID: post.crossPostMeta.siteID)
} else {
let controller = ReaderDetailViewController.loadFromStoryboard()
Expand Down