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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import Foundation

extension ReaderPost {

func getSiteIconURL(size: Int) -> URL? {
SiteIconViewModel.makeReaderSiteIconURL(iconURL: siteIconURL, siteID: siteID?.intValue, size: CGSize(width: size, height: size))
}

/// Find cached comment with given ID.
///
/// - Parameter id: The comment id
Expand Down
1 change: 0 additions & 1 deletion WordPress/Classes/Models/ReaderPost.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ extern NSString * const ReaderPostStoredCommentTextKey;
- (BOOL)isP2Type;
- (NSString *)authorString;
- (BOOL)contentIncludesFeaturedImage;
- (NSURL *)siteIconForDisplayOfSize:(NSInteger)size;
- (SourceAttributionStyle)sourceAttributionStyle;
- (NSString *)sourceAuthorNameForDisplay;
- (NSURL *)sourceAvatarURLForDisplay;
Expand Down
14 changes: 0 additions & 14 deletions WordPress/Classes/Models/ReaderPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,6 @@ - (NSString *)blogNameForDisplay
return [[NSURL URLWithString:self.blogURL] host];
}

- (NSURL *)siteIconForDisplayOfSize:(NSInteger)size
{
NSString *str;
if ([self.siteIconURL length] > 0) {
if ([self.siteIconURL rangeOfString:@"/blavatar/"].location == NSNotFound) {
str = self.siteIconURL;
} else {
str = [NSString stringWithFormat:@"%@?s=%d&d=404", self.siteIconURL, size];
}
return [NSURL URLWithString:str];
}
return nil;
}

