Skip to content
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/ReaderPost+Searchable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension ReaderPost: SearchableItemConvertable {

var searchDescription: String? {
guard let readerPostPreview = contentPreviewForDisplay(), !readerPostPreview.isEmpty else {
return siteURLForDisplay() ?? contentForDisplay()
return blogURL ?? contentForDisplay()
}
return readerPostPreview
}
Expand Down
15 changes: 12 additions & 3 deletions WordPress/Classes/Models/ReaderPost.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "BasePost.h"
#import "ReaderPostContentProvider.h"

typedef NS_ENUM(NSUInteger, SourceAttributionStyle) {
SourceAttributionStyleNone,
SourceAttributionStylePost,
SourceAttributionStyleSite,
};

@class ReaderAbstractTopic;
@class ReaderCrossPostMeta;
Expand All @@ -13,7 +18,7 @@
extern NSString * const ReaderPostStoredCommentIDKey;
extern NSString * const ReaderPostStoredCommentTextKey;

@interface ReaderPost : BasePost <ReaderPostContentProvider>
@interface ReaderPost : BasePost

@property (nonatomic, strong) NSString *authorDisplayName;
@property (nonatomic, strong) NSString *authorEmail;
Expand Down Expand Up @@ -78,10 +83,14 @@ extern NSString * const ReaderPostStoredCommentTextKey;
+ (instancetype)createOrReplaceFromRemotePost:(RemoteReaderPost *)remotePost forTopic:(ReaderAbstractTopic *)topic context:(NSManagedObjectContext *) managedObjectContext;

- (BOOL)isCrossPost;
- (BOOL)isPrivate;
- (BOOL)isP2Type;
- (NSString *)authorString;
- (BOOL)contentIncludesFeaturedImage;
- (NSURL *)siteIconForDisplayOfSize:(NSInteger)size;
- (SourceAttributionStyle)sourceAttributionStyle;
- (NSString *)sourceAuthorNameForDisplay;
- (NSURL *)sourceAvatarURLForDisplay;
- (NSString *)sourceBlogNameForDisplay;
- (BOOL)isSourceAttributionWPCom;
- (NSDictionary *)railcarDictionary;

Expand Down
48 changes: 1 addition & 47 deletions WordPress/Classes/Models/ReaderPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,6 @@ - (BOOL)isCrossPost
return self.crossPostMeta != nil;
}

- (BOOL)isAtomic
{
return self.isBlogAtomic;
}

- (BOOL)isPrivate
Copy link
Contributor Author

Choose a reason for hiding this comment

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

isBlogPrivate is much clearer.

{
return self.isBlogPrivate;
}

- (BOOL)isP2Type
{
NSInteger orgID = [self.organizationID intValue];
Expand Down Expand Up @@ -393,14 +383,6 @@ - (NSString *)sourceAuthorNameForDisplay
return self.sourceAttribution.authorName;
}

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

