Skip to content
Closed
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
4 changes: 4 additions & 0 deletions MIGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
This file documents changes in the data model. Please explain any changes to the
data model as well as any custom migrations.

## WordPress 77
- @aerych 2018-07-27
- `SharingService` added `externalUsersOnly` (bool) property. A new field returned by the API.

## WordPress 76

- @frosty 2018-05-16
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def shared_with_networking_pods
pod 'AFNetworking', '3.2.1'
pod 'Alamofire', '4.7.2'
pod 'wpxmlrpc', '0.8.3'
pod 'WordPressKit', '~> 1.2'
pod 'WordPressKit', '1.2.1'
end

def shared_test_pods
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ PODS:
- WordPressShared (~> 1.0)
- WordPressUI (~> 1.0)
- wpxmlrpc (~> 0.8)
- WordPressKit (1.2):
- WordPressKit (1.2.1):
- Alamofire (~> 4.7)
- CocoaLumberjack (= 3.4.2)
- NSObject-SafeExpectations (= 0.0.3)
Expand Down Expand Up @@ -167,7 +167,7 @@ DEPENDENCIES:
- WordPress-Aztec-iOS (= 1.0.0-beta.24)
- WordPress-Editor-iOS (= 1.0.0-beta.24)
- WordPressAuthenticator (= 1.0.4)
- WordPressKit (~> 1.2)
- WordPressKit (= 1.2.1)
- WordPressShared (= 1.0.9)
- WordPressUI (from `https://github.com/wordpress-mobile/WordPressUI-iOS.git`, commit `7a5b1a3fb44f62416fbc2e5f0de623b87b613aae`)
- WPMediaPicker (= 1.1)
Expand Down Expand Up @@ -256,13 +256,13 @@ SPEC CHECKSUMS:
WordPress-Aztec-iOS: b019a2ee94d7a7c300b463776b5009682cd13e9c
WordPress-Editor-iOS: d110040c64267ab002c3551cc343b8dfe6f59f3a
WordPressAuthenticator: 2825f0c56f83a17470564dbec427991fa5cac5af
WordPressKit: 68eaa8df5ceedeed03ba796afc4b825f0bed4fe2
WordPressKit: a4a3849684f631a3abf579f6d3f15a32677cbb30
WordPressShared: e5ea8a1ed3329735e40bd6623830960f63dd10fd
WordPressUI: af141587ec444f9af753a00605bd0d3f14d8d8a3
WPMediaPicker: 5cc9386a4720f906d8fb79c7c4090d216b9f2348
wpxmlrpc: bfc572f62ce7ee897f6f38b098d2ba08732ecef4
ZendeskSDK: 2cda4db2ba6b10ba89aeb8dddaa94e97c85946a0

PODFILE CHECKSUM: 2234776d14f86b13e13804654ce8178d74ac866d
PODFILE CHECKSUM: 6c257291bab7089dda9372c0fc53feda5f8b5f3a

COCOAPODS: 1.5.3
12 changes: 12 additions & 0 deletions WordPress/Classes/Models/PublicizeConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ open class PublicizeConnection: NSManagedObject {
@objc open func isBroken() -> Bool {
return status == "broken"
}

@objc open func mustDisconnect() -> Bool {
return status == "must-disconnect"
}

@objc open func requiresUserAction() -> Bool {
return isBroken() || mustDisconnect()
}

@objc open func mustDisconnectFacebook() -> Bool {
return mustDisconnect() && service == PublicizeService.facebookServiceID
}
}
2 changes: 2 additions & 0 deletions WordPress/Classes/Models/PublicizeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import CoreData

open class PublicizeService: NSManagedObject {
@objc static let googlePlusServiceID = "google_plus"
@objc static let facebookServiceID = "facebook"

@NSManaged open var connectURL: String
@NSManaged open var detail: String
@NSManaged open var externalUsersOnly: Bool
@NSManaged open var icon: String
@NSManaged open var jetpackSupport: Bool
@NSManaged open var jetpackModuleRequired: String
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Services/SharingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ open class SharingService: LocalCoreDataService {
}
pubService?.connectURL = remoteService.connectURL
pubService?.detail = remoteService.detail
pubService?.externalUsersOnly = remoteService.externalUsersOnly
pubService?.icon = remoteService.icon
pubService?.jetpackModuleRequired = remoteService.jetpackModuleRequired
pubService?.jetpackSupport = remoteService.jetpackSupport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import WordPressShared
@objc var immutableHandler: ImmuTableViewHandler!
@objc var delegate: SharingAccountSelectionDelegate?

fileprivate lazy var noResultsViewController: NoResultsViewController = {
let controller = NoResultsViewController.controller()
controller.view.frame = view.frame
addChildViewController(controller)
view.addSubview(controller.view)
controller.didMove(toParentViewController: self)
return controller
}()


// MARK: - Lifecycle Methods

Expand Down Expand Up @@ -72,6 +81,25 @@ import WordPressShared
}