- (NSString *)titleForDisplay
{
NSString *title = [[self.postTitle trim] stringByDecodingXMLCharacters];
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Models/ReaderSiteTopic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Foundation
@NSManaged open var isVisible: Bool
@NSManaged open var organizationID: Int
@NSManaged open var postCount: NSNumber
/// - warning: Not guaranteed to be a blavatar icon
@NSManaged open var siteBlavatar: String
@NSManaged open var siteDescription: String
@NSManaged open var siteID: NSNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ struct SiteIconViewModel {
init(readerSiteTopic: ReaderSiteTopic, size: Size = .regular) {
self.size = size
self.firstLetter = readerSiteTopic.title.first
self.imageURL = SiteIconViewModel.optimizedBlavatarURL(from: readerSiteTopic.siteBlavatar, imageSize: size.size)
self.imageURL = SiteIconViewModel.makeReaderSiteIconURL(iconURL: readerSiteTopic.siteBlavatar, siteID: readerSiteTopic.siteID.intValue, size: size.size)
}
}

// MARK: - SiteIconViewModel (Optimized URL)

extension SiteIconViewModel {
/// Returns the Size Optimized URL for a given Path.
static func optimizedURL(for path: String, imageSize: CGSize = SiteIconViewModel.Size.regular.size, isP2: Bool = false) -> URL? {
Expand Down Expand Up @@ -106,3 +108,30 @@ extension SiteIconViewModel {
return components.url
}
}

// MARK: - SiteIconViewModel (Reader)

extension SiteIconViewModel {
/// - parameter isBlavatar: A hint to skip the "is icon blavatar" check.
static func makeReaderSiteIconURL(iconURL: String?, isBlavatar: Bool = false, siteID: Int?, size: CGSize) -> URL? {
guard let iconURL, !iconURL.isEmpty else {
if let siteID {
return getHardcodedSiteIconURL(siteID: siteID)
}
return nil
}
if isBlavatarURL(iconURL) {
return optimizedBlavatarURL(from: iconURL, imageSize: size)
}
return URL(string: iconURL)
}

private static func getHardcodedSiteIconURL(siteID: Int) -> URL? {
switch siteID {
case 3584907:
return Bundle.main.url(forResource: "wpcom-blog-icon", withExtension: "png")
default:
return nil
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class ReaderPostCellViewModel {

if isP2 {
self.avatarURL = post.authorAvatarURL.flatMap(URL.init)
} else if let avatarURL = post.siteIconForDisplay(ofSize: Int(ReaderPostCell.avatarSize)) {
} else if let avatarURL = post.getSiteIconURL(size: Int(ReaderPostCell.avatarSize)) {
self.avatarURL = avatarURL
} else if let blogURL = post.blogURL.flatMap(URL.init), post.isExternal {
if let faviconURL = FaviconService.shared.cachedFavicon(forURL: blogURL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ReaderDetailHeaderViewModel: ObservableObject {

self.isFollowingSite = post.isFollowing

self.siteIconURL = post.siteIconForDisplay(ofSize: Int(ReaderDetailNewHeaderView.Constants.siteIconLength))
self.siteIconURL = post.getSiteIconURL(size: Int(ReaderDetailNewHeaderView.Constants.siteIconLength))
self.authorAvatarURL = post.avatarURLForDisplay() ?? nil

if let authorName = post.authorForDisplay(), !authorName.isEmpty {
Expand Down
Binary file added WordPress/Images/wpcom-blog-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 18 additions & 4 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
0C6C4CD42A4F0AD90049E762 /* blaze-search-page-1.json in Resources */ = {isa = PBXBuildFile; fileRef = 0C6C4CD32A4F0AD80049E762 /* blaze-search-page-1.json */; };
0C6C4CD62A4F0AEE0049E762 /* blaze-search-page-2.json in Resources */ = {isa = PBXBuildFile; fileRef = 0C6C4CD52A4F0AEE0049E762 /* blaze-search-page-2.json */; };
0C6C4CD82A4F0F2C0049E762 /* Bundle+TestExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C6C4CD72A4F0F2C0049E762 /* Bundle+TestExtensions.swift */; };
0C77A5B02CDE5675005BC0DA /* wpcom-blog-icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 0C77A5AF2CDE5675005BC0DA /* wpcom-blog-icon.png */; };
0C77A5B12CDE5675005BC0DA /* wpcom-blog-icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 0C77A5AF2CDE5675005BC0DA /* wpcom-blog-icon.png */; };
0C77A5B32CDE7924005BC0DA /* ReaderPostTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C77A5B22CDE7924005BC0DA /* ReaderPostTests.swift */; };
0C7D481A2A4DB9300023CF84 /* blaze-search-response.json in Resources */ = {isa = PBXBuildFile; fileRef = 0C7D48192A4DB9300023CF84 /* blaze-search-response.json */; };
0C896DE72A3A832B00D7D4E7 /* SiteVisibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C896DE62A3A832B00D7D4E7 /* SiteVisibilityTests.swift */; };
0C8FC9AA2A8C57000059DCE4 /* ItemProviderMediaExporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C8FC9A92A8C57000059DCE4 /* ItemProviderMediaExporterTests.swift */; };
Expand Down Expand Up @@ -1240,7 +1243,6 @@
E61507E42220A13B00213D33 /* richEmbedScript.js in Resources */ = {isa = PBXBuildFile; fileRef = E61507E32220A13B00213D33 /* richEmbedScript.js */; };
E66969C81B9E0A6800EC9C00 /* ReaderTopicServiceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E66969C71B9E0A6800EC9C00 /* ReaderTopicServiceTest.swift */; };
E6A215901D1065F200DE5270 /* AbstractPostTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6A2158F1D1065F200DE5270 /* AbstractPostTest.swift */; };
E6B9B8AA1B94E1FE0001B92F /* ReaderPostTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E6B9B8A91B94E1FE0001B92F /* ReaderPostTest.m */; };
E6B9B8AF1B94FA1C0001B92F /* ReaderStreamViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6B9B8AE1B94FA1C0001B92F /* ReaderStreamViewControllerTests.swift */; };
E8DEE110E4BC3FA1974AB1BB /* Pods_WordPressTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B921F5DD9A1F257C792EC225 /* Pods_WordPressTest.framework */; };
EA14532A29AD874C001F3143 /* ReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB10E3F27487F5D000DA4C1 /* ReaderTests.swift */; };
Expand Down Expand Up @@ -2029,6 +2031,8 @@
0C6C4CD32A4F0AD80049E762 /* blaze-search-page-1.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "blaze-search-page-1.json"; sourceTree = "<group>"; };
0C6C4CD52A4F0AEE0049E762 /* blaze-search-page-2.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "blaze-search-page-2.json"; sourceTree = "<group>"; };
0C6C4CD72A4F0F2C0049E762 /* Bundle+TestExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+TestExtensions.swift"; sourceTree = "<group>"; };
0C77A5AF2CDE5675005BC0DA /* wpcom-blog-icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "wpcom-blog-icon.png"; sourceTree = "<group>"; };
0C77A5B22CDE7924005BC0DA /* ReaderPostTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderPostTests.swift; sourceTree = "<group>"; };
0C7D48192A4DB9300023CF84 /* blaze-search-response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "blaze-search-response.json"; sourceTree = "<group>"; };
0C896DE62A3A832B00D7D4E7 /* SiteVisibilityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteVisibilityTests.swift; sourceTree = "<group>"; };
0C8FC9A92A8C57000059DCE4 /* ItemProviderMediaExporterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemProviderMediaExporterTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3109,7 +3113,6 @@
E61507E32220A13B00213D33 /* richEmbedScript.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = richEmbedScript.js; path = Resources/HTML/richEmbedScript.js; sourceTree = "<group>"; };
E66969C71B9E0A6800EC9C00 /* ReaderTopicServiceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReaderTopicServiceTest.swift; sourceTree = "<group>"; };
E6A2158F1D1065F200DE5270 /* AbstractPostTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AbstractPostTest.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
E6B9B8A91B94E1FE0001B92F /* ReaderPostTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReaderPostTest.m; sourceTree = "<group>"; };
E6B9B8AE1B94FA1C0001B92F /* ReaderStreamViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReaderStreamViewControllerTests.swift; sourceTree = "<group>"; };
EA14534229AD874C001F3143 /* JetpackUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JetpackUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
EA14534629AEF479001F3143 /* JetpackUITests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = JetpackUITests.xctestplan; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4116,6 +4119,14 @@
path = Mocks;
sourceTree = "<group>";
};
0C77A5AE2CDE5668005BC0DA /* Images */ = {
isa = PBXGroup;
children = (
0C77A5AF2CDE5675005BC0DA /* wpcom-blog-icon.png */,
);
path = Images;
sourceTree = "<group>";
};
0C7D48182A4DB91B0023CF84 /* Blaze */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4464,6 +4475,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
0C77A5AE2CDE5668005BC0DA /* Images */,
801D94F4291AB36A0051993E /* Lottie Animations */,
433840C622C2BA5B00CB13F8 /* AppImages.xcassets */,
F5A34D0525DF2F7700C9654B /* Fonts */,
Expand Down Expand Up @@ -5539,7 +5551,7 @@
5960967E1CF7959300848496 /* PostTests.swift */,
FEFA6AC72A88D5FC004EE5E6 /* Post+JetpackSocialTests.swift */,
8BBBEBB124B8F8C0005E358E /* ReaderCardTests.swift */,
E6B9B8A91B94E1FE0001B92F /* ReaderPostTest.m */,
0C77A5B22CDE7924005BC0DA /* ReaderPostTests.swift */,
24C69A8A2612421900312D9A /* UserSettingsTests.swift */,
24C69AC12612467C00312D9A /* UserSettingsTestsObjc.m */,
3F759FB92A2DA93B0039A845 /* WPAccount+Fixture.swift */,
Expand Down Expand Up @@ -8496,6 +8508,7 @@
172F06BD2865C04F00C78FD4 /* spectrum-'22-icon-app-60x60@2x.png in Resources */,
FF37F90922385CA000AFA3DB /* RELEASE-NOTES.txt in Resources */,
C7E5F2552799BD54009BC263 /* cool-blue-icon-app-83.5x83.5@2x.png in Resources */,
0C77A5B02CDE5675005BC0DA /* wpcom-blog-icon.png in Resources */,
17222D92261DDDF90047B163 /* blue-classic-icon-app-83.5x83.5@2x.png in Resources */,
17222D90261DDDF90047B163 /* blue-classic-icon-app-60x60@2x.png in Resources */,
17222D86261DDDF90047B163 /* celadon-icon-app-76x76.png in Resources */,
Expand Down Expand Up @@ -8914,6 +8927,7 @@
F41E4EA228F20AB8001880C6 /* white-on-celadon-icon-app-76.png in Resources */,
F465980A28E66A5B00D5F49A /* white-on-blue-icon-app-60@3x.png in Resources */,
F465977128E4669200D5F49A /* cool-green-icon-app-60@2x.png in Resources */,
0C77A5B12CDE5675005BC0DA /* wpcom-blog-icon.png in Resources */,
F41E4EAD28F20DF9001880C6 /* stroke-light-icon-app-83.5@2x.png in Resources */,
F46597B228E6605E00D5F49A /* neu-green-icon-app-83.5@2x.png in Resources */,
F465980028E66A1100D5F49A /* white-on-black-icon-app-83.5@2x.png in Resources */,
Expand Down Expand Up @@ -9987,6 +10001,7 @@
73C8F06621BEF76B00DDDF7E /* SiteAssemblyViewTests.swift in Sources */,
73178C2821BEE09300E37C9A /* SiteCreationDataCoordinatorTests.swift in Sources */,
4A266B8F282B05210089CF3D /* JSONObjectTests.swift in Sources */,
0C77A5B32CDE7924005BC0DA /* ReaderPostTests.swift in Sources */,
D81C2F6020F891C4002AE1F1 /* TrashCommentActionTests.swift in Sources */,
FA4ADADA1C509FE400F858D7 /* SiteManagementServiceTests.swift in Sources */,
3F1B66A323A2F54B0075F09E /* ReaderReblogActionTests.swift in Sources */,
Expand Down Expand Up @@ -10270,7 +10285,6 @@
F5D0A65223CCD3B600B20D27 /* PreviewWebKitViewControllerTests.swift in Sources */,
B5ECA6CD1DBAAD510062D7E0 /* CoreDataHelperTests.swift in Sources */,
931D270019EDAE8600114F17 /* CoreDataMigrationTests.m in Sources */,
E6B9B8AA1B94E1FE0001B92F /* ReaderPostTest.m in Sources */,
80EF9284280CFEB60064A971 /* DashboardPostsSyncManagerTests.swift in Sources */,
7EC9FE0B22C627DB00C5A888 /* PostEditorAnalyticsSessionTests.swift in Sources */,
4AEF2DD929A84B2C00345734 /* ReaderSiteServiceTests.swift in Sources */,
Expand Down
60 changes: 0 additions & 60 deletions WordPress/WordPressTest/ReaderPostTest.m

This file was deleted.

22 changes: 22 additions & 0 deletions WordPress/WordPressTest/ReaderPostTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import UIKit
import XCTest

@testable import WordPress

final class ReaderPostTests: CoreDataTestCase {
func testSiteIconURL() throws {
let post = NSEntityDescription.insertNewObject(forEntityName: "ReaderPost", into: mainContext) as! ReaderPost
XCTAssertNil(post.getSiteIconURL(size: 50))

post.siteIconURL = "http://example.com/icon.png"
XCTAssertEqual(post.getSiteIconURL(size: 50), URL(string: "http://example.com/icon.png"))

post.siteIconURL = "https://gravatar.com/blavatar/icon.png"
let scaledURL = try XCTUnwrap(post.getSiteIconURL(size: 50))
let components = try XCTUnwrap(URLComponents(url: scaledURL, resolvingAgainstBaseURL: false))
let queryItems = components.queryItems ?? []
XCTAssertEqual(queryItems.count, 2)
XCTAssertEqual(queryItems.first(where: { $0.name == "s" })?.value, Int(50 * UITraitCollection.current.displayScale).description)
XCTAssertEqual(queryItems.first(where: { $0.name == "d" })?.value, "404")
}
}