Skip to content

Commit 31a4b92

Browse files
authored
Merge pull request #21061 from wordpress-mobile/issue/20784-update-social-list
Jetpack Social: Handle remaining shares on post settings screen
2 parents 9be6a75 + ee476a0 commit 31a4b92

File tree

6 files changed

+77
-2
lines changed

6 files changed

+77
-2
lines changed

WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ class AztecPostViewController: UIViewController, PostEditor {
504504
PostCoordinator.shared.cancelAnyPendingSaveOf(post: post)
505505
addObservers(toPost: post)
506506
registerMediaObserver()
507+
disableSocialConnectionsIfNecessary()
507508
}
508509

509510
required init?(coder aDecoder: NSCoder) {

WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ class GutenbergViewController: UIViewController, PostEditor, FeaturedImageDelega
338338

339339
PostCoordinator.shared.cancelAnyPendingSaveOf(post: post)
340340
self.navigationBarManager.delegate = self
341+
disableSocialConnectionsIfNecessary()
341342
}
342343

343344
required init?(coder aDecoder: NSCoder) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
extension PostEditor {
3+
4+
func disableSocialConnectionsIfNecessary() {
5+
guard FeatureFlag.jetpackSocial.enabled,
6+
let post = self.post as? Post,
7+
let remainingShares = self.post.blog.sharingLimit?.remaining,
8+
let connections = self.post.blog.sortedConnections as? [PublicizeConnection],
9+
remainingShares < connections.count else {
10+
return
11+
}
12+
13+
for connection in connections {
14+
post.disablePublicizeConnectionWithKeyringID(connection.keyringConnectionID)
15+
}
16+
}
17+
18+
}

WordPress/Classes/ViewRelated/Post/PostSettingsViewController+JetpackSocial.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ extension PostSettingsViewController {
6666
return hostController.view
6767
}
6868

69+
// MARK: - Social share cells
70+
71+
@objc func userCanEditSharing() -> Bool {
72+
guard let post = self.apost as? Post else {
73+
return false
74+
}
75+
guard FeatureFlag.jetpackSocial.enabled else {
76+
return post.canEditPublicizeSettings()
77+
}
78+
79+
return post.canEditPublicizeSettings() && remainingSocialShares() > 0
80+
}
81+
82+
@objc func remainingSocialShares() -> Int {
83+
self.apost.blog.sharingLimit?.remaining ?? .max
84+
}
85+
6986
}
7087

7188
// MARK: - Private methods

WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ @interface PostSettingsViewController () <UITextFieldDelegate,
7878
@property (nonatomic, strong) WPAndDeviceMediaLibraryDataSource *mediaDataSource;
7979
@property (nonatomic, strong) NSArray *publicizeConnections;
8080
@property (nonatomic, strong) NSArray<PublicizeConnection *> *unsupportedConnections;
81+
@property (nonatomic, strong) NSMutableArray<NSNumber *> *enabledConnections;
8182

8283
@property (nonatomic, strong) NoResultsViewController *noResultsView;
8384
@property (nonatomic, strong) NSObject *mediaLibraryChangeObserverKey;
@@ -112,6 +113,7 @@ - (instancetype)initWithPost:(AbstractPost *)aPost
112113
if (self) {
113114
self.apost = aPost;
114115
self.unsupportedConnections = @[];
116+
self.enabledConnections = [NSMutableArray array];
115117
}
116118
return self;
117119
}
@@ -255,6 +257,11 @@ - (void)setupPublicizeConnections
255257
}
256258

257259
[supportedConnections addObject:connection];
260+
261+
if (![self.post publicizeConnectionDisabledForKeyringID:connection.keyringConnectionID]
262+
&& ![self.enabledConnections containsObject:connection.keyringConnectionID]) {
263+
[self.enabledConnections addObject:connection.keyringConnectionID];
264+
}
258265
}
259266