fileprivate func showNoResultsViewController() {
let title = NSLocalizedString("No Accounts Found",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a completely personal preference, but I tend to declare strings as constants (or as static cases in an enumeration), so that, at the call site, like here, it would read similar to this:

fileprivate func showNoResultsViewController() {
         noResultsViewController.configure(title: "", buttonTitle: NoResults.buttonTitle, subtitle: NoResults.message, image: nil, accessoryView: nil)
         noResultsViewController.delegate = self
}

I have found that makes the code slightly easier to parse for me. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm a fan of that when a string is reused. When used only once I like declaring a string in the context of its usage as a way of having as much context as possible in one place.

comment: "Title of an error message. There were no third-party service accounts found to setup sharing.")
let message = NSLocalizedString("Sorry. The social service did not tell us which account could be used for sharing.",
comment: "An error message shown if a third-party social service does not specify any accounts that an be used with publicize sharing.")
noResultsViewController.configure(title: title, buttonTitle: nil, subtitle: message, image: nil, accessoryView: nil)
}


fileprivate func showFacebookNotice() {
let message = NSLocalizedString("The Facebook connection could not be made because this account does not have access to any pages. Facebook supports sharing connections to Facebook Pages, but not to Facebook Profiles.",
comment: "Error message shown to a user who is trying to share to Facebook but does not have any available Facebook Pages.")

let buttonTitle = NSLocalizedString("Learn more", comment: "A button title.")
noResultsViewController.configure(title: "", buttonTitle: buttonTitle, subtitle: message, image: nil, accessoryView: nil)
noResultsViewController.delegate = self
}


// MARK: - View Model Wrangling


Expand All @@ -84,6 +112,15 @@ import WordPressShared
var connectedAccounts = [KeyringAccount]()
var accounts = keyringAccountsFromKeyringConnections(keyringConnections)

if accounts.count == 0 {
if publicizeService.serviceID == PublicizeService.facebookServiceID {
showFacebookNotice()
} else {
showNoResultsViewController()
}
return ImmuTable(sections: [])
}

