mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-24 10:32:46 +02:00
App Settings - Communities: Let the user update the publicity for each his community
This commit is contained in:
@@ -56,6 +56,7 @@ enum
|
||||
SETTINGS_SECTION_OTHER_INDEX,
|
||||
SETTINGS_SECTION_LABS_INDEX,
|
||||
SETTINGS_SECTION_CRYPTOGRAPHY_INDEX,
|
||||
SETTINGS_SECTION_FLAIR_INDEX,
|
||||
SETTINGS_SECTION_DEVICES_INDEX,
|
||||
SETTINGS_SECTION_COUNT
|
||||
};
|
||||
@@ -187,6 +188,9 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
NSMutableArray<MXDevice *> *devicesArray;
|
||||
DeviceView *deviceView;
|
||||
|
||||
// Flair
|
||||
NSMutableArray<MXGroup *> *communitiesArray;
|
||||
|
||||
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
|
||||
id kAppDelegateDidTapStatusBarNotificationObserver;
|
||||
|
||||
@@ -242,6 +246,8 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
isSavingInProgress = NO;
|
||||
isResetPwdInProgress = NO;
|
||||
is3PIDBindingInProgress = NO;
|
||||
|
||||
communitiesArray = [NSMutableArray array];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
@@ -413,6 +419,12 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
// Refresh devices in parallel
|
||||
[self loadDevices];
|
||||
|
||||
// Listen to MXSession groups changes, and load the current list.
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdateGroup:) name:kMXSessionDidJoinGroupNotification object:self.mainSession];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdateGroup:) name:kMXSessionDidLeaveGroupNotification object:self.mainSession];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdateGroup:) name:kMXSessionDidUpdateGroupSummaryNotification object:self.mainSession];
|
||||
[self refreshCommunitiesList:YES];
|
||||
|
||||
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
|
||||
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
||||
|
||||
@@ -952,6 +964,55 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
return cryptoInformationString;
|
||||
}
|
||||
|
||||
- (void)refreshCommunitiesList:(BOOL)forceUpdate
|
||||
{
|
||||
// Reset the table
|
||||
[communitiesArray removeAllObjects];
|
||||
|
||||
NSArray *groups = self.mainSession.groups;
|
||||
for (MXGroup *group in groups)
|
||||
{
|
||||
// Keep only the joined group
|
||||
if (group.membership == MXMembershipJoin)
|
||||
{
|
||||
[communitiesArray addObject:group];
|
||||
|
||||
if (forceUpdate)
|
||||
{
|
||||
// Force the matrix session to refresh the group summary.
|
||||
[self.mainSession updateGroupSummary:group success:nil failure:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSLog(@"[SettingsViewController] Loaded %tu groups", communitiesArray.count);
|
||||
|
||||
// Order alphabetically the groups
|
||||
[communitiesArray sortUsingComparator:^NSComparisonResult(MXGroup *group1, MXGroup *group2)
|
||||
{
|
||||
if (group1.profile.name.length && group1.profile.name.length)
|
||||
{
|
||||
return [group1.profile.name compare:group2.profile.name options:NSCaseInsensitiveSearch];
|
||||
}
|
||||
else if (group1.profile.name.length)
|
||||
{
|
||||
return NSOrderedAscending;
|
||||
}
|
||||
else if (group1.profile.name.length)
|
||||
{
|
||||
return NSOrderedDescending;
|
||||
}
|
||||
return [group1.groupId compare:group2.groupId options:NSCaseInsensitiveSearch];;
|
||||
}];
|
||||
|
||||
[self refreshSettings];
|
||||
}
|
||||
|
||||
- (void)didUpdateGroup:(NSNotification *)notif
|
||||
{
|
||||
[self refreshCommunitiesList:NO];
|
||||
}
|
||||
|
||||
- (void)loadDevices
|
||||
{
|
||||
// Refresh the account devices list
|
||||
@@ -1225,6 +1286,10 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
{
|
||||
count = LABS_COUNT;
|
||||
}
|
||||
else if (section == SETTINGS_SECTION_FLAIR_INDEX)
|
||||
{
|
||||
count = communitiesArray.count;
|
||||
}
|
||||
else if (section == SETTINGS_SECTION_DEVICES_INDEX)
|
||||
{
|
||||
count = devicesArray.count;
|
||||
@@ -1277,6 +1342,8 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
|
||||
cell.mxkLabel.textColor = kRiotPrimaryTextColor;
|
||||
|
||||
[cell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
// Force layout before reusing a cell (fix switch displayed outside the screen)
|
||||
[cell layoutIfNeeded];
|
||||
|
||||
@@ -1627,7 +1694,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_enable_push_notif", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = account.isPushKitNotificationActive;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(togglePushNotifications:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
@@ -1639,7 +1705,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_show_decrypted_content", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = account.showDecryptedContentInNotifications;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = account.isPushKitNotificationActive;
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleShowDecodedContent:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
@@ -1664,7 +1729,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_pin_rooms_with_missed_notif", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"pinRoomsWithMissedNotif"];
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(togglePinRoomsWithMissedNotif:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
@@ -1676,7 +1740,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_pin_rooms_with_unread", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"pinRoomsWithUnread"];
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(togglePinRoomsWithUnread:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
@@ -1690,7 +1753,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_enable_callkit", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = [MXKAppSettings standardAppSettings].isCallKitEnabled;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleCallKit:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
@@ -1794,7 +1856,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_contacts_discover_matrix_users", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = [MXKAppSettings standardAppSettings].syncLocalContacts;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleLocalContactsSync:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
@@ -1905,7 +1966,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
sendCrashReportCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_send_crash_report", @"Vector", nil);
|
||||
sendCrashReportCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableCrashReport"];
|
||||
sendCrashReportCell.mxkSwitch.enabled = YES;
|
||||
[sendCrashReportCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[sendCrashReportCell.mxkSwitch addTarget:self action:@selector(toggleSendCrashReport:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = sendCrashReportCell;
|
||||
@@ -1917,7 +1977,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
enableRageShakeCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_enable_rageshake", @"Vector", nil);
|
||||
enableRageShakeCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableRageShake"];
|
||||
enableRageShakeCell.mxkSwitch.enabled = YES;
|
||||
[enableRageShakeCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[enableRageShakeCell.mxkSwitch addTarget:self action:@selector(toggleEnableRageShake:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = enableRageShakeCell;
|
||||
@@ -2007,7 +2066,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_labs_matrix_apps", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"matrixApps"];
|
||||
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleLabsMatrixApps:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
@@ -2019,7 +2077,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_labs_create_conference_with_jitsi", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"createConferenceCallsWithJitsi"];
|
||||
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleJitsiForConference:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
@@ -2033,7 +2090,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_labs_e2e_encryption", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = (nil != session.crypto);
|
||||
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleLabsEndToEndEncryption:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
if (session.crypto)
|
||||
@@ -2045,6 +2101,23 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
cell = labelAndSwitchCell;
|
||||
}
|
||||
}
|
||||
else if (section == SETTINGS_SECTION_FLAIR_INDEX)
|
||||
{
|
||||
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
||||
|
||||
if (row < communitiesArray.count)
|
||||
{
|
||||
MXGroup *group = communitiesArray[row];
|
||||
labelAndSwitchCell.mxkLabel.text = (group.profile.name.length ? group.profile.name : group.groupId);
|
||||
labelAndSwitchCell.mxkSwitch.on = group.summary.user.isPublicised;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
labelAndSwitchCell.mxkSwitch.tag = row;
|
||||
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleCommunityFlair:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
}
|
||||
else if (section == SETTINGS_SECTION_DEVICES_INDEX)
|
||||
{
|
||||
MXKTableViewCell *deviceCell = [self getDefaultTableViewCell:tableView];
|
||||
@@ -2084,7 +2157,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_crypto_blacklist_unverified_devices", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = account.mxSession.crypto.globalBlacklistUnverifiedDevices;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleBlacklistUnverifiedDevices:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
@@ -2168,6 +2240,14 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
{
|
||||
return NSLocalizedStringFromTable(@"settings_labs", @"Vector", nil);
|
||||
}
|
||||
else if (section == SETTINGS_SECTION_FLAIR_INDEX)
|
||||
{
|
||||
// Check whether this section is visible
|
||||
if (communitiesArray.count > 0)
|
||||
{
|
||||
return NSLocalizedStringFromTable(@"settings_flair", @"Vector", nil);
|
||||
}
|
||||
}
|
||||
else if (section == SETTINGS_SECTION_DEVICES_INDEX)
|
||||
{
|
||||
// Check whether this section is visible
|
||||
@@ -2968,6 +3048,42 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
||||
- (void)toggleCommunityFlair:(id)sender
|
||||
{
|
||||
UISwitch *switchButton = (UISwitch*)sender;
|
||||
|
||||
if (switchButton.tag < communitiesArray.count)
|
||||
{
|
||||
MXGroup *group = communitiesArray[switchButton.tag];
|
||||
[self startActivityIndicator];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
[self.mainSession updateGroupPublicity:group isPublicised:switchButton.on success:^{
|
||||
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
[self stopActivityIndicator];
|
||||
}
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
[self stopActivityIndicator];
|
||||
|
||||
// Come back to previous state button
|
||||
[switchButton setOn:!switchButton.isOn animated:YES];
|
||||
|
||||
// Notify user
|
||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)markAllAsRead:(id)sender
|
||||
{
|
||||
// Feedback: disable button and run activity indicator
|
||||
|
||||
Reference in New Issue
Block a user