Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7b51e5e
Merge branch 'release/3.6.1'
koke Jun 18, 2013
7a80135
Merge branch 'release/3.6.2'
koke Jun 26, 2013
bea2667
Merge branch 'release/3.6.3'
koke Jun 27, 2013
3ecab4c
add date_modified_gmt field to Post and Page models - used for confli…
maxme Jul 10, 2013
75f1bf1
Conflict detection on AbstractPost upload
maxme Jul 10, 2013
d06d19b
new subview: RevisionView
maxme Jul 10, 2013
6eef078
minor additions to models Page and Post (set .author to wp_author_dis…
maxme Jul 10, 2013
162bc36
init a _RevisionSelector_ draft for iPhone
maxme Jul 10, 2013
9633989
plug the conflict detector and revision browser in EditPostViewContro…
maxme Jul 10, 2013
c9afd0a
- "Use" revision button works
maxme Jul 10, 2013
3afd286
improve RevisionView styling
maxme Jul 11, 2013
7092c53
fix pageControl flickering
maxme Jul 11, 2013
1905319
present RevisionSelector as a modal view instead of pushing it in nav…
maxme Jul 11, 2013
3dc73ee
Cleaning, add comments and marks
maxme Jul 11, 2013
b6c9b12
change background from sidebar_bg to dark gray
maxme Jul 11, 2013
c72396d
do a wp.editPost request with _if_not_modified_since_ option to check…
maxme Jul 11, 2013
ce0c67c
Use wp.editPost directly to check for a conflict
maxme Jul 11, 2013
3971e3c
plug alternative conflict detection in EditPostViewController
maxme Jul 11, 2013
b3cdf12
create new CoreData model (v.12) and set it as current - (and rollbac…
maxme Jul 15, 2013
80d49a8
cleanup
maxme Jul 15, 2013
d1d94cd
replace metaWeblog.editPost with wp.editPost
maxme Jul 15, 2013
dda912c
- add an activity indicator and refactor updateLayout
maxme Jul 15, 2013
34051d3
plug RevisionSelector in PostsViewController
maxme Jul 15, 2013
e5dd9c2
Merge branch 'develop' into ticket-1498-wp.editPost
maxme Jul 15, 2013
d4336d0
fix merge error
maxme Jul 15, 2013
428ae79
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
maxme Jul 16, 2013
fa6160b
use terms_names field to post Categories and Tags using wp.editPost
maxme Jul 16, 2013
5ece688
set AbstractPostRemoteStatusSync after wp.editPost->wp.getPost
maxme Jul 16, 2013
c12c696
hide Pager in RevisionSelector when pageNumber <= 1
maxme Jul 16, 2013
e232397
delete unused revisions when RevisionSelector is canceled
maxme Jul 16, 2013
b11bb12
use wp.newPost instead of metaWeblog.newPost
maxme Jul 16, 2013
b5876bb
new core data model version (v.13) and custom PostToPost class to mig…
maxme Jul 16, 2013
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
36 changes: 14 additions & 22 deletions WordPress/Classes/AbstractPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ - (void)remove {

- (void)awakeFromFetch {
[super awakeFromFetch];

if (self.remoteStatus == AbstractPostRemoteStatusPushing) {
// If we've just been fetched and our status is AbstractPostRemoteStatusPushing then something
// when wrong saving -- the app crashed for instance. So change our remote status to failed.
// Do this after a delay since property changes and saves are ignored during awakeFromFetch. See docs.
[self performSelector:@selector(markRemoteStatusFailed) withObject:nil afterDelay:0.1];
}

}

- (void)markRemoteStatusFailed {
Expand Down Expand Up @@ -72,7 +72,7 @@ - (AbstractPost *)createRevision {
NSLog(@"!!! Already have revision");
return self.revision;
}

AbstractPost *post = [NSEntityDescription insertNewObjectForEntityForName:[[self entity] name] inManagedObjectContext:[self managedObjectContext]];
[post cloneFrom:self];
[post setValue:self forKey:@"original"];
Expand Down Expand Up @@ -121,62 +121,54 @@ - (AbstractPost *)original {
- (BOOL)hasChanges {
if (![self isRevision])
return NO;

//Do not move the Featured Image check below in the code.
if ((self.post_thumbnail != self.original.post_thumbnail)
&& (![self.post_thumbnail isEqual:self.original.post_thumbnail])){
self.isFeaturedImageChanged = YES;
return YES;
} else
self.isFeaturedImageChanged = NO;


//first let's check if there's no post title or content (in case a cheeky user deleted them both)
if ((self.postTitle == nil || [self.postTitle isEqualToString:@""]) && (self.content == nil || [self.content isEqualToString:@""]))
return NO;

// We need the extra check since [nil isEqual:nil] returns NO
if ((self.postTitle != self.original.postTitle)
&& (![self.postTitle isEqual:self.original.postTitle]))
return YES;
if ((self.content != self.original.content)
&& (![self.content isEqual:self.original.content]))
return YES;

if ((self.status != self.original.status)
&& (![self.status isEqual:self.original.status]))
return YES;

if ((self.password != self.original.password)
&& (![self.password isEqual:self.original.password]))
return YES;

if ((self.dateCreated != self.original.dateCreated)
&& (![self.dateCreated isEqual:self.original.dateCreated]))
return YES;

if ((self.permaLink != self.original.permaLink)
&& (![self.permaLink isEqual:self.original.permaLink]))
return YES;

if (self.hasRemote == NO) {
return YES;
}

// Relationships are not going to be nil, just empty sets,
// so we can avoid the extra check
if (![self.media isEqual:self.original.media])
return YES;

return NO;
}

- (void)findComments {
NSSet *comments = [self.blog.comments filteredSetUsingPredicate:
[NSPredicate predicateWithFormat:@"(postID == %@) AND (post == NULL)", self.postID]];
if (comments && [comments count] > 0) {
[self.comments unionSet:comments];
}
return NO;
}

- (void)autosave {
Expand Down
8 changes: 6 additions & 2 deletions WordPress/Classes/BasePost.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

typedef enum {
AbstractPostRemoteStatusPushing, // Uploading post
AbstractPostRemoteStatusFailed, // Upload failed
AbstractPostRemoteStatusLocal, // Only local version
AbstractPostRemoteStatusFailed, // Upload failed
AbstractPostRemoteStatusConflicted, // Upload conflicts with a newer server revision
AbstractPostRemoteStatusLocal, // Only local version
AbstractPostRemoteStatusSync, // Post uploaded
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it's going to break for existing installs: Local drafts will turn into conflicts and synced posts will turn into local drafts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Migration is done in commit b5876bb

} AbstractPostRemoteStatus;

Expand All @@ -25,6 +26,7 @@ typedef enum {
@property (nonatomic, strong) NSNumber * postID;
@property (nonatomic, strong) NSString * author;
@property (nonatomic, strong) NSDate * date_created_gmt;
@property (nonatomic, strong) NSDate * date_modified_gmt;
@property (nonatomic, strong) NSString * postTitle;
@property (nonatomic, strong) NSString * content;
@property (nonatomic, strong) NSString * status;
Expand All @@ -40,6 +42,7 @@ typedef enum {

@property (readonly) BOOL hasChanges;
@property (nonatomic, assign) BOOL isFeaturedImageChanged;
@property (nonatomic, assign) BOOL ignoreConflictCheck;

- (NSArray *)availableStatuses;
// Does the post exist on the blog?
Expand All @@ -63,5 +66,6 @@ typedef enum {
#pragma mark     Data Management
- (void)uploadWithSuccess:(void (^)())success failure:(void (^)(NSError *error))failure;
- (void)deletePostWithSuccess:(void (^)())success failure:(void (^)(NSError *error))failure;
- (void)getPostWithSuccess:(void (^)())success failure:(void (^)(NSError *error))failure;

@end
42 changes: 23 additions & 19 deletions WordPress/Classes/BasePost.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ - (void)markRemoteStatusFailed;
@end

@implementation BasePost
@dynamic author, content, date_created_gmt, postID, postTitle, status, password, remoteStatusNumber, permaLink,
mt_excerpt, mt_text_more, wp_slug, post_thumbnail;
@dynamic author, content, date_created_gmt, date_modified_gmt, postID, postTitle, status, password, remoteStatusNumber,
permaLink, mt_excerpt, mt_text_more, wp_slug, post_thumbnail;

@synthesize isFeaturedImageChanged;
@synthesize isFeaturedImageChanged, ignoreConflictCheck;

+ (NSString *)titleForStatus:(NSString *)status {
if ([status isEqualToString:@"draft"]) {
Expand Down Expand Up @@ -111,6 +111,9 @@ + (NSString *)titleForRemoteStatus:(NSNumber *)remoteStatus {
case AbstractPostRemoteStatusFailed:
return NSLocalizedString(@"Failed", @"");
break;
case AbstractPostRemoteStatusConflicted:
return NSLocalizedString(@"Conflicted", @"");
break;
case AbstractPostRemoteStatusSync:
return NSLocalizedString(@"Posts", @"");
break;
Expand Down Expand Up @@ -141,41 +144,42 @@ - (void)setDateCreated:(NSDate *)localDate {


- (void)findComments {

}

- (void)uploadWithSuccess:(void (^)())success failure:(void (^)(NSError *error))failure {
}

- (void)deletePostWithSuccess:(void (^)())success failure:(void (^)(NSError *error))failure {

}

- (void)getPostWithSuccess:(void (^)())success failure:(void (^)(NSError *error))failure {
}

- (NSDictionary *)XMLRPCDictionary {
NSMutableDictionary *postParams = [NSMutableDictionary dictionary];
[postParams setValueIfNotNil:self.postTitle forKey:@"title"];
[postParams setValueIfNotNil:self.content forKey:@"description"];
[postParams setValueIfNotNil:self.date_created_gmt forKey:@"date_created_gmt"];
[postParams setValueIfNotNil:self.password forKey:@"wp_password"];
[postParams setValueIfNotNil:self.permaLink forKey:@"permalink"];
[postParams setValueIfNotNil:self.mt_excerpt forKey:@"mt_excerpt"];
[postParams setValueIfNotNil:self.wp_slug forKey:@"wp_slug"];

[postParams setValueIfNotNil:self.postTitle forKey:@"post_title"];
[postParams setValueIfNotNil:self.content forKey:@"post_content"];
[postParams setValueIfNotNil:self.date_created_gmt forKey:@"post_date_gmt"];
[postParams setValueIfNotNil:self.password forKey:@"post_password"];
[postParams setValueIfNotNil:self.permaLink forKey:@"link"];
[postParams setValueIfNotNil:self.mt_excerpt forKey:@"post_excerpt"];
[postParams setValueIfNotNil:self.wp_slug forKey:@"post_name"];
// To remove a featured image, you have to send an empty string to the API
if (self.post_thumbnail == nil) {
// Including an empty string for wp_post_thumbnail generates
// an "Invalid attachment ID" error in the call to wp.newPage
if ([self.postID intValue] > 0) {
[postParams setValue:@"" forKey:@"wp_post_thumbnail"];
if ([self.postID longLongValue] > 0) {
[postParams setValue:@"" forKey:@"post_thumbnail"];
}

} else {
[postParams setValue:self.post_thumbnail forKey:@"wp_post_thumbnail"];
[postParams setValue:self.post_thumbnail forKey:@"post_thumbnail"];
}

if (self.mt_text_more != nil && [self.mt_text_more length] > 0)
[postParams setObject:self.mt_text_more forKey:@"mt_text_more"];
[postParams setObject:self.mt_text_more forKey:@"post_more"];

return postParams;
}

Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ - (WPXMLRPCRequestOperation *)operationForOptionsWithSuccess:(void (^)())success
return;

self.options = [NSDictionary dictionaryWithDictionary:(NSDictionary *)responseObject];
NSString *minimumVersion = @"3.1";
NSString *minimumVersion = @"3.4";
float version = [[self version] floatValue];
if (version < [minimumVersion floatValue]) {
if (self.lastUpdateWarning == nil || [self.lastUpdateWarning floatValue] < [minimumVersion floatValue]) {
Expand Down
15 changes: 5 additions & 10 deletions WordPress/Classes/EditPostViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "NSString+XMLExtensions.h"
#import "WPPopoverBackgroundView.h"
#import "WPAddCategoryViewController.h"
#import "RevisionSelectorViewController.h"

NSTimeInterval kAnimationDuration = 0.3f;

Expand Down Expand Up @@ -127,10 +128,6 @@ - (void)viewDidLoad {
[self addChildViewController:self.postMediaViewController];
}

self.postSettingsViewController.view.frame = editView.frame;
self.postMediaViewController.view.frame = editView.frame;
self.postPreviewViewController.view.frame = editView.frame;

self.title = [self editorTitle];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
Expand Down Expand Up @@ -578,8 +575,7 @@ - (void)newCategoryCreatedNotificationReceived:(NSNotification *)notification {
}


- (IBAction)showAddNewCategoryView:(id)sender
{
- (IBAction)showAddNewCategoryView:(id)sender {
WPFLogMethod();
WPAddCategoryViewController *addCategoryViewController = [[WPAddCategoryViewController alloc] initWithNibName:@"WPAddCategoryViewController" bundle:nil];
addCategoryViewController.blog = self.post.blog;
Expand Down Expand Up @@ -643,15 +639,14 @@ - (void)savePost:(BOOL)upload{
} failure:^(NSError *error) {
WPFLog(@"post failed: %@", [error localizedDescription]);
}];
} else {
} else {
[self.apost.original save];
}

[self dismissEditView];
}

- (void)logSavePostStats
{
- (void)logSavePostStats {
NSString *buttonTitle = self.navigationItem.rightBarButtonItem.title;
NSString *event;
if ([buttonTitle isEqualToString:NSLocalizedString(@"Schedule", nil)]) {
Expand Down Expand Up @@ -1433,7 +1428,7 @@ - (void)wrapSelectionWithTag:(NSString *)tag {
suffix = [NSString stringWithFormat:@"</%@>\n", tag];
} else {
prefix = [NSString stringWithFormat:@"<%@>", tag];
suffix = [NSString stringWithFormat:@"</%@>", tag];
suffix = [NSString stringWithFormat:@"</%@>", tag];
}
textView.scrollEnabled = NO;
NSString *replacement = [NSString stringWithFormat:@"%@%@%@",prefix,selection,suffix];
Expand Down
2 changes: 2 additions & 0 deletions WordPress/Classes/Page.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ + (NSString *)titleForRemoteStatus:(NSNumber *)remoteStatus {

- (void )updateFromDictionary:(NSDictionary *)postInfo {
self.postTitle = [postInfo objectForKey:@"title"];
self.author = [postInfo objectForKey:@"wp_author_display_name"];
self.postID = [[postInfo objectForKey:@"page_id"] numericValue];
self.content = [postInfo objectForKey:@"description"];
self.date_modified_gmt = [postInfo objectForKey:@"date_modified_gmt"];
self.date_created_gmt = [postInfo objectForKey:@"date_created_gmt"];
NSString *status = [postInfo objectForKey:@"page_status"];
if ([status isEqualToString:@"future"]) {
Expand Down
Loading