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
9 changes: 0 additions & 9 deletions Sources/WordPressData/Swift/AbstractPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,6 @@ public extension AbstractPost {
return media.first(where: { !$0.willAttemptToUploadLater() }) != nil
}

/// Returns the changes made in the current revision compared to the
/// previous revision or the original post if there is only one revision.
var changes: RemotePostUpdateParameters {
guard let original else {
return RemotePostUpdateParameters() // Empty
}
return RemotePostUpdateParameters.changes(from: original, to: self)
}

/// Returns all revisions of the post including the original one.
var allRevisions: [AbstractPost] {
var revisions: [AbstractPost] = [self]
Expand Down
2 changes: 1 addition & 1 deletion Sources/WordPressData/Swift/PostMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ private extension PostMetadataContainer {
extension PostMetadataContainer.Key {
static let jetpackNewsletterAccess: PostMetadataContainer.Key = "_jetpack_newsletter_access"
static let jetpackNewsletterEmailDisabled: PostMetadataContainer.Key = "_jetpack_dont_email_post_to_subs"
static let foreignID: PostMetadataContainer.Key = "wp_jp_foreign_id"
public static let foreignID: PostMetadataContainer.Key = "wp_jp_foreign_id"
}
2 changes: 0 additions & 2 deletions Sources/WordPressData/WordPressData.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ FOUNDATION_EXPORT const unsigned char WordPressDataVersionString[];
// As we'll hopefully soon rewrite these in Swift, we can implement proper access level then.
#import <WordPressData/Blog.h>
#import <WordPressData/CoreDataStack.h>
#import <WordPressData/PostHelper.h>

FOUNDATION_EXTERN void SetCocoaLumberjackObjCLogLevel(NSUInteger ddLogLevelRawValue);
13 changes: 13 additions & 0 deletions WordPress/Classes/Services/AbstractPost+Changes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import WordPressData
import WordPressKit

extension AbstractPost {
/// Returns the changes made in the current revision compared to the
/// previous revision or the original post if there is only one revision.
var changes: RemotePostUpdateParameters {
guard let original else {
return RemotePostUpdateParameters() // Empty
}
return RemotePostUpdateParameters.changes(from: original, to: self)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import WordPressData

extension PostHelper {
public typealias StringDictionary = [String: String]
typealias StringDictionary = [String: String]
typealias Keys = Post.Constants
typealias SkipPrefix = Post.PublicizeMetadataSkipPrefix

Expand All @@ -15,7 +17,7 @@ extension PostHelper {
/// - metadata: The metadata dictionary for the post. Optional because Obj-C shouldn't be trusted.
/// - Returns: A dictionary for the `Post`'s `disabledPublicizeConnections` property.
@objc(disabledPublicizeConnectionsForPost:andMetadata:)
public static func disabledPublicizeConnections(for post: AbstractPost?, metadata: [[String: Any]]?) -> [NSNumber: StringDictionary] {
static func disabledPublicizeConnections(for post: AbstractPost?, metadata: [[String: Any]]?) -> [NSNumber: StringDictionary] {
guard let post, let metadata else {
return [:]
}
Expand Down Expand Up @@ -70,7 +72,7 @@ extension PostHelper {
/// - Parameter post: The associated `Post` object.
/// - Returns: An array of metadata dictionaries representing the `Post`'s disabled connections.
@objc(publicizeMetadataEntriesForPost:)
public static func publicizeMetadataEntries(for post: Post?) -> [StringDictionary] {
static func publicizeMetadataEntries(for post: Post?) -> [StringDictionary] {
guard let post,
let disabledConnectionsDictionary = post.disabledPublicizeConnections else {
return []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Foundation
import WordPressShared
import WordPressData
import WordPressKit
import WordPressShared

extension PostHelper {
@objc public static let foreignIDKey = PostMetadataContainer.Key.foreignID.rawValue
@objc static let foreignIDKey = PostMetadataContainer.Key.foreignID.rawValue

@objc public static func getForeignID(for post: RemotePost) -> UUID? {
@objc static func getForeignID(for post: RemotePost) -> UUID? {
guard let metadata = post.metadata as? [[String: Any]] else {
return nil
}
Expand All @@ -16,7 +17,7 @@ extension PostHelper {
return UUID(uuidString: value)
}

@objc public static func makeRawMetadata(from post: RemotePost) -> Data? {
@objc static func makeRawMetadata(from post: RemotePost) -> Data? {
guard let metadata = post.metadata else {
return nil
}
Expand All @@ -32,18 +33,8 @@ extension PostHelper {
}
}

static func mapDictionaryToMetadataItems(_ dictionary: [String: Any]) -> RemotePostMetadataItem? {
let id = dictionary["id"]
let value = dictionary["value"]
return RemotePostMetadataItem(
id: (id as? String) ?? (id as? NSNumber)?.stringValue,
key: dictionary["key"] as? String,
value: value as? String
)
}

@objc(createOrUpdateCategoryForRemoteCategory:blog:context:)
public class func createOrUpdateCategory(for remoteCategory: RemotePostCategory, in blog: Blog, in context: NSManagedObjectContext) -> PostCategory? {
class func createOrUpdateCategory(for remoteCategory: RemotePostCategory, in blog: Blog, in context: NSManagedObjectContext) -> PostCategory? {
guard let categoryID = remoteCategory.categoryID else {
wpAssertionFailure("remote category missing categoryID")
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "PostHelper.h"
#import "WordPressData-Swift.h"
#import "WordPress-Swift.h"

@import WordPressData;
@import WordPressKit;
@import WordPressKitModels;
@import WordPressShared;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Foundation
import WordPressData
import WordPressKit
import WordPressShared

extension RemotePostCreateParameters {
/// Initializes the parameters required to create the given post.
public init(post: AbstractPost) {
init(post: AbstractPost) {
self.init(
type: post is Post ? "post" : "page",
status: (post.status ?? .draft).rawValue
Expand Down Expand Up @@ -32,7 +33,7 @@ extension RemotePostCreateParameters {
$0.categoryID.intValue
}
metadata = Set(Self.generateRemoteMetadata(for: post).compactMap { dictionary -> RemotePostMetadataItem? in
return PostHelper.mapDictionaryToMetadataItems(dictionary)
return Self.mapDictionaryToMetadataItems(dictionary)
})
discussion = RemotePostDiscussionSettings(
allowComments: post.allowComments,
Expand All @@ -56,4 +57,14 @@ private extension RemotePostCreateParameters {
output += PostMetadata.entries(in: PostMetadataContainer(post))
return output
}

static func mapDictionaryToMetadataItems(_ dictionary: [String: Any]) -> RemotePostMetadataItem? {
let id = dictionary["id"]
let value = dictionary["value"]
return RemotePostMetadataItem(
id: (id as? String) ?? (id as? NSNumber)?.stringValue,
key: dictionary["key"] as? String,
value: value as? String
)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import WordPressData
import WordPressKit

extension RemotePostUpdateParameters {

public var isEmpty: Bool {
var isEmpty: Bool {
self == RemotePostUpdateParameters()
}

/// Returns a diff between the original and the latest revision with the
/// changes applied on top.
public static func changes(
static func changes(
from original: AbstractPost,
to latest: AbstractPost,
with changes: RemotePostUpdateParameters? = nil
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/System/WordPress-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "NSObject+Helpers.h"

#import "PostCategoryService.h"
#import "PostHelper.h"
#import "PostTagService.h"

#import "ReaderPostService.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "PostHelper.h"
@import WordPressData;

@class Blog;
Expand Down
1 change: 0 additions & 1 deletion WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,6 @@
publicHeaders = (
"Objective-C/include/Blog.h",
"Objective-C/include/CoreDataStack.h",
"Objective-C/include/PostHelper.h",
WordPressData.h,
);
target = 3F7AE0B42D9B30A100AB4892 /* WordPressData */;
Expand Down