260267
self.publicizeConnections = supportedConnections;
@@ -927,13 +934,19 @@ - (UITableViewCell *)configureDisclosureCellWithSharing:(BOOL)canEditSharing
927934
- (UITableViewCell *)configureShareCellForIndexPath:(NSIndexPath *)indexPath
928935
{
929936
UITableViewCell *cell;
930-
BOOL canEditSharing = [self.post canEditPublicizeSettings];
937+
BOOL canEditSharing = [self userCanEditSharing];
931938
NSInteger sec = [[self.sections objectAtIndex:indexPath.section] integerValue];
932939
NSArray<PublicizeConnection *> *connections = sec == PostSettingsSectionShare ? self.publicizeConnections : self.unsupportedConnections;
933940

934941
if (indexPath.row < connections.count) {
942+
PublicizeConnection *connection = connections[indexPath.row];
943+
if ([Feature enabled:FeatureFlagJetpackSocial]) {
944+
BOOL hasRemainingShares = self.enabledConnections.count < [self remainingSocialShares];
945+
BOOL isSwitchOn = ![self.post publicizeConnectionDisabledForKeyringID:connection.keyringConnectionID];
946+
canEditSharing = canEditSharing && (hasRemainingShares || isSwitchOn);
947+
}
935948
cell = [self configureSocialCellForIndexPath:indexPath
936-
connection:connections[indexPath.row]
949+
connection:connection
937950
canEditSharing:canEditSharing
938951
section:sec];
939952
} else {
@@ -1170,8 +1183,18 @@ - (void)toggleShareConnectionForIndexPath:(NSIndexPath *) indexPath
11701183
[cellSwitch setOn:!cellSwitch.on animated:YES];
11711184
if (cellSwitch.on) {
11721185
[self.post enablePublicizeConnectionWithKeyringID:connection.keyringConnectionID];
1186+
1187+
if ([Feature enabled:FeatureFlagJetpackSocial]) {
1188+
[self.enabledConnections addObject:connection.keyringConnectionID];
1189+
[self reloadSocialSectionComparingValue:[self remainingSocialShares]];
1190+
}
11731191
} else {
11741192
[self.post disablePublicizeConnectionWithKeyringID:connection.keyringConnectionID];
1193+
1194+
if ([Feature enabled:FeatureFlagJetpackSocial]) {
1195+
[self.enabledConnections removeObject:connection.keyringConnectionID];
1196+
[self reloadSocialSectionComparingValue:[self remainingSocialShares] - 1];
1197+
}
11751198
}
11761199
}
11771200
}
@@ -1414,6 +1437,15 @@ - (UITableViewCell *)configureRemainingSharesCell
14141437
return cell;
14151438
}
14161439

1440+
- (void)reloadSocialSectionComparingValue:(NSUInteger)value
1441+
{
1442+
if (self.enabledConnections.count == value) {
1443+
NSUInteger sharingSection = [self.sections indexOfObject:@(PostSettingsSectionShare)];
1444+
NSIndexSet *sharingSectionSet = [NSIndexSet indexSetWithIndex:sharingSection];
1445+
[self.tableView reloadSections:sharingSectionSet withRowAnimation:UITableViewRowAnimationNone];
1446+
}
1447+
}
1448+
14171449
#pragma mark - WPMediaPickerViewControllerDelegate methods
14181450