- (NSURL *)sourceAvatarURLForDisplay
{
if (!self.sourceAttribution) {
Expand All @@ -414,14 +396,6 @@ - (NSString *)sourceBlogNameForDisplay
return self.sourceAttribution.blogName;
}

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

- (BOOL)isSourceAttributionWPCom
{
return (self.sourceAttribution.blogID) ? YES : NO;
Expand All @@ -432,26 +406,6 @@ - (NSURL *)avatarURLForDisplay
return [NSURL URLWithString:self.authorAvatarURL];
}

- (NSString *)siteURLForDisplay
{
return self.blogURL;
}

- (NSString *)siteHostNameForDisplay
{
return self.blogURL.hostname;
}

- (NSString *)crossPostOriginSiteURLForDisplay
{
return self.crossPostMeta.siteURL;
}

- (BOOL)isCommentCrossPost
{
return self.crossPostMeta.commentURL.length > 0;
}

- (NSDictionary *)railcarDictionary
{
if (!self.railcar) {
Expand All @@ -467,7 +421,7 @@ - (NSDictionary *)railcarDictionary
return nil;
}

- (void) didSave {
- (void)didSave {
[super didSave];

// A ReaderCard can have either a post, or a list of topics, but not both.
Expand Down
42 changes: 0 additions & 42 deletions WordPress/Classes/Models/ReaderPostContentProvider.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import Foundation
/// initialize it from a given `Blog`.
///
extension MediaHost {
enum ReaderPostContentProviderError: Swift.Error {
enum ReaderPostError: Swift.Error {
case baseInitializerError(error: Error)
}

init(with readerPostContentProvider: ReaderPostContentProvider, failure: (ReaderPostContentProviderError) -> ()) {
let isAccessibleThroughWPCom = readerPostContentProvider.isWPCom() || readerPostContentProvider.isJetpack()
init(with post: ReaderPost, failure: (ReaderPostError) -> ()) {
let isAccessibleThroughWPCom = post.isWPCom || post.isJetpack

// This is the only way in which we can obtain the username and authToken here.
// It'd be nice if all data was associated with an account instead, for transparency
Expand All @@ -22,14 +22,13 @@ extension MediaHost {

self.init(
isAccessibleThroughWPCom: isAccessibleThroughWPCom,
isPrivate: readerPostContentProvider.isPrivate(),
isAtomic: readerPostContentProvider.isAtomic(),
siteID: readerPostContentProvider.siteID()?.intValue,
isPrivate: post.isBlogPrivate,
isAtomic: post.isBlogAtomic,
siteID: post.siteID?.intValue,
username: username,
authToken: authToken,
failure: { error in
// We just associate a ReaderPostContentProvider with the underlying error for simpler debugging.
failure(ReaderPostContentProviderError.baseInitializerError(error: error))
failure(ReaderPostError.baseInitializerError(error: error))
}
)
}
Expand Down
6 changes: 3 additions & 3 deletions WordPress/Classes/Services/CommentService.m
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ - (void)replyToPost:(ReaderPost *)post
{
// Create and optimistically save a comment, based on the current wpcom acct
// post and content provided.
BOOL isPrivateSite = post.isPrivate;
BOOL isPrivateSite = post.isBlogPrivate;
[self createHierarchicalCommentWithContent:content withParent:nil postObjectID:post.objectID siteID:post.siteID completion:^(NSManagedObjectID *commentID) {
if (!commentID) {
NSError *error = [NSError errorWithDomain:WKErrorDomain code:WKErrorUnknown userInfo:@{NSDebugDescriptionErrorKey: @"Failed to create a comment for a post"}];
Expand Down Expand Up @@ -737,7 +737,7 @@ - (void)replyToHierarchicalCommentWithID:(NSNumber *)commentID
{
// Create and optimistically save a comment, based on the current wpcom acct
// post and content provided.
BOOL isPrivateSite = post.isPrivate;
BOOL isPrivateSite = post.isBlogPrivate;
[self createHierarchicalCommentWithContent:content withParent:nil postObjectID:post.objectID siteID:post.siteID completion:^(NSManagedObjectID *commentObjectID) {
if (!commentObjectID) {
NSError *error = [NSError errorWithDomain:WKErrorDomain code:WKErrorUnknown userInfo:@{NSDebugDescriptionErrorKey: @"Failed to create a comment for a post"}];
Expand Down Expand Up @@ -1204,7 +1204,7 @@ - (BOOL)mergeHierarchicalComments:(NSArray *)comments forPage:(NSUInteger)page f

comment.depth = ancestors.count;
comment.post = post;
comment.content = [self sanitizeCommentContent:comment.content isPrivateSite:post.isPrivate];
comment.content = [self sanitizeCommentContent:comment.content isPrivateSite:post.isBlogPrivate];
[commentsToKeep addObject:comment];
}

Expand Down
1 change: 0 additions & 1 deletion WordPress/Classes/System/WordPress-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#import "ReaderCommentsViewController.h"
#import "ReaderGapMarker.h"
#import "ReaderPost.h"
#import "ReaderPostContentProvider.h"
#import "ReaderPostService.h"
#import "ReaderSiteService.h"
#import "ReaderSiteService_Internal.h"
Expand Down
5 changes: 1 addition & 4 deletions WordPress/Classes/Utility/Media/ImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ final class ImageView: UIView {
var isErrorViewEnabled = true
var loadingStyle = LoadingStyle.background

/// The background color to use when the image is loaded.
var successBackgroundColor = UIColor.clear
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it in one of the previous PRs and decided to remove it since it's not longer needed. It was replaced by ReaderAvatarView.


override init(frame: CGRect) {
super.init(frame: frame)

Expand Down Expand Up @@ -72,7 +69,7 @@ final class ImageView: UIView {
case .success(let image):
imageView.configure(image: image)
imageView.isHidden = false
backgroundColor = successBackgroundColor
backgroundColor = .clear
case .failure:
if isErrorViewEnabled {
makeErrorView().isHidden = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private extension RichCommentContentRenderer {
// We'll log the error, so we know it's there, but we won't halt execution.
WordPressAppDelegate.crashLogging?.logError(error)
})
} else if let post = comment.post as? ReaderPost, post.isPrivate() {
} else if let post = comment.post as? ReaderPost, post.isBlogPrivate {
return MediaHost(with: post, failure: { error in
// We'll log the error, so we know it's there, but we won't halt execution.
WordPressAppDelegate.crashLogging?.logError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open class ReaderBlockedSiteCell: UITableViewCell {

fileprivate func applyStyles() {
contentView.backgroundColor = .systemGroupedBackground
borderedContentView.layer.borderColor = WPStyleGuide.readerCardCellBorderColor().cgColor
borderedContentView.layer.borderColor = UIColor.separator.cgColor
borderedContentView.layer.borderWidth = .hairlineBorderWidth
label.font = WPStyleGuide.subtitleFont()
label.textColor = .secondaryLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ private enum ReaderCardDiscoverAttribution: Int {
textLabel?.backgroundColor = backgroundColor
}

@objc open func configureView(_ contentProvider: ReaderPostContentProvider?) {
if contentProvider?.sourceAttributionStyle() == SourceAttributionStyle.post {
configurePostAttribution(contentProvider!)
} else if contentProvider?.sourceAttributionStyle() == SourceAttributionStyle.site {
configureSiteAttribution(contentProvider!, verboseAttribution: false)
@objc open func configureView(_ post: ReaderPost?) {
if post?.sourceAttributionStyle() == SourceAttributionStyle.post {
configurePostAttribution(post!)
} else if post?.sourceAttributionStyle() == SourceAttributionStyle.site {
configureSiteAttribution(post!, verboseAttribution: false)
} else {
reset()
}
}

@objc open func configureViewWithVerboseSiteAttribution(_ contentProvider: ReaderPostContentProvider?) {
if let contentProvider = contentProvider {
configureSiteAttribution(contentProvider, verboseAttribution: true)
@objc open func configureViewWithVerboseSiteAttribution(_ post: ReaderPost?) {
if let post {
configureSiteAttribution(post, verboseAttribution: true)
} else {
reset()
}
Expand All @@ -102,26 +102,26 @@ private enum ReaderCardDiscoverAttribution: Int {
attributionAction = .none
}

fileprivate func configurePostAttribution(_ contentProvider: ReaderPostContentProvider) {
let url = contentProvider.sourceAvatarURLForDisplay()
fileprivate func configurePostAttribution(_ post: ReaderPost) {
let url = post.sourceAvatarURLForDisplay()
let placeholder = UIImage(named: gravatarImageName)
imageView.downloadImage(from: url, placeholderImage: placeholder)
imageView.shouldRoundCorners = true

let str = stringForPostAttribution(contentProvider.sourceAuthorNameForDisplay(),
blogName: contentProvider.sourceBlogNameForDisplay())
let str = stringForPostAttribution(post.sourceAuthorNameForDisplay(),
blogName: post.sourceBlogNameForDisplay())
let attributes = originalAttributionParagraphAttributes
textLabel.attributedText = NSAttributedString(string: str, attributes: attributes)
attributionAction = .none
}

fileprivate func configureSiteAttribution(_ contentProvider: ReaderPostContentProvider, verboseAttribution verbose: Bool) {
let url = contentProvider.sourceAvatarURLForDisplay()
fileprivate func configureSiteAttribution(_ post: ReaderPost, verboseAttribution verbose: Bool) {
let url = post.sourceAvatarURLForDisplay()
let placeholder = UIImage(named: blavatarImageName)
imageView.downloadImage(from: url, placeholderImage: placeholder)
imageView.shouldRoundCorners = false

let blogName = contentProvider.sourceBlogNameForDisplay()
let blogName = post.sourceBlogNameForDisplay()
let pattern = patternForSiteAttribution(verbose)
let str = String(format: pattern, blogName!)

Expand Down
Loading