Skip to content
Draft
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
73 changes: 38 additions & 35 deletions Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let package = Package(
.library(name: "WordPressCore", targets: ["WordPressCore"]),
.library(name: "WordPressCoreProtocols", targets: ["WordPressCoreProtocols"]),
.library(name: "WordPressKit", targets: ["WordPressKit"]),
.library(name: "WordPressData", targets: ["WordPressData"]),
.library(name: "WordPressMediaLibrary", targets: ["WordPressMediaLibrary"])
],
dependencies: [
Expand Down Expand Up @@ -280,6 +281,29 @@ let package = Package(
],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.target(
name: "WordPressData",
dependencies: [
"BuildSettingsKit",
"FormattableContentKit",
"SFHFKeychainUtils",
"WordPressShared",
"WordPressKit",
"WordPressUI",
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
.product(name: "Gravatar", package: "Gravatar-SDK-iOS"),
.product(name: "NSURL-IDN", package: "NSURL-IDN"),
.product(name: "WordPressAPI", package: "wordpress-rs")
],
resources: [.process("Resources")],
swiftSettings: [
.swiftLanguageMode(.v5),
// The Xcode target this module replaced compiled bare slash regex
// literals (e.g. ReaderPost.swift); plain Swift 5 mode does not.
.enableUpcomingFeature("BareSlashRegexLiterals")
]
),
.target(
name: "WordPressReader",
dependencies: [
Expand Down Expand Up @@ -320,6 +344,16 @@ let package = Package(
dependencies: [.target(name: "WordPressShared")],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.testTarget(
name: "WordPressDataTests",
dependencies: [
"WordPressData",
"WordPressKit",
"WordPressKitModels",
"WordPressShared"
],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.testTarget(
name: "WordPressSharedObjCTests",
dependencies: [.target(name: "WordPressShared"), .target(name: "WordPressTesting")],
Expand Down Expand Up @@ -364,8 +398,6 @@ enum XcodeSupport {
.library(name: "XcodeTarget_Keystone", targets: ["XcodeTarget_Keystone"]),
.library(name: "XcodeTarget_WordPressTests", targets: ["XcodeTarget_WordPressTests"]),
.library(name: "XcodeTarget_WordPressKitTests", targets: ["XcodeTarget_WordPressKitTests"]),
.library(name: "XcodeTarget_WordPressData", targets: ["XcodeTarget_WordPressData"]),
.library(name: "XcodeTarget_WordPressDataTests", targets: ["XcodeTarget_WordPressDataTests"]),
.library(name: "XcodeTarget_WordPressAuthentificator", targets: ["XcodeTarget_WordPressAuthentificator"]),
.library(
name: "XcodeTarget_WordPressAuthentificatorTests",
Expand Down Expand Up @@ -452,6 +484,7 @@ enum XcodeSupport {
"WordPressUI",
"WordPressCore",
"WordPressKit",
"WordPressData",
.product(name: "Alamofire", package: "Alamofire"),
.product(name: "AutomatticAbout", package: "AutomatticAbout-swift"),
.product(name: "AutomatticTracks", package: "Automattic-Tracks-iOS"),
Expand Down Expand Up @@ -491,21 +524,12 @@ enum XcodeSupport {
.xcodeTarget(
"XcodeTarget_WordPressTests",
dependencies: testDependencies + [
"FormattableContentKit",
"WordPressData",
"WordPressKit",
"WordPressShared",
"WordPressUI",
.product(name: "Gravatar", package: "Gravatar-SDK-iOS"),
// Needed by WordPressData because of how linkage works...
//
"BuildSettingsKit",
"FormattableContentKit",
"SFHFKeychainUtils",
"WordPressKit",
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
.product(name: "CocoaLumberjackSwiftLogBackend", package: "CocoaLumberjack"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NSObject-SafeExpectations", package: "NSObject-SafeExpectations"),
.product(name: "NSURL-IDN", package: "NSURL-IDN"),
.product(name: "WordPressAPI", package: "wordpress-rs")
]
),
Expand All @@ -516,12 +540,6 @@ enum XcodeSupport {
"WordPressKit"
]
),
.xcodeTarget(
"XcodeTarget_WordPressDataTests",
dependencies: [
"WordPressKit"
]
),
.xcodeTarget("XcodeTarget_WordPressAuthentificator", dependencies: wordPresAuthentificatorDependencies),
.xcodeTarget(
"XcodeTarget_WordPressAuthentificatorTests",
Expand Down Expand Up @@ -599,21 +617,6 @@ enum XcodeSupport {
dependencies: [
"UITestsFoundation"
]
),
.xcodeTarget(
"XcodeTarget_WordPressData",
dependencies: [
"BuildSettingsKit",
"FormattableContentKit",
"SFHFKeychainUtils",
"WordPressShared",
"WordPressKit",
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
.product(name: "Gravatar", package: "Gravatar-SDK-iOS"),
.product(name: "NSURL-IDN", package: "NSURL-IDN"),
.product(name: "WordPressAPI", package: "wordpress-rs")
]
)
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Foundation

extension Bundle {
@objc public class var wordPressData: Bundle {
Bundle(for: BundleToken.self)
.module
}
}

private final class BundleToken {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"configurations" : [
{
"id" : "4A78A2D0-FB06-481E-B333-C1BA9A78D4FE",
"name" : "Configuration 1",
"id" : "1CD15192-2579-4CD8-815F-86BF8B214099",
"name" : "Test Scheme Action",
"options" : {

}
Expand All @@ -14,8 +14,8 @@
"testTargets" : [
{
"target" : {
"containerPath" : "container:WordPress.xcodeproj",
"identifier" : "3F7AE0BB2D9B30A200AB4892",
"containerPath" : "container:../Modules",
"identifier" : "WordPressDataTests",
"name" : "WordPressDataTests"
}
}
Expand Down
11 changes: 9 additions & 2 deletions WordPress/Classes/Models/ReaderListTopic+Creation.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import Foundation
import WordPressData
import WordPressKit
import WordPressShared

extension ReaderListTopic {

/// Returns an existing topic for the specified list, or creates one if one
/// doesn't already exist.
///
static func named(_ listName: String, forUser user: String, in context: NSManagedObjectContext) -> ReaderListTopic? {
let remote = ReaderTopicServiceRemote(wordPressComRestApi: WordPressComRestApi.anonymousApi(userAgent: WPUserAgent.wordPress()))
static func named(
_ listName: String,
forUser user: String,
in context: NSManagedObjectContext
) -> ReaderListTopic? {
let remote = ReaderTopicServiceRemote(
wordPressComRestApi: WordPressComRestApi.anonymousApi(userAgent: WPUserAgent.wordPress())
)
let sanitizedListName = remote.slug(forTopicName: listName) ?? listName.lowercased()
let sanitizedUser = user.lowercased()
let path = remote.path(forEndpoint: "read/list/\(sanitizedUser)/\(sanitizedListName)/posts", withVersion: ._1_2)
Expand Down
47 changes: 28 additions & 19 deletions WordPress/Classes/Services/CommentService+Swift.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import WordPressData
import WordPressKit

/// Encapsulates actions related to fetching reply comments.
///
Expand All @@ -13,11 +14,13 @@ extension CommentService {
/// - accountService: Service dependency to fetch the current user's dotcom ID.
/// - success: Closure called when the fetch succeeds.
/// - failure: Closure called when the fetch fails.
func getLatestReplyID(for parentID: Int,
siteID: Int,
accountService: AccountService? = nil,
success: @escaping (Int) -> Void,
failure: @escaping (Error?) -> Void) {
func getLatestReplyID(
for parentID: Int,
siteID: Int,
accountService: AccountService? = nil,
success: @escaping (Int) -> Void,
failure: @escaping (Error?) -> Void
) {
guard let remote = restRemote(forSite: NSNumber(value: siteID)) else {
DDLogError("Unable to create a REST remote to fetch comment replies.")
failure(nil)
Expand All @@ -34,9 +37,12 @@ extension CommentService {
// Therefore, fetch all replies and filter for the current user here.
remote.getCommentsV2(for: siteID, parameters: [.parent: parentID]) { remoteComments in
// Filter for comments authored by the current user, and return the most recent commentID (if any).
success(remoteComments
.filter { $0.authorID == userID }
.max { $0.date < $1.date }?.commentID ?? 0)
success(
remoteComments
.filter { $0.authorID == userID }
.max { $0.date < $1.date }?
.commentID ?? 0
)
} failure: { error in
failure(error)
}
Expand All @@ -50,11 +56,12 @@ extension CommentService {
/// - completion: The block executed after the replies are updated.
func updateRepliesVisibility(for ancestorComment: Comment, completion: (() -> Void)? = nil) {
guard let context = ancestorComment.managedObjectContext,
let post = ancestorComment.post as? ReaderPost,
let comments = post.comments else {
completion?()
return
}
let post = ancestorComment.post as? ReaderPost,
let comments = post.comments
else {
completion?()
return
}

let isVisible = (ancestorComment.status == CommentStatusType.approved.description)

Expand All @@ -66,11 +73,12 @@ extension CommentService {
context.perform {
comments.filter { comment in
comment.parentID == ancestorComment.commentID
|| comment.hierarchy
.split(separator: ".")
.compactMap({ Int32($0) })
.contains(ancestorComment.commentID)
}.forEach { childComment in
|| comment.hierarchy
.split(separator: ".")
.compactMap({ Int32($0) })
.contains(ancestorComment.commentID)
}
.forEach { childComment in
childComment.visibleOnReader = isVisible
}

Expand All @@ -84,7 +92,8 @@ extension CommentService {
@objc(fetchPostsIfNeededForComments:inBlog:)
public func fetchPostsIfNeeded(for comments: [RemoteComment], in blog: Blog) {
// Find posts that do not exists locally.
let postIds = comments
let postIds =
comments
.reduce(into: Set<NSNumber>()) { result, comment in
if let postId = comment.postID, comment.postTitle == nil {
result.insert(postId)
Expand Down
18 changes: 11 additions & 7 deletions WordPress/Classes/Services/PushAuthenticationService.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import WordPressData
import WordPressKit
import WordPressShared

/// The purpose of this service is to encapsulate the Restful API that performs Mobile 2FA
Expand Down Expand Up @@ -30,13 +31,16 @@ class PushAuthenticationService {
return
}

self.authenticationServiceRemote!.authorizeLogin(token,
success: {
completion(true)
},
failure: {
completion(false)
})
self.authenticationServiceRemote!
.authorizeLogin(
token,
success: {
completion(true)
},
failure: {
completion(false)
}
)
}

/// Helper method to get the WordPress.com REST Api, if any
Expand Down
Loading