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
5 changes: 2 additions & 3 deletions Sources/WordPressData/Objective-C/PostHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ + (void)updatePost:(AbstractPost *)post withRemotePost:(RemotePost *)remotePost
}

post.rawMetadata = [PostHelper makeRawMetadataFrom:remotePost];
post.foreignID = [PostHelper getForeignIDFor:remotePost];

post.autosaveTitle = remotePost.autosave.title;
post.autosaveExcerpt = remotePost.autosave.excerpt;
Expand All @@ -68,7 +69,6 @@ + (void)updatePost:(AbstractPost *)post withRemotePost:(RemotePost *)remotePost
if ([post isKindOfClass:[Page class]]) {
Page *pagePost = (Page *)post;
pagePost.parentID = remotePost.parentID;
pagePost.foreignID = remotePost.foreignID;
} else if ([post isKindOfClass:[Post class]]) {
Post *postPost = (Post *)post;
postPost.commentsStatus = remotePost.commentsStatus;
Expand Down Expand Up @@ -100,7 +100,6 @@ + (void)updatePost:(AbstractPost *)post withRemotePost:(RemotePost *)remotePost
publicizeMessage = [publicizeMessageDictionary stringForKey:@"value"];
publicizeMessageID = [publicizeMessageDictionary stringForKey:@"id"];
}
postPost.foreignID = remotePost.foreignID;
postPost.publicID = publicID;
postPost.publicizeMessage = publicizeMessage;
postPost.publicizeMessageID = publicizeMessageID;
Expand Down Expand Up @@ -185,7 +184,7 @@ + (NSArray *)mergePosts:(NSArray <RemotePost *> *)remotePosts
for (RemotePost *remotePost in remotePosts) {
AbstractPost *post = [blog lookupPostWithID:remotePost.postID inContext:context];
if (post == nil) {
NSUUID *foreignID = remotePost.foreignID;
NSUUID *foreignID = [PostHelper getForeignIDFor:remotePost];
if (foreignID != nil) {
post = [blog lookupLocalPostWithForeignID:foreignID inContext:context];
}
Expand Down
13 changes: 12 additions & 1 deletion Sources/WordPressData/Swift/PostHelper+Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import WordPressShared
import WordPressKit

extension PostHelper {
@objc public static let foreignIDKey = "wp_jp_foreign_id"
@objc public static let foreignIDKey = PostMetadataContainer.Key.foreignID.rawValue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's still used in one more place – will address later.


@objc public static func getForeignID(for post: RemotePost) -> UUID? {
guard let metadata = post.metadata as? [[String: Any]] else {
return nil
}
let container = PostMetadataContainer(metadata: metadata)
guard let value = container.getString(for: .foreignID) else {
return nil
}
return UUID(uuidString: value)
}

@objc public static func makeRawMetadata(from post: RemotePost) -> Data? {
guard let metadata = post.metadata else {
Expand Down
1 change: 1 addition & 0 deletions Sources/WordPressData/Swift/PostMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +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"
}
25 changes: 0 additions & 25 deletions Sources/WordPressData/Swift/RemotePost+Metadata.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class PostRepositoryTests: CoreDataTestCase {
if $0 <= 3 {
post.metadata = [[
"id": 1234,
"key": PostHelper.foreignIDKey,
"key": "wp_jp_foreign_id",
"value": "892D484C-9972-47DE-8103-03A7FDE4EFCC"
]]
}
Expand Down