14191451
- (UIViewController *)emptyViewControllerForMediaPickerController:(WPMediaPickerViewController *)picker

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,8 @@
21212121
83DC5C472A4B769000DAA422 /* JetpackSocialSettingsRemainingSharesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DC5C452A4B769000DAA422 /* JetpackSocialSettingsRemainingSharesView.swift */; };
21222122
83E1E5592A58B5C2000B576F /* JetpackSocialError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E1E5582A58B5C2000B576F /* JetpackSocialError.swift */; };
21232123
83E1E55A2A58B5C2000B576F /* JetpackSocialError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E1E5582A58B5C2000B576F /* JetpackSocialError.swift */; };
2124+
83E1E55F2A5CB8BF000B576F /* PostEditor+JetpackSocial.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E1E55E2A5CB8BF000B576F /* PostEditor+JetpackSocial.swift */; };
2125+
83E1E5602A5CB8BF000B576F /* PostEditor+JetpackSocial.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E1E55E2A5CB8BF000B576F /* PostEditor+JetpackSocial.swift */; };
21242126
83EF3D7B2937D703000AF9BF /* SharedDataIssueSolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = FED65D78293511E4008071BF /* SharedDataIssueSolver.swift */; };
21252127
83EF3D7F2937F08C000AF9BF /* SharedDataIssueSolverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83EF3D7C2937E969000AF9BF /* SharedDataIssueSolverTests.swift */; };
21262128
83F3E26011275E07004CD686 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83F3E25F11275E07004CD686 /* MapKit.framework */; };
@@ -7505,6 +7507,7 @@
75057507
83C972DF281C45AB0049E1FE /* Post+BloggingPrompts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Post+BloggingPrompts.swift"; sourceTree = "<group>"; };
75067508
83DC5C452A4B769000DAA422 /* JetpackSocialSettingsRemainingSharesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackSocialSettingsRemainingSharesView.swift; sourceTree = "<group>"; };
75077509
83E1E5582A58B5C2000B576F /* JetpackSocialError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackSocialError.swift; sourceTree = "<group>"; };
7510+
83E1E55E2A5CB8BF000B576F /* PostEditor+JetpackSocial.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PostEditor+JetpackSocial.swift"; sourceTree = "<group>"; };
75087511
83EF3D7C2937E969000AF9BF /* SharedDataIssueSolverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedDataIssueSolverTests.swift; sourceTree = "<group>"; };
75097512
83F3E25F11275E07004CD686 /* MapKit.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
75107513
83F3E2D211276371004CD686 /* CoreLocation.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
@@ -14833,6 +14836,7 @@
1483314836
C3E2462826277B7700B99EA6 /* PostAuthorSelectorViewController.swift */,
1483414837
E13ACCD31EE5672100CCE985 /* PostEditor.swift */,
1483514838
E17FEAD7221490F7006E1D2D /* PostEditorAnalyticsSession.swift */,
14839+
83E1E55E2A5CB8BF000B576F /* PostEditor+JetpackSocial.swift */,
1483614840
91DCE84521A6A7F50062F134 /* PostEditor+MoreOptions.swift */,
1483714841
91DCE84721A6C58C0062F134 /* PostEditor+Publish.swift */,
1483814842
7E504D4921A5B8D400E341A8 /* PostEditorNavigationBarManager.swift */,
@@ -21627,6 +21631,7 @@
2162721631
405BFB21223B37A000CD5BEA /* FollowersCountStatsRecordValue+CoreDataProperties.swift in Sources */,
2162821632
D8212CC720AA85C1008E8AE8 /* ReaderHeaderAction.swift in Sources */,
2162921633
405B53FB1F83C369002E19BF /* FancyAlerts+VerificationPrompt.swift in Sources */,
21634+
83E1E55F2A5CB8BF000B576F /* PostEditor+JetpackSocial.swift in Sources */,
2163021635
E6D2E1651B8AAD7E0000ED14 /* ReaderSiteStreamHeader.swift in Sources */,
2163121636
F126FE0020A33BDB0010EB6E /* VideoUploadProcessor.swift in Sources */,
2163221637
E166FA1B1BB0656B00374B5B /* PeopleCellViewModel.swift in Sources */,
@@ -24675,6 +24680,7 @@
2467524680
F4F9D5F2290993D400502576 /* MigrationWelcomeViewModel.swift in Sources */,
2467624681
FABB22ED2602FC2C00C8785C /* EditorFactory.swift in Sources */,
2467724682
FABB22EE2602FC2C00C8785C /* NotificationSiteSubscriptionViewController.swift in Sources */,
24683+
83E1E5602A5CB8BF000B576F /* PostEditor+JetpackSocial.swift in Sources */,
2467824684
FABB22EF2602FC2C00C8785C /* PostingActivityDay.swift in Sources */,
2467924685
C7A09A4B28401B7B003096ED /* QRLoginService.swift in Sources */,
2468024686
FABB22F02602FC2C00C8785C /* ReaderTeamTopic.swift in Sources */,

0 commit comments

Comments
 (0)