Remove flairs and related groups.

This commit is contained in:
Doug
2022-08-05 15:09:56 +01:00
committed by Doug
parent 85db4e22a0
commit 57f92307f2
21 changed files with 5 additions and 723 deletions
@@ -41,7 +41,6 @@ enum
SECTION_TAG_PROMOTION,
SECTION_TAG_HISTORY,
SECTION_TAG_ADDRESSES,
SECTION_TAG_FLAIR,
SECTION_TAG_BANNED_USERS,
SECTION_TAG_BANNED_ADVANCED
};
@@ -77,12 +76,6 @@ enum
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_JOINED
};
enum
{
ROOM_SETTINGS_RELATED_GROUPS_NEW_GROUP,
ROOM_SETTINGS_RELATED_GROUPS_OFFSET = 1000
};
enum
{
ROOM_SETTINGS_ADVANCED_ROOM_ID,
@@ -115,8 +108,6 @@ NSString *const kRoomSettingsHistoryVisibilityKey = @"kRoomSettingsHistoryVisibi
NSString *const kRoomSettingsNewAliasesKey = @"kRoomSettingsNewAliasesKey";
NSString *const kRoomSettingsRemovedAliasesKey = @"kRoomSettingsRemovedAliasesKey";
NSString *const kRoomSettingsCanonicalAliasKey = @"kRoomSettingsCanonicalAliasKey";
NSString *const kRoomSettingsNewRelatedGroupKey = @"kRoomSettingsNewRelatedGroupKey";
NSString *const kRoomSettingsRemovedRelatedGroupKey = @"kRoomSettingsRemovedRelatedGroupKey";
NSString *const kRoomSettingsEncryptionKey = @"kRoomSettingsEncryptionKey";
NSString *const kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey = @"kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey";
@@ -124,7 +115,6 @@ NSString *const kRoomSettingsNameCellViewIdentifier = @"kRoomSettingsNameCellVie
NSString *const kRoomSettingsTopicCellViewIdentifier = @"kRoomSettingsTopicCellViewIdentifier";
NSString *const kRoomSettingsWarningCellViewIdentifier = @"kRoomSettingsWarningCellViewIdentifier";
NSString *const kRoomSettingsNewAddressCellViewIdentifier = @"kRoomSettingsNewAddressCellViewIdentifier";
NSString *const kRoomSettingsNewCommunityCellViewIdentifier = @"kRoomSettingsNewCommunityCellViewIdentifier";
NSString *const kRoomSettingsAddressCellViewIdentifier = @"kRoomSettingsAddressCellViewIdentifier";
NSString *const kRoomSettingsAdvancedCellViewIdentifier = @"kRoomSettingsAdvancedCellViewIdentifier";
NSString *const kRoomSettingsAdvancedEnableE2eCellViewIdentifier = @"kRoomSettingsAdvancedEnableE2eCellViewIdentifier";
@@ -156,10 +146,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
NSUInteger localAddressesCount;
UITextField* addAddressTextField;
// Related groups/communities
NSMutableArray<NSString *> *relatedGroups;
UITextField* addGroupTextField;
// The potential image loader
MXMediaLoader *uploader;
@@ -248,7 +234,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
historyVisibilityTickCells = [[NSMutableDictionary alloc] initWithCapacity:4];
roomAddresses = [NSMutableArray array];
relatedGroups = [NSMutableArray array];
[self.tableView registerClass:MXKTableViewCellWithLabelAndSwitch.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]];
[self.tableView registerClass:MXKTableViewCellWithLabelAndMXKImageView.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndMXKImageView defaultReuseIdentifier]];
@@ -258,7 +243,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:kRoomSettingsNameCellViewIdentifier];
[self.tableView registerClass:TableViewCellWithLabelAndLargeTextView.class forCellReuseIdentifier:kRoomSettingsTopicCellViewIdentifier];
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:kRoomSettingsNewAddressCellViewIdentifier];
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:kRoomSettingsNewCommunityCellViewIdentifier];
[self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kRoomSettingsAddressCellViewIdentifier];
[self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kRoomSettingsWarningCellViewIdentifier];
@@ -421,7 +405,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
historyVisibilityTickCells = nil;
roomAddresses = nil;
relatedGroups = nil;
if (extraEventsListener)
{
@@ -516,8 +499,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
localAddressesCount++;
}
[self refreshRelatedGroups];
// create sections
NSMutableArray<Section*> *tmpSections = [NSMutableArray arrayWithCapacity:SECTION_TAG_BANNED_ADVANCED + 1];
@@ -606,34 +587,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
[tmpSections addObject:sectionAddresses];
}
if (RiotSettings.shared.roomSettingsScreenShowFlairSettings)
{
Section *sectionFlair = [Section sectionWithTag:SECTION_TAG_FLAIR];
for (NSInteger counter = 0; counter < relatedGroups.count; counter++)
{
[sectionFlair addRowWithTag:counter + ROOM_SETTINGS_RELATED_GROUPS_OFFSET];
}
if (self.mainSession)
{
// Check user's power level to know whether the user is allowed to add communities to this room
MXRoomPowerLevels *powerLevels = [mxRoomState powerLevels];
NSInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId];
if (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomRelatedGroups])
{
[sectionFlair addRowWithTag:ROOM_SETTINGS_RELATED_GROUPS_NEW_GROUP];
}
}
sectionFlair.headerTitle = [VectorL10n roomDetailsFlairSection];
if ([sectionFlair hasAnyRows])
{
[tmpSections addObject:sectionFlair];
}
}
if (bannedMembers.count)
{
Section *sectionBannedUsers = [Section sectionWithTag:SECTION_TAG_BANNED_USERS];
@@ -1156,36 +1109,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
}];
}
- (void)refreshRelatedGroups
{
// Refresh here the related communities list.
[relatedGroups removeAllObjects];
[relatedGroups addObjectsFromArray:mxRoomState.relatedGroups];
NSArray *removedCommunities = updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey];
if (removedCommunities.count)
{
for (NSUInteger index = 0; index < relatedGroups.count;)
{
NSString *groupId = relatedGroups[index];
// Check whether the user did not remove it
if ([removedCommunities indexOfObject:groupId] != NSNotFound)
{
[relatedGroups removeObjectAtIndex:index];
}
else
{
index++;
}
}
}
NSArray *communities = updatedItemsDict[kRoomSettingsNewRelatedGroupKey];
if (communities)
{
[relatedGroups addObjectsFromArray:communities];
}
}
#pragma mark - UITextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView;
@@ -1347,18 +1270,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
addAddressTextField.text = nil;
}
}
else if (textField == addGroupTextField)
{
// Dismiss the keyboard
[addGroupTextField resignFirstResponder];
NSString *groupId = addGroupTextField.text;
if (!groupId.length || [self addCommunity:groupId])
{
// Reset the input field
addGroupTextField.text = nil;
}
}
return YES;
}
@@ -1920,52 +1831,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
return;
}
// Related groups
if (updatedItemsDict[kRoomSettingsNewRelatedGroupKey] || updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey])
{
[self refreshRelatedGroups];
pendingOperation = [mxRoom setRelatedGroups:relatedGroups success:^{
if (weakSelf)
{
typeof(self) self = weakSelf;
self->pendingOperation = nil;
[self->updatedItemsDict removeObjectForKey:kRoomSettingsNewRelatedGroupKey];
[self->updatedItemsDict removeObjectForKey:kRoomSettingsRemovedRelatedGroupKey];
[self onSave:nil];
}
} failure:^(NSError *error) {
MXLogDebug(@"[RoomSettingsViewController] Update room communities failed");
if (weakSelf)
{
typeof(self) self = weakSelf;
self->pendingOperation = nil;
dispatch_async(dispatch_get_main_queue(), ^{
NSString* message = error.localizedDescription;
if (!message.length)
{
message = [VectorL10n roomDetailsFailToUpdateRoomCommunities];
}
[self onSaveFailed:message withKeys:@[kRoomSettingsNewRelatedGroupKey,kRoomSettingsRemovedRelatedGroupKey]];
});
}
}];
return;
}
}
// Update here other room settings
@@ -2793,64 +2658,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
cell = addressCell;
}
}
else if (section == SECTION_TAG_FLAIR)
{
if (row == ROOM_SETTINGS_RELATED_GROUPS_NEW_GROUP)
{
MXKTableViewCellWithLabelAndTextField *addCommunityCell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsNewCommunityCellViewIdentifier forIndexPath:indexPath];
// Retrieve the current edited value if any
NSString *currentValue = (addGroupTextField ? addGroupTextField.text : nil);
addCommunityCell.mxkLabelLeadingConstraint.constant = 0;
addCommunityCell.mxkTextFieldLeadingConstraint.constant = tableView.vc_separatorInset.left;
addCommunityCell.mxkTextFieldTrailingConstraint.constant = 15;
addCommunityCell.mxkLabel.text = nil;
addCommunityCell.accessoryType = UITableViewCellAccessoryNone;
addCommunityCell.accessoryView = [[UIImageView alloc] initWithImage:[AssetImages.plusIcon.image vc_tintedImageUsingColor:ThemeService.shared.theme.textPrimaryColor]];
addGroupTextField = addCommunityCell.mxkTextField;
addGroupTextField.placeholder = [VectorL10n roomDetailsNewFlairPlaceholder:self.mainSession.matrixRestClient.homeserverSuffix];
addGroupTextField.attributedPlaceholder = [[NSAttributedString alloc]
initWithString:addGroupTextField.placeholder
attributes:@{NSForegroundColorAttributeName: ThemeService.shared.theme.placeholderTextColor}];
addGroupTextField.userInteractionEnabled = YES;
addGroupTextField.text = currentValue;
addGroupTextField.textColor = ThemeService.shared.theme.textSecondaryColor;
addGroupTextField.tintColor = ThemeService.shared.theme.tintColor;
addGroupTextField.font = [UIFont systemFontOfSize:17];
addGroupTextField.borderStyle = UITextBorderStyleNone;
addGroupTextField.textAlignment = NSTextAlignmentLeft;
addGroupTextField.autocorrectionType = UITextAutocorrectionTypeNo;
addGroupTextField.spellCheckingType = UITextSpellCheckingTypeNo;
addGroupTextField.delegate = self;
cell = addCommunityCell;
}
else if (row >= ROOM_SETTINGS_RELATED_GROUPS_OFFSET)
{
UITableViewCell *communityCell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAddressCellViewIdentifier forIndexPath:indexPath];
communityCell.textLabel.font = [UIFont systemFontOfSize:16];
communityCell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
communityCell.textLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
communityCell.accessoryView = nil;
communityCell.accessoryType = UITableViewCellAccessoryNone;
communityCell.selectionStyle = UITableViewCellSelectionStyleNone;
NSInteger index = row - ROOM_SETTINGS_RELATED_GROUPS_OFFSET;
if (index < relatedGroups.count)
{
communityCell.textLabel.text = relatedGroups[index];
}
cell = communityCell;
}
}
else if (section == SECTION_TAG_BANNED_USERS)
{
UITableViewCell *addressCell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAddressCellViewIdentifier forIndexPath:indexPath];
@@ -3171,18 +2978,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
});
}
}
else if (section == SECTION_TAG_FLAIR)
{
if (row == ROOM_SETTINGS_RELATED_GROUPS_NEW_GROUP)
{
NSString *groupId = addGroupTextField.text;
if (!groupId.length || [self addCommunity:groupId])
{
// Reset the input field
addGroupTextField.text = nil;
}
}
}
else if (section == SECTION_TAG_BANNED_USERS)
{
// Show the RoomMemberDetailsViewController on this member so that
@@ -3240,27 +3035,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
swipeActionConfiguration.performsFirstActionWithFullSwipe = NO;
return swipeActionConfiguration;
}
else if (section == SECTION_TAG_FLAIR && row >= ROOM_SETTINGS_RELATED_GROUPS_OFFSET)
{
UIContextualAction *removeAddressAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:@" "
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
[self removeCommunityAtIndexPath:indexPath];
completionHandler(YES);
}];
removeAddressAction.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
removeAddressAction.image = [AssetImages.removeIcon.image vc_notRenderedImage];
// Create swipe action configuration
NSArray<UIContextualAction*> *actions = @[
removeAddressAction
];
UISwipeActionsConfiguration *swipeActionConfiguration = [UISwipeActionsConfiguration configurationWithActions:actions];
swipeActionConfiguration.performsFirstActionWithFullSwipe = NO;
return swipeActionConfiguration;
}
return nil;
}
@@ -3693,20 +3467,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
}
}
- (void)removeCommunityAtIndexPath:(NSIndexPath *)indexPath
{
indexPath = [_tableViewSections tagsIndexPathFromTableViewIndexPath:indexPath];
NSInteger row = indexPath.row;
NSInteger index = row - ROOM_SETTINGS_RELATED_GROUPS_OFFSET;
if (index < relatedGroups.count)
{
NSString *groupId = relatedGroups[index];
[self removeCommunity:groupId];
}
}
- (void)removeRoomAlias:(NSString*)roomAlias
{
NSString *canonicalAlias;
@@ -3762,36 +3522,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
}
}
- (void)removeCommunity:(NSString*)groupId
{
// Check whether the alias has just been added
NSMutableArray<NSString *> *addedGroup = updatedItemsDict[kRoomSettingsNewRelatedGroupKey];
if (addedGroup && [addedGroup indexOfObject:groupId] != NSNotFound)
{
[addedGroup removeObject:groupId];
if (!addedGroup.count)
{
[updatedItemsDict removeObjectForKey:kRoomSettingsNewRelatedGroupKey];
}
}
else
{
NSMutableArray<NSString *> *removedGroup = updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey];
if (!removedGroup)
{
removedGroup = [NSMutableArray array];
updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey] = removedGroup;
}
[removedGroup addObject:groupId];
}
[self updateSections];
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
}
- (BOOL)addRoomAlias:(NSString*)roomAlias
{
// Check whether the provided alias is valid
@@ -3873,71 +3603,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
return NO;
}
- (BOOL)addCommunity:(NSString*)groupId
{
// Check whether the provided id is valid
if ([MXTools isMatrixGroupIdentifier:groupId])
{
// Check whether this group has just been deleted
NSMutableArray<NSString *> *removedGroups = updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey];
if (removedGroups && [removedGroups indexOfObject:groupId] != NSNotFound)
{
[removedGroups removeObject:groupId];
if (!removedGroups.count)
{
[updatedItemsDict removeObjectForKey:kRoomSettingsRemovedRelatedGroupKey];
}
}
// Check whether this alias is not already defined for this room
else if ([relatedGroups indexOfObject:groupId] == NSNotFound)
{
NSMutableArray<NSString *> *addedGroup = updatedItemsDict[kRoomSettingsNewRelatedGroupKey];
if (!addedGroup)
{
addedGroup = [NSMutableArray array];
updatedItemsDict[kRoomSettingsNewRelatedGroupKey] = addedGroup;
}
[addedGroup addObject:groupId];
}
[self updateSections];
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
return YES;
}
// Prompt here user for invalid id
__weak typeof(self) weakSelf = self;
[currentAlert dismissViewControllerAnimated:NO completion:nil];
NSString *alertMsg = [VectorL10n roomDetailsFlairInvalidIdPromptMsg:groupId];
currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomDetailsFlairInvalidIdPromptTitle]
message:alertMsg
preferredStyle:UIAlertControllerStyleAlert];
[currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n ok]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
}
}]];
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCAddCommunityAlert"];
[self presentViewController:currentAlert animated:YES completion:nil];
return NO;
}
#pragma mark - TableViewCellWithCheckBoxesDelegate
- (void)tableViewCellWithCheckBoxes:(TableViewCellWithCheckBoxes *)tableViewCellWithCheckBoxes didTapOnCheckBoxAtIndex:(NSUInteger)index