// Filter out connected accounts into a different Array
for (idx, acct) in accounts.enumerated() {
if accountIsConnected(acct) {
Expand Down Expand Up @@ -196,7 +233,11 @@ import WordPressShared

for connection in connections {
let acct = KeyringAccount(name: connection.externalDisplay, externalID: nil, externalIDForConnection: connection.externalID, keyringConnection: connection)
accounts.append(acct)

// Do not include the service if it only supports external users.
if !publicizeService.externalUsersOnly {
accounts.append(acct)
}

for externalUser in connection.additionalExternalUsers {
let acct = KeyringAccount(name: externalUser.externalName, externalID: externalUser.externalID, externalIDForConnection: externalUser.externalID, keyringConnection: connection)
Expand Down Expand Up @@ -283,3 +324,13 @@ import WordPressShared
func didDismissSharingAccountViewController(_ controller: SharingAccountViewController)
func sharingAccountViewController(_ controller: SharingAccountViewController, selectedKeyringConnection keyringConnection: KeyringConnection, externalID: String?)
}


extension SharingAccountViewController: NoResultsViewControllerDelegate {
func actionButtonPressed() {
if let url = URL(string: "https://en.support.wordpress.com/publicize/#facebook-pages") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@aerych do you think we should show the blog post instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should match the behavior in Calypso where the support page is linked from the message shown when attempting to link a Facebook account with no pages. The blog post is linked from the message shown for a pre-existing connection that needs to be disconnected.

Unless I somehow got that backwards 😬

UIApplication.shared.open(url)
}
dismiss(animated: true, completion: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ - (void)configurePublicizeCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath
PublicizeConnection *connection = [[self connectionsForService] objectAtIndex:indexPath.row];
cell.textLabel.text = connection.externalDisplay;

if ([connection isBroken]) {
if ([connection requiresUserAction]) {
cell.accessoryView = [WPStyleGuide sharingCellWarningAccessoryImageView];
}
}
Expand Down
69 changes: 58 additions & 11 deletions WordPress/Classes/ViewRelated/Blog/SharingDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,46 @@ - (void)viewDidLoad

#pragma mark - Instance Methods

- (void)openFacebookFAQ
{
NSURL *url = [NSURL URLWithString:@"https://en.blog.wordpress.com/2018/07/23/sharing-options-from-wordpress-com-to-facebook-are-changing/"];
[[UIApplication sharedApplication] openURL:url options:[NSDictionary new] completionHandler:nil];
}

- (NSString *)textForFacebookFooter
{
NSString *title = NSLocalizedString(@"As of August 1, 2018, Facebook no longer allows direct sharing of posts to Facebook Profiles. Connections to Facebook Pages remain unchanged.", @"Message shown to users who have an old publicize connection to a facebook profile.");
return [NSString stringWithFormat:title, self.publicizeConnection.label];
}

- (NSString *)textForBrokenConnectionFooter
{
NSString *title = NSLocalizedString(@"There is an issue connecting to %@. Reconnect to continue publicizing.", @"Informs the user about an issue connecting to the third-party sharing service. The `%@` is a placeholder for the service name.");
return [NSString stringWithFormat:title, self.publicizeConnection.label];
}

- (void)configureReconnectCell: (UITableViewCell *)cell
{
cell.textLabel.text = NSLocalizedString(@"Reconnect", @"Verb. Text label. Tapping attempts to reconnect a third-party sharing service to the user's blog.");
[WPStyleGuide configureTableViewActionCell:cell];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textColor = [WPStyleGuide jazzyOrange];
}

- (void)configureLearnMoreCell: (UITableViewCell *)cell
{
cell.textLabel.text = NSLocalizedString(@"Learn More", @"Title of a button. Tapping allows the user to learn more about the specific error.");
[WPStyleGuide configureTableViewActionCell:cell];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textColor = [WPStyleGuide wordPressBlue];
}

- (void)configureDisconnectCell: (UITableViewCell *)cell
{
cell.textLabel.text = NSLocalizedString(@"Disconnect", @"Verb. Text label. Tapping disconnects a third-party sharing service from the user's blog.");
[WPStyleGuide configureTableViewDestructiveActionCell:cell];
}

- (NSManagedObjectContext *)managedObjectContext
{
return self.blog.managedObjectContext;
Expand All @@ -70,7 +110,7 @@ - (NSManagedObjectContext *)managedObjectContext

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if ([self.publicizeConnection isBroken]) {
if ([self.publicizeConnection requiresUserAction]) {
return 3;
}

Expand All @@ -96,10 +136,17 @@ - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInte
if (section == 0) {
return NSLocalizedString(@"Allow this connection to be used by all admins and users of your site.", @"");
}
if (section == 1 && [self.publicizeConnection isBroken]) {
NSString *title = NSLocalizedString(@"There is an issue connecting to %@. Reconnect to continue publicizing.", @"Informs the user about an issue connecting to the third-party sharing service. The `%@` is a placeholder for the service name.");
return [NSString stringWithFormat:title, self.publicizeConnection.label];

if (section == 1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest extracting each logical branch to a separate method. That way titleForFooterInSection would be easier to read and parse, which might also make it. in the long term, more difficult to get wrong.

if ([self.publicizeConnection mustDisconnectFacebook]) {
return [self textForFacebookFooter];
}

if ([self.publicizeConnection isBroken]) {
return [self textForBrokenConnectionFooter];
}
}

return nil;
}

Expand All @@ -120,14 +167,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [self switchTableViewCell];

} else if (indexPath.section == 1 && [self.publicizeConnection isBroken]) {
cell.textLabel.text = NSLocalizedString(@"Reconnect", @"Verb. Text label. Tapping attempts to reconnect a third-party sharing service to the user's blog.");
[WPStyleGuide configureTableViewActionCell:cell];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textColor = [WPStyleGuide jazzyOrange];
[self configureReconnectCell:cell];

} else if (indexPath.section == 1 && [self.publicizeConnection mustDisconnectFacebook]) {
[self configureLearnMoreCell:cell];

} else {
cell.textLabel.text = NSLocalizedString(@"Disconnect", @"Verb. Text label. Tapping disconnects a third-party sharing service from the user's blog.");
[WPStyleGuide configureTableViewDestructiveActionCell:cell];
[self configureDisconnectCell:cell];
}

return cell;
Expand All @@ -139,7 +185,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath

if (indexPath.section == 1 && [self.publicizeConnection isBroken]) {
[self reconnectPublicizeConnection];

} else if (indexPath.section == 1 && [self.publicizeConnection mustDisconnectFacebook]) {
[self openFacebookFAQ];
} else {
[self promptToConfirmDisconnect];
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/ViewRelated/Blog/SharingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ - (void)configurePublicizeCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath

// Check if any of the connections are broken.
for (PublicizeConnection *pubConn in connections) {
if ([pubConn isBroken]) {
if ([pubConn requiresUserAction]) {
cell.accessoryView = [WPStyleGuide sharingCellWarningAccessoryImageView];
break;
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/WordPress.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>WordPress 76.xcdatamodel</string>
<string>WordPress 77.xcdatamodel</string>
</dict>
</plist>
Loading