2015-11-20 13:12:37 +00:00
|
|
|
/*
|
2016-06-23 16:51:44 +00:00
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-03-03 13:08:47 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-11-26 15:47:24 +00:00
|
|
|
#import "RoomSettingsViewController.h"
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
#import "TableViewCellWithLabelAndLargeTextView.h"
|
2016-07-05 15:26:55 +00:00
|
|
|
#import "TableViewCellWithCheckBoxAndLabel.h"
|
2015-12-15 09:46:34 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
#import "SegmentedViewController.h"
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2015-12-15 09:46:34 +00:00
|
|
|
#import "AvatarGenerator.h"
|
2016-07-12 12:41:16 +00:00
|
|
|
#import "Tools.h"
|
2015-12-15 09:46:34 +00:00
|
|
|
|
2017-03-09 10:50:12 +00:00
|
|
|
#import "MXRoom+Riot.h"
|
2017-09-14 14:00:50 +00:00
|
|
|
#import "MXRoomSummary+Riot.h"
|
2015-12-15 17:17:20 +00:00
|
|
|
|
2016-05-19 15:22:29 +00:00
|
|
|
#import "AppDelegate.h"
|
2018-11-30 16:10:28 +00:00
|
|
|
#import "Riot-Swift.h"
|
2016-05-19 15:22:29 +00:00
|
|
|
|
2016-08-02 09:57:02 +00:00
|
|
|
#import "RoomMemberDetailsViewController.h"
|
|
|
|
|
2017-02-28 09:24:27 +00:00
|
|
|
#import <MobileCoreServices/MobileCoreServices.h>
|
|
|
|
|
2018-01-22 14:43:16 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ROOM_SETTINGS_MAIN_SECTION_INDEX = 0,
|
|
|
|
ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX,
|
|
|
|
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_INDEX,
|
|
|
|
ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX,
|
|
|
|
ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX,
|
|
|
|
ROOM_SETTINGS_BANNED_USERS_SECTION_INDEX,
|
|
|
|
ROOM_SETTINGS_ADVANCED_SECTION_INDEX,
|
|
|
|
ROOM_SETTINGS_SECTION_COUNT
|
|
|
|
};
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2018-01-22 14:43:16 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ROOM_SETTINGS_MAIN_SECTION_ROW_PHOTO = 0,
|
|
|
|
ROOM_SETTINGS_MAIN_SECTION_ROW_NAME,
|
|
|
|
ROOM_SETTINGS_MAIN_SECTION_ROW_TOPIC,
|
|
|
|
ROOM_SETTINGS_MAIN_SECTION_ROW_TAG ,
|
|
|
|
ROOM_SETTINGS_MAIN_SECTION_ROW_DIRECT_CHAT,
|
|
|
|
ROOM_SETTINGS_MAIN_SECTION_ROW_MUTE_NOTIFICATIONS,
|
|
|
|
ROOM_SETTINGS_MAIN_SECTION_ROW_LEAVE,
|
|
|
|
ROOM_SETTINGS_MAIN_SECTION_ROW_COUNT
|
|
|
|
};
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2018-01-22 14:43:16 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_INVITED_ONLY = 0,
|
|
|
|
ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE_APART_FROM_GUEST,
|
|
|
|
ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE,
|
|
|
|
ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_SUB_COUNT
|
|
|
|
};
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2018-01-22 14:43:16 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_ANYONE = 0,
|
|
|
|
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY,
|
|
|
|
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_INVITED,
|
|
|
|
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_JOINED,
|
|
|
|
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_COUNT
|
|
|
|
};
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2016-04-19 13:28:15 +00:00
|
|
|
#define ROOM_TOPIC_CELL_HEIGHT 124
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2016-08-02 09:06:31 +00:00
|
|
|
#define SECTION_TITLE_PADDING_WHEN_HIDDEN 0.01f
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
NSString *const kRoomSettingsAvatarKey = @"kRoomSettingsAvatarKey";
|
|
|
|
NSString *const kRoomSettingsAvatarURLKey = @"kRoomSettingsAvatarURLKey";
|
|
|
|
NSString *const kRoomSettingsNameKey = @"kRoomSettingsNameKey";
|
|
|
|
NSString *const kRoomSettingsTopicKey = @"kRoomSettingsTopicKey";
|
2016-06-28 12:58:17 +00:00
|
|
|
NSString *const kRoomSettingsTagKey = @"kRoomSettingsTagKey";
|
2016-06-23 16:51:44 +00:00
|
|
|
NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
|
2017-09-20 13:08:25 +00:00
|
|
|
NSString *const kRoomSettingsDirectChatKey = @"kRoomSettingsDirectChatKey";
|
2016-06-30 11:30:53 +00:00
|
|
|
NSString *const kRoomSettingsJoinRuleKey = @"kRoomSettingsJoinRuleKey";
|
|
|
|
NSString *const kRoomSettingsGuestAccessKey = @"kRoomSettingsGuestAccessKey";
|
|
|
|
NSString *const kRoomSettingsDirectoryKey = @"kRoomSettingsDirectoryKey";
|
|
|
|
NSString *const kRoomSettingsHistoryVisibilityKey = @"kRoomSettingsHistoryVisibilityKey";
|
2016-07-08 13:07:05 +00:00
|
|
|
NSString *const kRoomSettingsNewAliasesKey = @"kRoomSettingsNewAliasesKey";
|
|
|
|
NSString *const kRoomSettingsRemovedAliasesKey = @"kRoomSettingsRemovedAliasesKey";
|
|
|
|
NSString *const kRoomSettingsCanonicalAliasKey = @"kRoomSettingsCanonicalAliasKey";
|
2018-01-19 16:08:44 +00:00
|
|
|
NSString *const kRoomSettingsNewRelatedGroupKey = @"kRoomSettingsNewRelatedGroupKey";
|
|
|
|
NSString *const kRoomSettingsRemovedRelatedGroupKey = @"kRoomSettingsRemovedRelatedGroupKey";
|
2016-11-03 10:57:08 +00:00
|
|
|
NSString *const kRoomSettingsEncryptionKey = @"kRoomSettingsEncryptionKey";
|
2017-03-03 12:07:18 +00:00
|
|
|
NSString *const kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey = @"kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey";
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-07-11 15:53:47 +00:00
|
|
|
NSString *const kRoomSettingsNameCellViewIdentifier = @"kRoomSettingsNameCellViewIdentifier";
|
|
|
|
NSString *const kRoomSettingsTopicCellViewIdentifier = @"kRoomSettingsTopicCellViewIdentifier";
|
2016-07-12 15:22:06 +00:00
|
|
|
NSString *const kRoomSettingsWarningCellViewIdentifier = @"kRoomSettingsWarningCellViewIdentifier";
|
2016-07-12 12:41:16 +00:00
|
|
|
NSString *const kRoomSettingsNewAddressCellViewIdentifier = @"kRoomSettingsNewAddressCellViewIdentifier";
|
2018-01-19 16:08:44 +00:00
|
|
|
NSString *const kRoomSettingsNewCommunityCellViewIdentifier = @"kRoomSettingsNewCommunityCellViewIdentifier";
|
2016-07-11 15:53:47 +00:00
|
|
|
NSString *const kRoomSettingsAddressCellViewIdentifier = @"kRoomSettingsAddressCellViewIdentifier";
|
2016-07-11 22:13:05 +00:00
|
|
|
NSString *const kRoomSettingsAdvancedCellViewIdentifier = @"kRoomSettingsAdvancedCellViewIdentifier";
|
2016-11-03 10:57:08 +00:00
|
|
|
NSString *const kRoomSettingsAdvancedEnableE2eCellViewIdentifier = @"kRoomSettingsAdvancedEnableE2eCellViewIdentifier";
|
|
|
|
NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSettingsAdvancedE2eEnabledCellViewIdentifier";
|
2016-07-11 15:53:47 +00:00
|
|
|
|
2015-11-26 15:47:24 +00:00
|
|
|
@interface RoomSettingsViewController ()
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-06-27 13:32:07 +00:00
|
|
|
// The updated user data
|
2015-11-27 13:02:37 +00:00
|
|
|
NSMutableDictionary<NSString*, id> *updatedItemsDict;
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2016-06-27 13:32:07 +00:00
|
|
|
// The current table items
|
2015-11-20 13:12:37 +00:00
|
|
|
UITextField* nameTextField;
|
2016-06-27 13:32:07 +00:00
|
|
|
UITextView* topicTextView;
|
2016-07-05 14:31:07 +00:00
|
|
|
|
|
|
|
// The room tag items
|
|
|
|
TableViewCellWithCheckBoxes *roomTagCell;
|
2015-11-20 16:07:45 +00:00
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
// Room Access items
|
2016-07-12 15:22:06 +00:00
|
|
|
NSInteger directoryVisibilityIndex;
|
|
|
|
NSInteger missingAddressWarningIndex;
|
2016-07-05 15:26:55 +00:00
|
|
|
TableViewCellWithCheckBoxAndLabel *accessInvitedOnlyTickCell;
|
|
|
|
TableViewCellWithCheckBoxAndLabel *accessAnyoneApartGuestTickCell;
|
|
|
|
TableViewCellWithCheckBoxAndLabel *accessAnyoneTickCell;
|
2016-06-30 11:30:53 +00:00
|
|
|
UISwitch *directoryVisibilitySwitch;
|
|
|
|
MXRoomDirectoryVisibility actualDirectoryVisibility;
|
2016-07-11 15:53:47 +00:00
|
|
|
MXHTTPOperation* actualDirectoryVisibilityRequest;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
// History Visibility items
|
2016-07-05 15:26:55 +00:00
|
|
|
NSMutableDictionary<MXRoomHistoryVisibility, TableViewCellWithCheckBoxAndLabel*> *historyVisibilityTickCells;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
// Room aliases
|
|
|
|
NSMutableArray<NSString *> *roomAddresses;
|
|
|
|
NSUInteger localAddressesCount;
|
2016-07-11 15:53:47 +00:00
|
|
|
NSInteger roomAddressNewAliasIndex;
|
|
|
|
UITextField* addAddressTextField;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2018-01-19 16:08:44 +00:00
|
|
|
// Related groups/communities
|
|
|
|
NSMutableArray<NSString *> *relatedGroups;
|
|
|
|
NSInteger relatedGroupsNewGroupIndex;
|
|
|
|
UITextField* addGroupTextField;
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
// The potential image loader
|
2016-12-01 13:55:29 +00:00
|
|
|
MXMediaLoader *uploader;
|
2016-06-23 16:51:44 +00:00
|
|
|
|
|
|
|
// The pending http operation
|
2015-11-20 16:07:45 +00:00
|
|
|
MXHTTPOperation* pendingOperation;
|
2015-11-27 14:16:16 +00:00
|
|
|
|
|
|
|
// the updating spinner
|
|
|
|
UIActivityIndicatorView* updatingSpinner;
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
UIAlertController *currentAlert;
|
2015-12-15 12:14:37 +00:00
|
|
|
|
2015-12-15 17:17:20 +00:00
|
|
|
// listen to more events than the mother class
|
|
|
|
id extraEventsListener;
|
|
|
|
|
2015-12-15 12:14:37 +00:00
|
|
|
// picker
|
|
|
|
MediaPickerViewController* mediaPicker;
|
2015-12-15 17:17:20 +00:00
|
|
|
|
2016-05-19 15:22:29 +00:00
|
|
|
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
|
2016-06-23 16:51:44 +00:00
|
|
|
id appDelegateDidTapStatusBarNotificationObserver;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-08-02 10:06:06 +00:00
|
|
|
// A copy of the banned members
|
|
|
|
NSArray<MXRoomMember*> *bannedMembers;
|
2017-07-21 09:28:17 +00:00
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
|
|
|
|
id kThemeServiceDidChangeThemeNotificationObserver;
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2015-11-26 15:47:24 +00:00
|
|
|
@implementation RoomSettingsViewController
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2016-08-22 09:54:26 +00:00
|
|
|
- (void)finalizeInit
|
|
|
|
{
|
|
|
|
[super finalizeInit];
|
|
|
|
|
|
|
|
_selectedRoomSettingsField = RoomSettingsViewControllerFieldNone;
|
2017-01-03 13:40:23 +00:00
|
|
|
|
|
|
|
// Setup `MXKViewControllerHandling` properties
|
|
|
|
self.enableBarTintColorStatusChange = NO;
|
|
|
|
self.rageShakeManager = [RageShakeManager sharedManager];
|
2016-08-22 09:54:26 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 09:22:58 +00:00
|
|
|
- (void)initWithSession:(MXSession *)session andRoomId:(NSString *)roomId
|
|
|
|
{
|
|
|
|
[super initWithSession:session andRoomId:roomId];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-08-02 09:22:58 +00:00
|
|
|
// Add an additional listener to update banned users
|
2018-07-23 16:14:45 +00:00
|
|
|
self->extraEventsListener = [mxRoom listenToEventsOfTypes:@[kMXEventTypeStringRoomMember] onEvent:^(MXEvent *event, MXTimelineDirection direction, MXRoomState *roomState) {
|
2018-07-19 07:47:34 +00:00
|
|
|
|
2018-07-23 16:14:45 +00:00
|
|
|
if (direction == MXTimelineDirectionForwards)
|
|
|
|
{
|
|
|
|
[self updateRoomState:roomState];
|
|
|
|
}
|
2016-08-02 09:22:58 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2016-08-02 10:06:06 +00:00
|
|
|
- (void)updateRoomState:(MXRoomState *)newRoomState
|
|
|
|
{
|
|
|
|
[super updateRoomState:newRoomState];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2018-07-11 21:52:46 +00:00
|
|
|
bannedMembers = [mxRoomState.members membersWithMembership:MXMembershipBan];
|
2016-08-02 10:06:06 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
- (UINavigationItem*)getNavigationItem
|
2015-11-26 17:23:50 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
// Check whether the view controller is currently displayed inside a segmented view controller or not.
|
|
|
|
UIViewController* topViewController = ((self.parentViewController) ? self.parentViewController : self);
|
2015-11-27 13:02:37 +00:00
|
|
|
|
|
|
|
return topViewController.navigationItem;
|
|
|
|
}
|
|
|
|
|
2015-12-02 07:32:39 +00:00
|
|
|
- (void)setNavBarButtons
|
2015-11-27 13:02:37 +00:00
|
|
|
{
|
|
|
|
[self getNavigationItem].rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(onSave:)];
|
2016-06-23 16:51:44 +00:00
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
2015-11-27 13:02:37 +00:00
|
|
|
[self getNavigationItem].leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancel:)];
|
2015-11-26 17:23:50 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
updatedItemsDict = [[NSMutableDictionary alloc] init];
|
2016-06-30 15:02:53 +00:00
|
|
|
historyVisibilityTickCells = [[NSMutableDictionary alloc] initWithCapacity:4];
|
2015-11-20 16:52:16 +00:00
|
|
|
|
2016-07-12 12:41:16 +00:00
|
|
|
roomAddresses = [NSMutableArray array];
|
2018-01-19 16:08:44 +00:00
|
|
|
relatedGroups = [NSMutableArray array];
|
2016-07-12 12:41:16 +00:00
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
[self.tableView registerClass:MXKTableViewCellWithLabelAndSwitch.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]];
|
|
|
|
[self.tableView registerClass:MXKTableViewCellWithLabelAndMXKImageView.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndMXKImageView defaultReuseIdentifier]];
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
// Use a specific cell identifier for the room name, the topic and the address in order to be able to keep reference
|
|
|
|
// on the text input field without being disturbed by the cell dequeuing process.
|
|
|
|
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:kRoomSettingsNameCellViewIdentifier];
|
|
|
|
[self.tableView registerClass:TableViewCellWithLabelAndLargeTextView.class forCellReuseIdentifier:kRoomSettingsTopicCellViewIdentifier];
|
2016-07-12 12:41:16 +00:00
|
|
|
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:kRoomSettingsNewAddressCellViewIdentifier];
|
2018-01-19 16:08:44 +00:00
|
|
|
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:kRoomSettingsNewCommunityCellViewIdentifier];
|
2016-07-12 12:41:16 +00:00
|
|
|
[self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kRoomSettingsAddressCellViewIdentifier];
|
2016-07-12 15:22:06 +00:00
|
|
|
[self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kRoomSettingsWarningCellViewIdentifier];
|
2016-07-11 15:53:47 +00:00
|
|
|
|
2016-07-05 15:57:33 +00:00
|
|
|
[self.tableView registerClass:MXKTableViewCellWithButton.class forCellReuseIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier]];
|
2016-07-05 14:31:07 +00:00
|
|
|
[self.tableView registerClass:TableViewCellWithCheckBoxes.class forCellReuseIdentifier:[TableViewCellWithCheckBoxes defaultReuseIdentifier]];
|
2016-07-05 15:26:55 +00:00
|
|
|
[self.tableView registerClass:TableViewCellWithCheckBoxAndLabel.class forCellReuseIdentifier:[TableViewCellWithCheckBoxAndLabel defaultReuseIdentifier]];
|
2016-07-08 13:07:05 +00:00
|
|
|
[self.tableView registerClass:MXKTableViewCell.class forCellReuseIdentifier:[MXKTableViewCell defaultReuseIdentifier]];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-07-25 14:11:26 +00:00
|
|
|
// Enable self sizing cells
|
|
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
|
|
self.tableView.estimatedRowHeight = 44;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2015-12-02 07:32:39 +00:00
|
|
|
[self setNavBarButtons];
|
2017-07-21 09:28:17 +00:00
|
|
|
|
|
|
|
// Observe user interface theme change.
|
2019-01-11 09:32:56 +00:00
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
2017-07-21 09:28:17 +00:00
|
|
|
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
|
|
|
|
}];
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)userInterfaceThemeDidChange
|
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
[ThemeService.shared.theme applyStyleOnNavigationBar:self.navigationController.navigationBar];
|
2018-11-29 16:31:41 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
self.activityIndicator.backgroundColor = ThemeService.shared.theme.overlayBackgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
|
|
// Check the table view style to select its bg color.
|
2019-01-11 10:45:27 +00:00
|
|
|
self.tableView.backgroundColor = ((self.tableView.style == UITableViewStylePlain) ? ThemeService.shared.theme.backgroundColor : ThemeService.shared.theme.headerBackgroundColor);
|
2017-08-11 14:56:09 +00:00
|
|
|
self.view.backgroundColor = self.tableView.backgroundColor;
|
|
|
|
|
|
|
|
if (self.tableView.dataSource)
|
|
|
|
{
|
|
|
|
[self.tableView reloadData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle
|
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
return ThemeService.shared.theme.statusBarStyle;
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 16:42:29 +00:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
2017-12-22 12:19:40 +00:00
|
|
|
|
|
|
|
// Screen tracking
|
2018-06-27 07:55:06 +00:00
|
|
|
[[Analytics sharedInstance] trackScreen:@"RoomSettings"];
|
2016-06-03 15:29:34 +00:00
|
|
|
|
2015-12-15 17:17:20 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdateRules:) name:kMXNotificationCenterDidUpdateRules object:nil];
|
2016-05-19 15:22:29 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
// Observe appDelegateDidTapStatusBarNotificationObserver.
|
|
|
|
appDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
2016-05-19 15:22:29 +00:00
|
|
|
|
2017-09-27 07:26:34 +00:00
|
|
|
[self.tableView setContentOffset:CGPointMake(-self.tableView.mxk_adjustedContentInset.left, -self.tableView.mxk_adjustedContentInset.top) animated:YES];
|
2016-05-19 15:22:29 +00:00
|
|
|
|
|
|
|
}];
|
2015-11-20 16:42:29 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 09:54:26 +00:00
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
|
|
|
// Edit the selected field if any
|
|
|
|
if (_selectedRoomSettingsField != RoomSettingsViewControllerFieldNone)
|
|
|
|
{
|
|
|
|
self.selectedRoomSettingsField = _selectedRoomSettingsField;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 14:20:15 +00:00
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
|
|
|
[self dismissFirstResponder];
|
2016-06-27 13:32:07 +00:00
|
|
|
|
2015-12-15 17:17:20 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXNotificationCenterDidUpdateRules object:nil];
|
2016-05-19 15:22:29 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
if (appDelegateDidTapStatusBarNotificationObserver)
|
2016-05-19 15:22:29 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:appDelegateDidTapStatusBarNotificationObserver];
|
|
|
|
appDelegateDidTapStatusBarNotificationObserver = nil;
|
2016-05-19 15:22:29 +00:00
|
|
|
}
|
2015-11-20 14:20:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 13:48:16 +00:00
|
|
|
// Those methods are called when the viewcontroller is added or removed from a container view controller.
|
|
|
|
- (void)willMoveToParentViewController:(nullable UIViewController *)parent
|
|
|
|
{
|
2016-06-27 13:32:07 +00:00
|
|
|
// Check whether the view is removed from its parent.
|
|
|
|
if (!parent)
|
2016-06-24 13:48:16 +00:00
|
|
|
{
|
2016-06-27 13:32:07 +00:00
|
|
|
[self dismissFirstResponder];
|
|
|
|
|
|
|
|
// Prompt user to save changes (if any).
|
|
|
|
if (updatedItemsDict.count)
|
|
|
|
{
|
|
|
|
[self promptUserToSaveChanges];
|
|
|
|
}
|
2016-06-24 13:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[super willMoveToParentViewController:parent];
|
|
|
|
}
|
2015-11-27 08:59:51 +00:00
|
|
|
- (void)didMoveToParentViewController:(nullable UIViewController *)parent
|
|
|
|
{
|
|
|
|
[super didMoveToParentViewController:parent];
|
2016-06-24 13:48:16 +00:00
|
|
|
|
2015-12-02 07:32:39 +00:00
|
|
|
[self setNavBarButtons];
|
2015-11-27 08:59:51 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 16:07:45 +00:00
|
|
|
- (void)destroy
|
|
|
|
{
|
|
|
|
self.navigationItem.rightBarButtonItem.enabled = NO;
|
|
|
|
|
2016-07-11 22:13:05 +00:00
|
|
|
if (currentAlert)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2016-07-11 22:13:05 +00:00
|
|
|
currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
if (uploader)
|
|
|
|
{
|
|
|
|
[uploader cancel];
|
|
|
|
uploader = nil;
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:07:45 +00:00
|
|
|
if (pendingOperation)
|
|
|
|
{
|
|
|
|
[pendingOperation cancel];
|
|
|
|
pendingOperation = nil;
|
|
|
|
}
|
|
|
|
|
2016-07-11 15:53:47 +00:00
|
|
|
if (actualDirectoryVisibilityRequest)
|
|
|
|
{
|
|
|
|
[actualDirectoryVisibilityRequest cancel];
|
|
|
|
actualDirectoryVisibilityRequest = nil;
|
|
|
|
}
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
if (kThemeServiceDidChangeThemeNotificationObserver)
|
2017-07-21 09:28:17 +00:00
|
|
|
{
|
2019-01-11 09:32:56 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kThemeServiceDidChangeThemeNotificationObserver];
|
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = nil;
|
2017-07-21 09:28:17 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
if (appDelegateDidTapStatusBarNotificationObserver)
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:appDelegateDidTapStatusBarNotificationObserver];
|
|
|
|
appDelegateDidTapStatusBarNotificationObserver = nil;
|
|
|
|
}
|
|
|
|
|
2016-06-30 15:02:53 +00:00
|
|
|
updatedItemsDict = nil;
|
|
|
|
historyVisibilityTickCells = nil;
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
roomAddresses = nil;
|
2018-01-19 16:08:44 +00:00
|
|
|
relatedGroups = nil;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-08-02 09:22:58 +00:00
|
|
|
if (extraEventsListener)
|
|
|
|
{
|
2018-07-19 07:47:34 +00:00
|
|
|
MXWeakify(self);
|
|
|
|
[mxRoom liveTimeline:^(MXEventTimeline *liveTimeline) {
|
|
|
|
MXStrongifyAndReturnIfNil(self);
|
|
|
|
|
|
|
|
[liveTimeline removeListener:self->extraEventsListener];
|
|
|
|
self->extraEventsListener = nil;
|
|
|
|
}];
|
2016-08-02 09:22:58 +00:00
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2015-11-20 16:07:45 +00:00
|
|
|
[super destroy];
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
- (void)withdrawViewControllerAnimated:(BOOL)animated completion:(void (^)(void))completion
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
// Check whether the current view controller is displayed inside a segmented view controller in order to withdraw the right item
|
|
|
|
if (self.parentViewController && [self.parentViewController isKindOfClass:SegmentedViewController.class])
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
[((SegmentedViewController*)self.parentViewController) withdrawViewControllerAnimated:animated completion:completion];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[super withdrawViewControllerAnimated:animated completion:completion];
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-20 14:20:15 +00:00
|
|
|
|
2016-06-27 13:32:07 +00:00
|
|
|
- (void)refreshRoomSettings
|
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
[self retrieveActualDirectoryVisibility];
|
|
|
|
|
2016-06-27 13:32:07 +00:00
|
|
|
// Check whether a text input is currently edited
|
|
|
|
BOOL isNameEdited = nameTextField ? nameTextField.isFirstResponder : NO;
|
|
|
|
BOOL isTopicEdited = topicTextView ? topicTextView.isFirstResponder : NO;
|
2016-07-11 15:53:47 +00:00
|
|
|
BOOL isAddressEdited = addAddressTextField ? addAddressTextField.isFirstResponder : NO;
|
2016-06-27 13:32:07 +00:00
|
|
|
|
|
|
|
// Trigger a full table reloadData
|
|
|
|
[super refreshRoomSettings];
|
|
|
|
|
|
|
|
// Restore the previous edited field
|
|
|
|
if (isNameEdited)
|
|
|
|
{
|
|
|
|
[self editRoomName];
|
|
|
|
}
|
|
|
|
else if (isTopicEdited)
|
|
|
|
{
|
|
|
|
[self editRoomTopic];
|
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
else if (isAddressEdited)
|
|
|
|
{
|
|
|
|
[self editAddRoomAddress];
|
|
|
|
}
|
2016-06-27 13:32:07 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
#pragma mark -
|
2016-08-22 09:54:26 +00:00
|
|
|
|
|
|
|
- (void)setSelectedRoomSettingsField:(RoomSettingsViewControllerField)selectedRoomSettingsField
|
|
|
|
{
|
|
|
|
// Check whether the view controller is already embedded inside a navigation controller
|
|
|
|
if (self.navigationController)
|
|
|
|
{
|
|
|
|
[self dismissFirstResponder];
|
|
|
|
|
2017-03-20 19:15:39 +00:00
|
|
|
// Check whether user allowed to change room info
|
|
|
|
NSDictionary *eventTypes = @{
|
|
|
|
@(RoomSettingsViewControllerFieldName): kMXEventTypeStringRoomName,
|
|
|
|
@(RoomSettingsViewControllerFieldTopic): kMXEventTypeStringRoomTopic,
|
|
|
|
@(RoomSettingsViewControllerFieldAvatar): kMXEventTypeStringRoomAvatar
|
|
|
|
};
|
|
|
|
|
|
|
|
NSString *eventTypeForSelectedField = eventTypes[@(selectedRoomSettingsField)];
|
|
|
|
|
2017-03-22 19:07:06 +00:00
|
|
|
if (!eventTypeForSelectedField)
|
|
|
|
return;
|
|
|
|
|
2018-07-20 08:34:54 +00:00
|
|
|
MXRoomPowerLevels *powerLevels = [mxRoomState powerLevels];
|
2017-03-20 19:15:39 +00:00
|
|
|
NSInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId];
|
|
|
|
|
|
|
|
if (oneSelfPowerLevel < [powerLevels minimumPowerLevelForSendingEventAsStateEvent:eventTypeForSelectedField])
|
|
|
|
return;
|
|
|
|
|
2016-08-22 09:54:26 +00:00
|
|
|
switch (selectedRoomSettingsField)
|
|
|
|
{
|
|
|
|
case RoomSettingsViewControllerFieldName:
|
|
|
|
{
|
|
|
|
[self editRoomName];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RoomSettingsViewControllerFieldTopic:
|
|
|
|
{
|
|
|
|
[self editRoomTopic];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RoomSettingsViewControllerFieldAvatar:
|
|
|
|
{
|
|
|
|
[self onRoomAvatarTap:nil];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This selection will be applied when the view controller will become active (see 'viewDidAppear')
|
|
|
|
_selectedRoomSettingsField = selectedRoomSettingsField;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
#pragma mark - private
|
|
|
|
|
2016-06-27 13:32:07 +00:00
|
|
|
- (void)editRoomName
|
|
|
|
{
|
|
|
|
if (![nameTextField becomeFirstResponder])
|
|
|
|
{
|
|
|
|
// Retry asynchronously
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[self editRoomName];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)editRoomTopic
|
|
|
|
{
|
|
|
|
if (![topicTextView becomeFirstResponder])
|
|
|
|
{
|
|
|
|
// Retry asynchronously
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[self editRoomTopic];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 15:53:47 +00:00
|
|
|
- (void)editAddRoomAddress
|
|
|
|
{
|
|
|
|
if (![addAddressTextField becomeFirstResponder])
|
|
|
|
{
|
|
|
|
// Retry asynchronously
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[self editAddRoomAddress];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 14:20:15 +00:00
|
|
|
- (void)dismissFirstResponder
|
|
|
|
{
|
|
|
|
if ([topicTextView isFirstResponder])
|
|
|
|
{
|
|
|
|
[topicTextView resignFirstResponder];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([nameTextField isFirstResponder])
|
|
|
|
{
|
|
|
|
[nameTextField resignFirstResponder];
|
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
if ([addAddressTextField isFirstResponder])
|
|
|
|
{
|
|
|
|
[addAddressTextField resignFirstResponder];
|
|
|
|
}
|
2016-08-22 09:54:26 +00:00
|
|
|
|
|
|
|
_selectedRoomSettingsField = RoomSettingsViewControllerFieldNone;
|
2015-11-20 14:20:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
- (void)startActivityIndicator
|
2015-11-20 16:07:45 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
// Lock user interaction
|
|
|
|
self.tableView.userInteractionEnabled = NO;
|
|
|
|
|
2016-06-27 13:32:07 +00:00
|
|
|
// Check whether the current view controller is displayed inside a segmented view controller in order to run the right activity view
|
|
|
|
if (self.parentViewController && [self.parentViewController isKindOfClass:SegmentedViewController.class])
|
|
|
|
{
|
|
|
|
[((SegmentedViewController*)self.parentViewController) startActivityIndicator];
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
// Force stop the activity view of the view controller
|
|
|
|
[self.activityIndicator stopAnimating];
|
2016-06-27 13:32:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[super startActivityIndicator];
|
|
|
|
}
|
2015-11-20 16:07:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
- (void)stopActivityIndicator
|
2015-11-20 16:07:45 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
// Check local conditions before stop the activity indicator
|
|
|
|
if (!pendingOperation && !uploader)
|
2015-11-27 14:16:16 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
// Unlock user interaction
|
|
|
|
self.tableView.userInteractionEnabled = YES;
|
|
|
|
|
2016-06-27 13:32:07 +00:00
|
|
|
// Check whether the current view controller is displayed inside a segmented view controller in order to stop the right activity view
|
|
|
|
if (self.parentViewController && [self.parentViewController isKindOfClass:SegmentedViewController.class])
|
|
|
|
{
|
|
|
|
[((SegmentedViewController*)self.parentViewController) stopActivityIndicator];
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
// Force stop the activity view of the view controller
|
|
|
|
[self.activityIndicator stopAnimating];
|
2016-06-27 13:32:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[super stopActivityIndicator];
|
|
|
|
}
|
2015-11-27 14:16:16 +00:00
|
|
|
}
|
2015-11-20 16:07:45 +00:00
|
|
|
}
|
2015-11-20 14:20:15 +00:00
|
|
|
|
2016-06-24 13:48:16 +00:00
|
|
|
- (void)promptUserToSaveChanges
|
|
|
|
{
|
|
|
|
// ensure that the user understands that the updates will be lost if
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2016-06-24 13:48:16 +00:00
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:nil message:NSLocalizedStringFromTable(@"room_details_save_changes_prompt", @"Vector", nil) preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"]
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[self->updatedItemsDict removeAllObjects];
|
|
|
|
|
|
|
|
[self withdrawViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"]
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[self onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCSaveChangesAlert"];
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
2016-06-24 13:48:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 22:13:05 +00:00
|
|
|
- (void)promptUserToCopyRoomId:(UILabel*)roomIdLabel
|
|
|
|
{
|
|
|
|
if (roomIdLabel)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2016-07-11 22:13:05 +00:00
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_details_copy_room_id", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[[UIPasteboard generalPasteboard] setString:roomIdLabel.text];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
2018-01-19 02:43:28 +00:00
|
|
|
style:UIAlertActionStyleCancel
|
2017-07-14 14:41:25 +00:00
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCCopyRoomIdAlert"];
|
|
|
|
[currentAlert popoverPresentationController].sourceView = roomIdLabel;
|
|
|
|
[currentAlert popoverPresentationController].sourceRect = roomIdLabel.bounds;
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
2016-07-11 22:13:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 12:41:16 +00:00
|
|
|
- (void)promptUserOnSelectedRoomAlias:(UILabel*)roomAliasLabel
|
|
|
|
{
|
|
|
|
if (roomAliasLabel)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2016-07-12 12:41:16 +00:00
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
2016-07-12 12:41:16 +00:00
|
|
|
|
2016-08-26 11:15:12 +00:00
|
|
|
// Check whether the user is allowed to modify the main address.
|
2018-09-21 14:23:32 +00:00
|
|
|
if ([self canSetCanonicalAlias])
|
2016-08-26 11:15:12 +00:00
|
|
|
{
|
|
|
|
// Compare the selected alias with the current main address
|
|
|
|
NSString *currentCanonicalAlias = mxRoomState.canonicalAlias;
|
|
|
|
NSString *canonicalAlias;
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsCanonicalAliasKey])
|
2016-08-26 11:15:12 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
canonicalAlias = updatedItemsDict[kRoomSettingsCanonicalAliasKey];
|
2016-08-26 11:15:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
canonicalAlias = currentCanonicalAlias;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canonicalAlias && [roomAliasLabel.text isEqualToString:canonicalAlias])
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_details_unset_main_address", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
// Prompt user before removing the current main address (use dispatch_async here to not be stuck by the table refresh).
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[self shouldRemoveCanonicalAlias:nil];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
2016-08-26 11:15:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Invite user to define this alias as the main room address
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_details_set_main_address", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[self setRoomAliasAsMainAddress:roomAliasLabel.text];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_details_copy_room_address", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[[UIPasteboard generalPasteboard] setString:roomAliasLabel.text];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_details_copy_room_url", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
// Create a matrix.to permalink to the room
|
|
|
|
[[UIPasteboard generalPasteboard] setString:[MXTools permalinkToRoom:roomAliasLabel.text]];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
2016-07-12 12:41:16 +00:00
|
|
|
|
2018-09-21 14:23:32 +00:00
|
|
|
// The user can only delete alias they has created, even if the Admin has set it as canonical.
|
|
|
|
// So, let the server answer if it's possible to delete an alias.
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"delete"]
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[self removeRoomAlias:roomAliasLabel.text];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
2018-01-19 02:43:28 +00:00
|
|
|
style:UIAlertActionStyleCancel
|
2017-07-14 14:41:25 +00:00
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCOnSelectedAliasAlert"];
|
|
|
|
[currentAlert popoverPresentationController].sourceView = roomAliasLabel;
|
|
|
|
[currentAlert popoverPresentationController].sourceRect = roomAliasLabel.bounds;
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
2016-07-12 12:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 15:53:47 +00:00
|
|
|
- (void)retrieveActualDirectoryVisibility
|
|
|
|
{
|
|
|
|
if (!mxRoom || actualDirectoryVisibilityRequest)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trigger a new request to check the actual directory visibility
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
|
|
|
actualDirectoryVisibilityRequest = [mxRoom directoryVisibility:^(MXRoomDirectoryVisibility directoryVisibility) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->actualDirectoryVisibilityRequest = nil;
|
2016-07-11 15:53:47 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->actualDirectoryVisibility = directoryVisibility;
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
// Update the value of the displayed toggle button (if any)
|
|
|
|
if (directoryVisibilitySwitch)
|
|
|
|
{
|
|
|
|
// Check a potential user's change before the end of the request
|
2019-01-07 23:24:11 +00:00
|
|
|
MXRoomDirectoryVisibility modifiedDirectoryVisibility = updatedItemsDict[kRoomSettingsDirectoryKey];
|
2016-07-11 15:53:47 +00:00
|
|
|
if (modifiedDirectoryVisibility)
|
|
|
|
{
|
|
|
|
if ([modifiedDirectoryVisibility isEqualToString:directoryVisibility])
|
|
|
|
{
|
|
|
|
// The requested change corresponds to the actual settings
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsDirectoryKey];
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
directoryVisibilitySwitch.on = ([directoryVisibility isEqualToString:kMXRoomDirectoryVisibilityPublic]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] request to get directory visibility failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->actualDirectoryVisibilityRequest = nil;
|
2016-07-11 15:53:47 +00:00
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2018-01-19 16:08:44 +00:00
|
|
|
- (void)refreshRelatedGroups
|
|
|
|
{
|
|
|
|
// Refresh here the related communities list.
|
|
|
|
[relatedGroups removeAllObjects];
|
|
|
|
[relatedGroups addObjectsFromArray:mxRoomState.relatedGroups];
|
2019-01-07 23:24:11 +00:00
|
|
|
NSArray *removedCommunities = updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey];
|
2018-01-19 16:08:44 +00:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-07 23:24:11 +00:00
|
|
|
NSArray *communities = updatedItemsDict[kRoomSettingsNewRelatedGroupKey];
|
2018-01-19 16:08:44 +00:00
|
|
|
if (communities)
|
|
|
|
{
|
|
|
|
[relatedGroups addObjectsFromArray:communities];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-01 13:50:37 +00:00
|
|
|
#pragma mark - UITextViewDelegate
|
|
|
|
|
|
|
|
- (void)textViewDidBeginEditing:(UITextView *)textView;
|
|
|
|
{
|
|
|
|
if (topicTextView == textView)
|
|
|
|
{
|
|
|
|
UIView *contentView = topicTextView.superview;
|
|
|
|
if (contentView)
|
|
|
|
{
|
|
|
|
// refresh cell's layout
|
|
|
|
[contentView.superview setNeedsLayout];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)textViewDidEndEditing:(UITextView *)textView
|
|
|
|
{
|
|
|
|
if (topicTextView == textView)
|
|
|
|
{
|
|
|
|
UIView *contentView = topicTextView.superview;
|
|
|
|
if (contentView)
|
|
|
|
{
|
|
|
|
// refresh cell's layout
|
|
|
|
[contentView.superview setNeedsLayout];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
- (void)textViewDidChange:(UITextView *)textView
|
|
|
|
{
|
|
|
|
if (topicTextView == textView)
|
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
NSString* currentTopic = mxRoomState.topic;
|
2015-11-27 13:02:37 +00:00
|
|
|
|
2016-09-01 12:39:10 +00:00
|
|
|
// Remove white space from both ends
|
|
|
|
NSString* topic = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
// Check whether the topic has been actually changed
|
2016-09-01 12:39:10 +00:00
|
|
|
if ((topic || currentTopic) && ([topic isEqualToString:currentTopic] == NO))
|
2015-11-27 13:02:37 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsTopicKey] = topic ? topic : @"";
|
2015-11-27 13:02:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsTopicKey];
|
2015-11-27 13:02:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 15:53:47 +00:00
|
|
|
#pragma mark - UITextFieldDelegate
|
|
|
|
|
|
|
|
- (void)textFieldDidBeginEditing:(UITextField *)textField
|
|
|
|
{
|
2016-09-01 12:39:10 +00:00
|
|
|
if (textField == nameTextField)
|
|
|
|
{
|
|
|
|
nameTextField.textAlignment = NSTextAlignmentLeft;
|
|
|
|
}
|
|
|
|
else if (textField == addAddressTextField)
|
2016-07-11 15:53:47 +00:00
|
|
|
{
|
|
|
|
if (textField.text.length == 0)
|
|
|
|
{
|
|
|
|
textField.text = @"#";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- (void)textFieldDidEndEditing:(UITextField *)textField
|
|
|
|
{
|
2016-09-01 12:39:10 +00:00
|
|
|
if (textField == nameTextField)
|
|
|
|
{
|
|
|
|
nameTextField.textAlignment = NSTextAlignmentRight;
|
|
|
|
}
|
|
|
|
else if (textField == addAddressTextField)
|
2016-07-11 15:53:47 +00:00
|
|
|
{
|
|
|
|
if (textField.text.length < 2)
|
|
|
|
{
|
|
|
|
// reset text field
|
|
|
|
textField.text = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check whether homeserver suffix should be added
|
|
|
|
NSRange range = [textField.text rangeOfString:@":"];
|
|
|
|
if (range.location == NSNotFound)
|
|
|
|
{
|
|
|
|
textField.text = [textField.text stringByAppendingString:self.mainSession.matrixRestClient.homeserverSuffix];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
|
|
|
{
|
|
|
|
// Auto complete room alias
|
|
|
|
if (textField == addAddressTextField)
|
|
|
|
{
|
|
|
|
// Add # if none
|
|
|
|
if (!textField.text.length || textField.text.length == range.length)
|
|
|
|
{
|
|
|
|
if ([string hasPrefix:@"#"] == NO)
|
|
|
|
{
|
|
|
|
if ([string isEqualToString:@":"])
|
|
|
|
{
|
|
|
|
textField.text = [NSString stringWithFormat:@"#%@",self.mainSession.matrixRestClient.homeserverSuffix];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textField.text = [NSString stringWithFormat:@"#%@",string];
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Remove default '#' if the string start with '#'
|
|
|
|
if ([string hasPrefix:@"#"] && [textField.text isEqualToString:@"#"])
|
|
|
|
{
|
|
|
|
textField.text = string;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
// Add homeserver automatically when user adds ':' at the end
|
|
|
|
else if (range.location == textField.text.length && [string isEqualToString:@":"])
|
|
|
|
{
|
|
|
|
textField.text = [textField.text stringByAppendingString:self.mainSession.matrixRestClient.homeserverSuffix];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)textFieldShouldClear:(UITextField *)textField
|
|
|
|
{
|
|
|
|
if (textField == addAddressTextField)
|
|
|
|
{
|
|
|
|
textField.text = @"#";
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)textFieldShouldReturn:(UITextField *)textField
|
|
|
|
{
|
2016-09-01 12:39:10 +00:00
|
|
|
if (textField == nameTextField)
|
|
|
|
{
|
|
|
|
// Dismiss the keyboard
|
|
|
|
[nameTextField resignFirstResponder];
|
|
|
|
}
|
|
|
|
else if (textField == addAddressTextField)
|
2016-07-11 15:53:47 +00:00
|
|
|
{
|
|
|
|
// Dismiss the keyboard
|
|
|
|
[addAddressTextField resignFirstResponder];
|
|
|
|
|
|
|
|
NSString *roomAlias = addAddressTextField.text;
|
|
|
|
if (!roomAlias.length || [self addRoomAlias:roomAlias])
|
|
|
|
{
|
|
|
|
// Reset the input field
|
|
|
|
addAddressTextField.text = nil;
|
|
|
|
}
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2016-07-01 13:50:37 +00:00
|
|
|
#pragma mark - actions
|
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
- (IBAction)onTextFieldUpdate:(UITextField*)textField
|
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
if (textField == nameTextField)
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-09-01 12:39:10 +00:00
|
|
|
NSString *currentName = mxRoomState.name;
|
|
|
|
|
|
|
|
// Remove white space from both ends
|
|
|
|
NSString *displayName = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
2015-11-27 13:02:37 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
// Check whether the name has been actually changed
|
2016-09-01 12:39:10 +00:00
|
|
|
if ((displayName || currentName) && ([displayName isEqualToString:currentName] == NO))
|
2015-11-27 13:02:37 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsNameKey] = displayName ? displayName : @"";
|
2015-11-27 13:02:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsNameKey];
|
2015-11-27 13:02:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 17:17:20 +00:00
|
|
|
- (void)didUpdateRules:(NSNotification *)notif
|
|
|
|
{
|
2016-06-27 13:32:07 +00:00
|
|
|
[self refreshRoomSettings];
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 13:02:37 +00:00
|
|
|
- (IBAction)onCancel:(id)sender
|
|
|
|
{
|
2016-06-27 13:32:07 +00:00
|
|
|
[self dismissFirstResponder];
|
|
|
|
|
2016-06-24 13:48:16 +00:00
|
|
|
// Check whether some changes have been done
|
2016-06-23 16:51:44 +00:00
|
|
|
if (updatedItemsDict.count)
|
2015-12-15 17:17:20 +00:00
|
|
|
{
|
2016-06-24 13:48:16 +00:00
|
|
|
[self promptUserToSaveChanges];
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
[self withdrawViewControllerAnimated:YES completion:nil];
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
2015-11-27 13:02:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 16:08:44 +00:00
|
|
|
- (void)onSaveFailed:(NSString*)message withKeys:(NSArray<NSString *>*)keys
|
2015-11-27 14:16:16 +00:00
|
|
|
{
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
|
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
2018-01-19 02:43:28 +00:00
|
|
|
style:UIAlertActionStyleCancel
|
2017-07-14 14:41:25 +00:00
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
// Discard related change
|
2018-01-19 16:08:44 +00:00
|
|
|
for (NSString *key in keys)
|
|
|
|
{
|
|
|
|
[self->updatedItemsDict removeObjectForKey:key];
|
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
|
|
|
// Save anything else
|
|
|
|
[self onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"retry", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[self onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCSaveChangesFailedAlert"];
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
2015-11-27 14:16:16 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 13:02:37 +00:00
|
|
|
- (IBAction)onSave:(id)sender
|
2015-11-20 16:07:45 +00:00
|
|
|
{
|
2016-06-28 12:58:17 +00:00
|
|
|
if (updatedItemsDict.count)
|
2015-11-20 16:07:45 +00:00
|
|
|
{
|
2016-06-28 12:58:17 +00:00
|
|
|
[self startActivityIndicator];
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
// check if there is some updates related to room state
|
|
|
|
if (mxRoomState)
|
2015-12-15 12:14:37 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsAvatarKey])
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
|
|
|
// Retrieve the current picture and make sure its orientation is up
|
2019-01-07 23:24:11 +00:00
|
|
|
UIImage *updatedPicture = [MXKTools forceImageOrientationUp:updatedItemsDict[kRoomSettingsAvatarKey]];
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
// Upload picture
|
2016-12-01 13:55:29 +00:00
|
|
|
uploader = [MXMediaManager prepareUploaderWithMatrixSession:mxRoom.mxSession initialRange:0 andRange:1.0];
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
[uploader uploadData:UIImageJPEGRepresentation(updatedPicture, 0.5) filename:nil mimeType:@"image/jpeg" success:^(NSString *url) {
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->uploader = nil;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsAvatarKey];
|
2019-01-07 23:24:11 +00:00
|
|
|
self->updatedItemsDict[kRoomSettingsAvatarURLKey] = url;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[self onSave:nil];
|
2016-06-28 12:58:17 +00:00
|
|
|
}
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
} failure:^(NSError *error) {
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
NSLog(@"[RoomSettingsViewController] Image upload failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->uploader = nil;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_avatar", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsAvatarKey]];
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString* photoUrl = updatedItemsDict[kRoomSettingsAvatarURLKey];
|
2016-06-30 11:30:53 +00:00
|
|
|
if (photoUrl)
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom setAvatar:photoUrl success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsAvatarURLKey];
|
|
|
|
[self onSave:nil];
|
2016-06-28 12:58:17 +00:00
|
|
|
}
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
} failure:^(NSError *error) {
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
NSLog(@"[RoomSettingsViewController] Failed to update the room avatar");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_avatar", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsAvatarURLKey]];
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-12-15 12:14:37 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
// has a new room name
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString* roomName = updatedItemsDict[kRoomSettingsNameKey];
|
2016-06-30 11:30:53 +00:00
|
|
|
if (roomName)
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
2016-06-30 11:30:53 +00:00
|
|
|
pendingOperation = [mxRoom setName:roomName success:^{
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsNameKey];
|
|
|
|
[self onSave:nil];
|
2016-06-28 12:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Rename room failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_room_name", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsNameKey]];
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
2015-12-15 12:14:37 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// has a new room topic
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString* roomTopic = updatedItemsDict[kRoomSettingsTopicKey];
|
2016-06-30 11:30:53 +00:00
|
|
|
if (roomTopic)
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
2016-06-30 11:30:53 +00:00
|
|
|
pendingOperation = [mxRoom setTopic:roomTopic success:^{
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsTopicKey];
|
|
|
|
[self onSave:nil];
|
2016-06-28 12:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
NSLog(@"[RoomSettingsViewController] Rename topic failed");
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_topic", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsTopicKey]];
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
2015-12-15 12:14:37 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
// Room guest access
|
2019-01-07 23:24:11 +00:00
|
|
|
MXRoomGuestAccess guestAccess = updatedItemsDict[kRoomSettingsGuestAccessKey];
|
2016-06-30 11:30:53 +00:00
|
|
|
if (guestAccess)
|
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom setGuestAccess:guestAccess success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
[self onSave:nil];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Update guest access failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_room_guest_access", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsGuestAccessKey]];
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Room join rule
|
2019-01-07 23:24:11 +00:00
|
|
|
MXRoomJoinRule joinRule = updatedItemsDict[kRoomSettingsJoinRuleKey];
|
2016-06-30 11:30:53 +00:00
|
|
|
if (joinRule)
|
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom setJoinRule:joinRule success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
[self onSave:nil];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Update join rule failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_room_join_rule", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsJoinRuleKey]];
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// History visibility
|
2019-01-07 23:24:11 +00:00
|
|
|
MXRoomHistoryVisibility visibility = updatedItemsDict[kRoomSettingsHistoryVisibilityKey];
|
2016-06-30 11:30:53 +00:00
|
|
|
if (visibility)
|
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom setHistoryVisibility:visibility success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
[self onSave:nil];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Update history visibility failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_history_visibility", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsHistoryVisibilityKey]];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Room addresses
|
2019-01-07 23:24:11 +00:00
|
|
|
NSMutableArray<NSString *> *aliases = updatedItemsDict[kRoomSettingsNewAliasesKey];
|
2016-07-08 13:07:05 +00:00
|
|
|
if (aliases.count)
|
|
|
|
{
|
|
|
|
NSString *roomAlias = aliases.firstObject;
|
|
|
|
|
|
|
|
pendingOperation = [mxRoom addAlias:roomAlias success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
if (aliases.count > 1)
|
|
|
|
{
|
|
|
|
[aliases removeObjectAtIndex:0];
|
2019-01-07 23:24:11 +00:00
|
|
|
self->updatedItemsDict[kRoomSettingsNewAliasesKey] = aliases;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsNewAliasesKey];
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[self onSave:nil];
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Add room aliases failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_add_room_aliases", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsNewAliasesKey]];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
aliases = updatedItemsDict[kRoomSettingsRemovedAliasesKey];
|
2016-07-08 13:07:05 +00:00
|
|
|
if (aliases.count)
|
|
|
|
{
|
|
|
|
NSString *roomAlias = aliases.firstObject;
|
|
|
|
|
|
|
|
pendingOperation = [mxRoom removeAlias:roomAlias success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
if (aliases.count > 1)
|
|
|
|
{
|
|
|
|
[aliases removeObjectAtIndex:0];
|
2019-01-07 23:24:11 +00:00
|
|
|
self->updatedItemsDict[kRoomSettingsRemovedAliasesKey] = aliases;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsRemovedAliasesKey];
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[self onSave:nil];
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Remove room aliases failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_remove_room_aliases", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsRemovedAliasesKey]];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString* canonicalAlias = updatedItemsDict[kRoomSettingsCanonicalAliasKey];
|
2016-07-08 13:07:05 +00:00
|
|
|
if (canonicalAlias)
|
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom setCanonicalAlias:canonicalAlias success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsCanonicalAliasKey];
|
|
|
|
[self onSave:nil];
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Update canonical alias failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_room_canonical_alias", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsCanonicalAliasKey]];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Related groups
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsNewRelatedGroupKey] || updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey])
|
2018-01-19 16:08:44 +00:00
|
|
|
{
|
|
|
|
[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) {
|
|
|
|
|
|
|
|
NSLog(@"[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 = NSLocalizedStringFromTable(@"room_details_fail_to_update_room_communities", @"Vector", nil);
|
|
|
|
}
|
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsNewRelatedGroupKey,kRoomSettingsRemovedRelatedGroupKey]];
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2015-12-15 12:14:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
// Update here other room settings
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString *roomTag = updatedItemsDict[kRoomSettingsTagKey];
|
2016-06-30 11:30:53 +00:00
|
|
|
if (roomTag)
|
2015-11-20 16:07:45 +00:00
|
|
|
{
|
2016-06-28 12:58:17 +00:00
|
|
|
if (!roomTag.length)
|
|
|
|
{
|
|
|
|
roomTag = nil;
|
|
|
|
}
|
2015-11-20 16:07:45 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
[mxRoom setRoomTag:roomTag completion:^{
|
2015-11-20 16:07:45 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2015-11-20 16:07:45 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
|
|
|
[self onSave:nil];
|
2016-06-23 16:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
2015-11-20 16:07:45 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsMuteNotifKey])
|
2015-11-20 16:07:45 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
if (((NSNumber*) updatedItemsDict[kRoomSettingsMuteNotifKey]).boolValue)
|
2016-09-08 08:43:03 +00:00
|
|
|
{
|
|
|
|
[mxRoom mentionsOnly:^{
|
2015-11-20 16:07:45 +00:00
|
|
|
|
2016-09-08 08:43:03 +00:00
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-09-08 08:43:03 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsMuteNotifKey];
|
|
|
|
[self onSave:nil];
|
2016-09-08 08:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[mxRoom allMessages:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-09-08 08:43:03 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsMuteNotifKey];
|
|
|
|
[self onSave:nil];
|
2016-09-08 08:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
}
|
2016-06-23 16:51:44 +00:00
|
|
|
return;
|
2015-11-20 16:07:45 +00:00
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsDirectChatKey])
|
2017-09-20 13:08:25 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
pendingOperation = [mxRoom setIsDirect:((NSNumber*) updatedItemsDict[kRoomSettingsDirectChatKey]).boolValue withUserId:nil success:^{
|
2017-09-20 13:08:25 +00:00
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
|
|
|
|
self->pendingOperation = nil;
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsDirectChatKey];
|
|
|
|
[self onSave:nil];
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
} failure:^(NSError *error) {
|
2017-09-20 13:08:25 +00:00
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Altering DMness failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
|
|
|
|
self->pendingOperation = nil;
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_room_direct", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsDirectChatKey]];
|
2017-09-20 13:08:25 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
// Room directory visibility
|
2019-01-07 23:24:11 +00:00
|
|
|
MXRoomDirectoryVisibility directoryVisibility = updatedItemsDict[kRoomSettingsDirectoryKey];
|
2016-06-30 11:30:53 +00:00
|
|
|
if (directoryVisibility)
|
|
|
|
{
|
|
|
|
[mxRoom setDirectoryVisibility:directoryVisibility success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsDirectoryKey];
|
|
|
|
[self onSave:nil];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Update room directory visibility failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
self->pendingOperation = nil;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_update_room_directory_visibility", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsDirectoryKey]];
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
// Room encryption
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsEncryptionKey])
|
2016-11-03 10:57:08 +00:00
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom enableEncryptionWithAlgorithm:kMXCryptoMegolmAlgorithm success:^{
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
|
|
|
|
self->pendingOperation = nil;
|
|
|
|
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsEncryptionKey];
|
|
|
|
[self onSave:nil];
|
2016-11-03 10:57:08 +00:00
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
} failure:^(NSError *error) {
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
NSLog(@"[RoomSettingsViewController] Enabling encrytion failed. Error: %@", error);
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
|
|
|
|
self->pendingOperation = nil;
|
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
NSString* message = error.localizedDescription;
|
|
|
|
if (!message.length)
|
|
|
|
{
|
|
|
|
message = NSLocalizedStringFromTable(@"room_details_fail_to_enable_encryption", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
[self onSaveFailed:message withKeys:@[kRoomSettingsEncryptionKey]];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
});
|
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
}];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-03-03 12:07:18 +00:00
|
|
|
// Room settings on blacklist unverified devices
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey])
|
2017-03-03 12:07:18 +00:00
|
|
|
{
|
|
|
|
BOOL blacklistUnverifiedDevices = [((NSNumber*)updatedItemsDict[kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey]) boolValue];
|
|
|
|
[mxRoom.mxSession.crypto setBlacklistUnverifiedDevicesInRoom:mxRoom.roomId blacklist:blacklistUnverifiedDevices];
|
|
|
|
}
|
2015-11-20 16:07:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = NO;
|
2015-12-15 17:17:20 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
[self stopActivityIndicator];
|
2015-11-20 16:07:45 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
[self withdrawViewControllerAnimated:YES completion:nil];
|
2015-11-20 16:07:45 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
#pragma mark - UITableViewDataSource
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
|
|
{
|
2018-01-19 16:08:44 +00:00
|
|
|
// Refresh here the room addresses list.
|
2016-07-12 15:22:06 +00:00
|
|
|
[roomAddresses removeAllObjects];
|
|
|
|
localAddressesCount = 0;
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
NSArray *removedAliases = updatedItemsDict[kRoomSettingsRemovedAliasesKey];
|
2016-07-12 15:22:06 +00:00
|
|
|
|
|
|
|
NSArray *aliases = mxRoomState.aliases;
|
|
|
|
if (aliases)
|
|
|
|
{
|
|
|
|
for (NSString *alias in aliases)
|
|
|
|
{
|
|
|
|
// Check whether the user did not remove it
|
|
|
|
if (!removedAliases || [removedAliases indexOfObject:alias] == NSNotFound)
|
|
|
|
{
|
|
|
|
// Add it
|
|
|
|
if ([alias hasSuffix:self.mainSession.matrixRestClient.homeserverSuffix])
|
|
|
|
{
|
|
|
|
[roomAddresses insertObject:alias atIndex:localAddressesCount];
|
|
|
|
localAddressesCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[roomAddresses addObject:alias];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
aliases = updatedItemsDict[kRoomSettingsNewAliasesKey];
|
2016-07-12 15:22:06 +00:00
|
|
|
for (NSString *alias in aliases)
|
|
|
|
{
|
|
|
|
// Add this new alias to local addresses
|
|
|
|
[roomAddresses insertObject:alias atIndex:localAddressesCount];
|
|
|
|
localAddressesCount++;
|
|
|
|
}
|
|
|
|
|
2018-01-19 16:08:44 +00:00
|
|
|
[self refreshRelatedGroups];
|
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
// Return the fixed number of sections
|
2016-06-23 16:51:44 +00:00
|
|
|
return ROOM_SETTINGS_SECTION_COUNT;
|
|
|
|
}
|
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
|
{
|
2016-07-12 15:22:06 +00:00
|
|
|
NSInteger count = 0;
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
if (section == ROOM_SETTINGS_MAIN_SECTION_INDEX)
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-07-12 15:22:06 +00:00
|
|
|
count = ROOM_SETTINGS_MAIN_SECTION_ROW_COUNT;
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
else if (section == ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX)
|
|
|
|
{
|
2016-07-12 15:22:06 +00:00
|
|
|
missingAddressWarningIndex = -1;
|
|
|
|
directoryVisibilityIndex = -1;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
count = ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_SUB_COUNT;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
// Check whether a room address is required for the current join rule
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString *joinRule = updatedItemsDict[kRoomSettingsJoinRuleKey];
|
2016-07-12 15:22:06 +00:00
|
|
|
if (!joinRule)
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2016-07-12 15:22:06 +00:00
|
|
|
// Use the actual values if no change is pending.
|
|
|
|
joinRule = mxRoomState.joinRule;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
if ([joinRule isEqualToString:kMXRoomJoinRulePublic] && !roomAddresses.count)
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2016-07-12 15:22:06 +00:00
|
|
|
// Notify the user that a room address is required.
|
|
|
|
missingAddressWarningIndex = count++;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
directoryVisibilityIndex = count++;
|
|
|
|
}
|
|
|
|
else if (section == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
count = ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_COUNT;
|
|
|
|
}
|
|
|
|
else if (section == ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
roomAddressNewAliasIndex = -1;
|
|
|
|
|
|
|
|
count = (localAddressesCount ? roomAddresses.count : roomAddresses.count + 1);
|
2018-09-21 14:23:32 +00:00
|
|
|
|
|
|
|
// Everyone can add an alias: display the "add address" entry
|
|
|
|
roomAddressNewAliasIndex = count++;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
else if (section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
relatedGroupsNewGroupIndex = -1;
|
|
|
|
|
|
|
|
count = relatedGroups.count;
|
|
|
|
|
|
|
|
if (self.mainSession)
|
|
|
|
{
|
|
|
|
// Check user's power level to know whether the user is allowed to add communities to this room
|
2018-07-20 08:34:54 +00:00
|
|
|
MXRoomPowerLevels *powerLevels = [mxRoomState powerLevels];
|
2018-01-19 16:08:44 +00:00
|
|
|
NSInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId];
|
|
|
|
|
|
|
|
if (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomRelatedGroups])
|
|
|
|
{
|
|
|
|
relatedGroupsNewGroupIndex = count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-02 09:06:31 +00:00
|
|
|
else if (section == ROOM_SETTINGS_BANNED_USERS_SECTION_INDEX)
|
|
|
|
{
|
2016-08-02 10:06:06 +00:00
|
|
|
count = bannedMembers.count;
|
2016-08-02 09:06:31 +00:00
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
else if (section == ROOM_SETTINGS_ADVANCED_SECTION_INDEX)
|
|
|
|
{
|
2016-07-12 15:22:06 +00:00
|
|
|
count = 1;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
if (mxRoom.mxSession.crypto)
|
|
|
|
{
|
|
|
|
count++;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2018-07-16 20:30:55 +00:00
|
|
|
if (mxRoom.summary.isEncrypted)
|
2017-03-03 12:07:18 +00:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
2016-11-03 10:57:08 +00:00
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
return count;
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
|
|
{
|
|
|
|
if (section == ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
return NSLocalizedStringFromTable(@"room_details_access_section", @"Vector", nil);
|
|
|
|
}
|
|
|
|
else if (section == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
return NSLocalizedStringFromTable(@"room_details_history_section", @"Vector", nil);
|
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
else if (section == ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
return NSLocalizedStringFromTable(@"room_details_addresses_section", @"Vector", nil);
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
else if (section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX)
|
|
|
|
{
|
2018-02-06 22:38:12 +00:00
|
|
|
if (relatedGroupsNewGroupIndex == -1)
|
|
|
|
{
|
|
|
|
// Hide this section
|
|
|
|
return nil;
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
return NSLocalizedStringFromTable(@"room_details_flair_section", @"Vector", nil);
|
|
|
|
}
|
2016-08-02 09:06:31 +00:00
|
|
|
else if (section == ROOM_SETTINGS_BANNED_USERS_SECTION_INDEX)
|
|
|
|
{
|
2016-08-02 10:06:06 +00:00
|
|
|
if (bannedMembers.count)
|
2016-08-02 09:06:31 +00:00
|
|
|
{
|
|
|
|
return NSLocalizedStringFromTable(@"room_details_banned_users_section", @"Vector", nil);
|
|
|
|
}
|
2018-02-06 22:38:12 +00:00
|
|
|
// Hide this section
|
|
|
|
return nil;
|
2016-08-02 09:06:31 +00:00
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
else if (section == ROOM_SETTINGS_ADVANCED_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
return NSLocalizedStringFromTable(@"room_details_advanced_section", @"Vector", nil);
|
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2016-08-11 11:59:17 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
|
|
|
|
{
|
|
|
|
if ([view isKindOfClass:UITableViewHeaderFooterView.class])
|
|
|
|
{
|
|
|
|
// Customize label style
|
|
|
|
UITableViewHeaderFooterView *tableViewHeaderFooterView = (UITableViewHeaderFooterView*)view;
|
2019-01-11 10:45:27 +00:00
|
|
|
tableViewHeaderFooterView.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2016-08-11 11:59:17 +00:00
|
|
|
tableViewHeaderFooterView.textLabel.font = [UIFont systemFontOfSize:15];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 09:06:31 +00:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
|
|
|
{
|
2016-08-02 10:06:06 +00:00
|
|
|
if (section == ROOM_SETTINGS_BANNED_USERS_SECTION_INDEX && bannedMembers.count == 0)
|
2016-08-02 09:06:31 +00:00
|
|
|
{
|
|
|
|
// Hide this section
|
|
|
|
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
|
|
|
|
}
|
2018-02-06 22:38:12 +00:00
|
|
|
else if (section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX && relatedGroupsNewGroupIndex == -1)
|
|
|
|
{
|
|
|
|
// Hide this section
|
|
|
|
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
|
|
|
|
}
|
2016-08-02 09:06:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return [super tableView:tableView heightForHeaderInSection:section];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
|
|
|
{
|
2016-08-02 10:06:06 +00:00
|
|
|
if (section == ROOM_SETTINGS_BANNED_USERS_SECTION_INDEX && bannedMembers.count == 0)
|
2016-08-02 09:06:31 +00:00
|
|
|
{
|
|
|
|
// Hide this section
|
|
|
|
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
|
|
|
|
}
|
2018-02-06 22:38:12 +00:00
|
|
|
else if (section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX && relatedGroupsNewGroupIndex == -1)
|
|
|
|
{
|
|
|
|
// Hide this section
|
|
|
|
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
|
|
|
|
}
|
2016-08-02 09:06:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return [super tableView:tableView heightForFooterInSection:section];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
if (indexPath.section == ROOM_SETTINGS_MAIN_SECTION_INDEX)
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
if (indexPath.row == ROOM_SETTINGS_MAIN_SECTION_ROW_TOPIC)
|
2015-11-20 14:06:48 +00:00
|
|
|
{
|
|
|
|
return ROOM_TOPIC_CELL_HEIGHT;
|
|
|
|
}
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2015-11-20 14:06:48 +00:00
|
|
|
NSInteger row = indexPath.row;
|
2016-06-27 13:32:07 +00:00
|
|
|
UITableViewCell* cell;
|
|
|
|
|
|
|
|
// Check user's power level to know which settings are editable.
|
2018-07-20 08:34:54 +00:00
|
|
|
MXRoomPowerLevels *powerLevels = [mxRoomState powerLevels];
|
2016-06-27 13:32:07 +00:00
|
|
|
NSInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId];
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
// general settings
|
2016-06-23 16:51:44 +00:00
|
|
|
if (indexPath.section == ROOM_SETTINGS_MAIN_SECTION_INDEX)
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_MUTE_NOTIFICATIONS)
|
2015-12-15 17:17:20 +00:00
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
MXKTableViewCellWithLabelAndSwitch *roomNotifCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
|
|
|
|
|
|
|
[roomNotifCell.mxkSwitch addTarget:self action:@selector(toggleRoomNotification:) forControlEvents:UIControlEventValueChanged];
|
2015-12-15 17:17:20 +00:00
|
|
|
|
|
|
|
roomNotifCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_mute_notifs", @"Vector", nil);
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsMuteNotifKey])
|
2015-12-15 17:17:20 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
roomNotifCell.mxkSwitch.on = ((NSNumber*) updatedItemsDict[kRoomSettingsMuteNotifKey]).boolValue;
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
roomNotifCell.mxkSwitch.on = mxRoom.isMute || mxRoom.isMentionsOnly;
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cell = roomNotifCell;
|
2017-09-20 13:08:25 +00:00
|
|
|
}
|
|
|
|
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_DIRECT_CHAT)
|
|
|
|
{
|
|
|
|
MXKTableViewCellWithLabelAndSwitch *roomDirectChat = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
|
|
|
|
|
|
|
[roomDirectChat.mxkSwitch addTarget:self action:@selector(toggleDirectChat:) forControlEvents:UIControlEventValueChanged];
|
2017-09-14 09:33:59 +00:00
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
roomDirectChat.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_direct_chat", @"Vector", nil);
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsDirectChatKey])
|
2017-09-20 13:08:25 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
roomDirectChat.mxkSwitch.on = ((NSNumber*) updatedItemsDict[kRoomSettingsDirectChatKey]).boolValue;
|
2017-09-20 13:08:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roomDirectChat.mxkSwitch.on = mxRoom.isDirect;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell = roomDirectChat;
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
2016-06-23 16:51:44 +00:00
|
|
|
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_PHOTO)
|
2015-12-15 09:46:34 +00:00
|
|
|
{
|
2016-06-30 11:30:53 +00:00
|
|
|
MXKTableViewCellWithLabelAndMXKImageView *roomPhotoCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndMXKImageView defaultReuseIdentifier] forIndexPath:indexPath];
|
|
|
|
|
2016-07-11 22:13:05 +00:00
|
|
|
roomPhotoCell.mxkLabelLeadingConstraint.constant = roomPhotoCell.separatorInset.left;
|
2016-06-30 11:30:53 +00:00
|
|
|
roomPhotoCell.mxkImageViewTrailingConstraint.constant = 10;
|
2015-12-15 09:46:34 +00:00
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
roomPhotoCell.mxkImageViewWidthConstraint.constant = roomPhotoCell.mxkImageViewHeightConstraint.constant = 30;
|
|
|
|
|
|
|
|
roomPhotoCell.mxkImageViewDisplayBoxType = MXKTableViewCellDisplayBoxTypeCircle;
|
|
|
|
|
|
|
|
// Handle tap on avatar to update it
|
|
|
|
if (!roomPhotoCell.mxkImageView.gestureRecognizers.count)
|
2015-12-15 09:46:34 +00:00
|
|
|
{
|
2015-12-15 12:14:37 +00:00
|
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onRoomAvatarTap:)];
|
|
|
|
[roomPhotoCell.mxkImageView addGestureRecognizer:tap];
|
2015-12-15 09:46:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 17:11:13 +00:00
|
|
|
roomPhotoCell.mxkImageView.defaultBackgroundColor = [UIColor clearColor];
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2015-12-15 09:46:34 +00:00
|
|
|
roomPhotoCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_photo", @"Vector", nil);
|
2019-01-11 10:45:27 +00:00
|
|
|
roomPhotoCell.mxkLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2015-12-15 09:46:34 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsAvatarKey])
|
2015-12-15 09:46:34 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
roomPhotoCell.mxkImageView.image = (UIImage*) updatedItemsDict[kRoomSettingsAvatarKey];
|
2015-12-15 09:46:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-14 14:00:50 +00:00
|
|
|
[mxRoom.summary setRoomAvatarImageIn:roomPhotoCell.mxkImageView];
|
2016-06-27 13:32:07 +00:00
|
|
|
|
|
|
|
roomPhotoCell.userInteractionEnabled = (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomAvatar]);
|
|
|
|
roomPhotoCell.mxkImageView.alpha = roomPhotoCell.userInteractionEnabled ? 1.0f : 0.5f;
|
2015-12-15 09:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cell = roomPhotoCell;
|
|
|
|
}
|
2016-06-23 16:51:44 +00:00
|
|
|
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_TOPIC)
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
TableViewCellWithLabelAndLargeTextView *roomTopicCell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsTopicCellViewIdentifier forIndexPath:indexPath];
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2016-07-11 22:13:05 +00:00
|
|
|
roomTopicCell.labelLeadingConstraint.constant = roomTopicCell.separatorInset.left;
|
|
|
|
|
2016-07-01 13:50:37 +00:00
|
|
|
roomTopicCell.label.text = NSLocalizedStringFromTable(@"room_details_topic", @"Vector", nil);
|
2016-06-27 13:32:07 +00:00
|
|
|
|
2016-07-01 13:50:37 +00:00
|
|
|
topicTextView = roomTopicCell.textView;
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsTopicKey])
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
topicTextView.text = (NSString*) updatedItemsDict[kRoomSettingsTopicKey];
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-27 13:32:07 +00:00
|
|
|
topicTextView.text = mxRoomState.topic;
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
topicTextView.tintColor = ThemeService.shared.theme.tintColor;
|
2016-07-01 13:50:37 +00:00
|
|
|
topicTextView.font = [UIFont systemFontOfSize:15];
|
2016-06-27 13:32:07 +00:00
|
|
|
topicTextView.bounces = NO;
|
|
|
|
topicTextView.delegate = self;
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2016-04-19 13:28:15 +00:00
|
|
|
// disable the edition if the user cannot update it
|
2016-06-27 13:32:07 +00:00
|
|
|
topicTextView.editable = (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomTopic]);
|
2019-01-11 10:45:27 +00:00
|
|
|
topicTextView.textColor = ThemeService.shared.theme.textSecondaryColor;
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
topicTextView.keyboardAppearance = ThemeService.shared.theme.keyboardAppearance;
|
2017-11-22 02:55:11 +00:00
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
cell = roomTopicCell;
|
|
|
|
}
|
2016-06-23 16:51:44 +00:00
|
|
|
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_NAME)
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
MXKTableViewCellWithLabelAndTextField *roomNameCell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsNameCellViewIdentifier forIndexPath:indexPath];
|
2016-07-01 08:33:07 +00:00
|
|
|
|
2016-07-11 22:13:05 +00:00
|
|
|
roomNameCell.mxkLabelLeadingConstraint.constant = roomNameCell.separatorInset.left;
|
2016-09-01 12:39:10 +00:00
|
|
|
roomNameCell.mxkTextFieldLeadingConstraint.constant = 16;
|
2016-07-01 08:33:07 +00:00
|
|
|
roomNameCell.mxkTextFieldTrailingConstraint.constant = 15;
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
roomNameCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_room_name", @"Vector", nil);
|
2019-01-11 10:45:27 +00:00
|
|
|
roomNameCell.mxkLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2016-06-27 13:32:07 +00:00
|
|
|
roomNameCell.accessoryType = UITableViewCellAccessoryNone;
|
2016-07-11 15:53:47 +00:00
|
|
|
roomNameCell.accessoryView = nil;
|
2016-06-27 13:32:07 +00:00
|
|
|
|
|
|
|
nameTextField = roomNameCell.mxkTextField;
|
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
nameTextField.tintColor = ThemeService.shared.theme.tintColor;
|
2016-07-01 13:50:37 +00:00
|
|
|
nameTextField.font = [UIFont systemFontOfSize:17];
|
2016-07-01 08:33:07 +00:00
|
|
|
nameTextField.borderStyle = UITextBorderStyleNone;
|
|
|
|
nameTextField.textAlignment = NSTextAlignmentRight;
|
2016-09-01 12:39:10 +00:00
|
|
|
nameTextField.delegate = self;
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsNameKey])
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
nameTextField.text = (NSString*) updatedItemsDict[kRoomSettingsNameKey];
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-27 13:32:07 +00:00
|
|
|
nameTextField.text = mxRoomState.name;
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 13:32:07 +00:00
|
|
|
// disable the edition if the user cannot update it
|
2016-07-01 08:33:07 +00:00
|
|
|
nameTextField.userInteractionEnabled = (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomName]);
|
2019-01-11 10:45:27 +00:00
|
|
|
nameTextField.textColor = ThemeService.shared.theme.textSecondaryColor;
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
// Add a "textFieldDidChange" notification method to the text field control.
|
2016-06-27 13:32:07 +00:00
|
|
|
[nameTextField addTarget:self action:@selector(onTextFieldUpdate:) forControlEvents:UIControlEventEditingChanged];
|
|
|
|
|
|
|
|
cell = roomNameCell;
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
2016-06-28 12:58:17 +00:00
|
|
|
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_TAG)
|
2015-12-16 09:28:58 +00:00
|
|
|
{
|
2016-07-05 14:31:07 +00:00
|
|
|
roomTagCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithCheckBoxes defaultReuseIdentifier] forIndexPath:indexPath];
|
2015-12-16 09:28:58 +00:00
|
|
|
|
2016-07-11 22:13:05 +00:00
|
|
|
roomTagCell.mainContainerLeadingConstraint.constant = roomTagCell.separatorInset.left;
|
|
|
|
|
2016-07-05 15:26:55 +00:00
|
|
|
roomTagCell.checkBoxesNumber = 2;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2016-07-05 14:31:07 +00:00
|
|
|
roomTagCell.allowsMultipleSelection = NO;
|
|
|
|
roomTagCell.delegate = self;
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2016-07-05 14:31:07 +00:00
|
|
|
NSArray *labels = roomTagCell.labels;
|
2016-06-28 12:58:17 +00:00
|
|
|
UILabel *label;
|
2016-07-05 14:31:07 +00:00
|
|
|
label = labels[0];
|
2019-01-11 10:45:27 +00:00
|
|
|
label.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2016-06-28 12:58:17 +00:00
|
|
|
label.text = NSLocalizedStringFromTable(@"room_details_favourite_tag", @"Vector", nil);
|
2016-07-05 14:31:07 +00:00
|
|
|
label = labels[1];
|
2019-01-11 10:45:27 +00:00
|
|
|
label.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2016-06-28 12:58:17 +00:00
|
|
|
label.text = NSLocalizedStringFromTable(@"room_details_low_priority_tag", @"Vector", nil);
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsTagKey])
|
2015-12-16 09:28:58 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString *roomTag = updatedItemsDict[kRoomSettingsTagKey];
|
2016-06-28 12:58:17 +00:00
|
|
|
if ([roomTag isEqualToString:kMXRoomTagFavourite])
|
|
|
|
{
|
2016-07-05 14:31:07 +00:00
|
|
|
[roomTagCell setCheckBoxValue:YES atIndex:0];
|
2016-06-28 12:58:17 +00:00
|
|
|
}
|
|
|
|
else if ([roomTag isEqualToString:kMXRoomTagLowPriority])
|
|
|
|
{
|
2016-07-05 14:31:07 +00:00
|
|
|
[roomTagCell setCheckBoxValue:YES atIndex:1];
|
2016-06-28 12:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-05 14:31:07 +00:00
|
|
|
if (mxRoom.accountData.tags[kMXRoomTagFavourite] != nil)
|
|
|
|
{
|
|
|
|
[roomTagCell setCheckBoxValue:YES atIndex:0];
|
|
|
|
}
|
|
|
|
else if (mxRoom.accountData.tags[kMXRoomTagLowPriority] != nil)
|
|
|
|
{
|
|
|
|
[roomTagCell setCheckBoxValue:YES atIndex:1];
|
|
|
|
}
|
2015-12-16 09:28:58 +00:00
|
|
|
}
|
|
|
|
|
2016-07-05 14:31:07 +00:00
|
|
|
cell = roomTagCell;
|
2015-12-16 09:28:58 +00:00
|
|
|
}
|
2016-07-05 15:57:33 +00:00
|
|
|
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_LEAVE)
|
|
|
|
{
|
|
|
|
MXKTableViewCellWithButton *leaveCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier] forIndexPath:indexPath];
|
|
|
|
|
|
|
|
NSString* title = NSLocalizedStringFromTable(@"leave", @"Vector", nil);
|
|
|
|
|
|
|
|
[leaveCell.mxkButton setTitle:title forState:UIControlStateNormal];
|
|
|
|
[leaveCell.mxkButton setTitle:title forState:UIControlStateHighlighted];
|
2019-01-11 10:45:27 +00:00
|
|
|
[leaveCell.mxkButton setTintColor:ThemeService.shared.theme.tintColor];
|
2016-08-26 14:12:46 +00:00
|
|
|
leaveCell.mxkButton.titleLabel.font = [UIFont systemFontOfSize:17];
|
2016-07-05 15:57:33 +00:00
|
|
|
|
|
|
|
[leaveCell.mxkButton removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
[leaveCell.mxkButton addTarget:self action:@selector(onLeave:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
|
|
cell = leaveCell;
|
|
|
|
}
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX)
|
|
|
|
{
|
2016-07-12 15:22:06 +00:00
|
|
|
if (indexPath.row == directoryVisibilityIndex)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
MXKTableViewCellWithLabelAndSwitch *directoryToggleCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
directoryToggleCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_access_section_directory_toggle", @"Vector", nil);
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
[directoryToggleCell.mxkSwitch addTarget:self action:@selector(toggleDirectoryVisibility:) forControlEvents:UIControlEventValueChanged];
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsDirectoryKey])
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
directoryToggleCell.mxkSwitch.on = ((NSNumber*) updatedItemsDict[kRoomSettingsDirectoryKey]).boolValue;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use the last retrieved value if any
|
2017-09-20 13:08:25 +00:00
|
|
|
directoryToggleCell.mxkSwitch.on = actualDirectoryVisibility ? [actualDirectoryVisibility isEqualToString:kMXRoomDirectoryVisibilityPublic] : NO;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 07:38:38 +00:00
|
|
|
// Check whether the user can change this option
|
2017-09-20 13:08:25 +00:00
|
|
|
directoryToggleCell.mxkSwitch.enabled = (oneSelfPowerLevel >= powerLevels.stateDefault);
|
2016-07-06 07:38:38 +00:00
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
// Store the switch to be able to update it
|
|
|
|
directoryVisibilitySwitch = directoryToggleCell.mxkSwitch;
|
2017-09-14 09:33:59 +00:00
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
cell = directoryToggleCell;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2016-07-12 15:22:06 +00:00
|
|
|
else if (indexPath.row == missingAddressWarningIndex)
|
|
|
|
{
|
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsWarningCellViewIdentifier forIndexPath:indexPath];
|
|
|
|
|
|
|
|
cell.textLabel.font = [UIFont systemFontOfSize:17];
|
2019-01-11 10:57:02 +00:00
|
|
|
cell.textLabel.textColor = ThemeService.shared.riotColorPinkRed;
|
2016-07-25 14:28:13 +00:00
|
|
|
cell.textLabel.numberOfLines = 0;
|
2016-07-12 15:22:06 +00:00
|
|
|
cell.accessoryView = nil;
|
|
|
|
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
cell.textLabel.text = NSLocalizedStringFromTable(@"room_details_access_section_no_address_warning", @"Vector", nil);
|
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
else
|
|
|
|
{
|
2016-07-05 15:26:55 +00:00
|
|
|
TableViewCellWithCheckBoxAndLabel *roomAccessCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithCheckBoxAndLabel defaultReuseIdentifier] forIndexPath:indexPath];
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2016-07-11 22:13:05 +00:00
|
|
|
roomAccessCell.checkBoxLeadingConstraint.constant = roomAccessCell.separatorInset.left;
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
// Retrieve the potential updated values for joinRule and guestAccess
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString *joinRule = updatedItemsDict[kRoomSettingsJoinRuleKey];
|
|
|
|
NSString *guestAccess = updatedItemsDict[kRoomSettingsGuestAccessKey];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
// Use the actual values if no change is pending
|
|
|
|
if (!joinRule)
|
|
|
|
{
|
|
|
|
joinRule = mxRoomState.joinRule;
|
|
|
|
}
|
|
|
|
if (!guestAccess)
|
|
|
|
{
|
|
|
|
guestAccess = mxRoomState.guestAccess;
|
|
|
|
}
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
if (indexPath.row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_INVITED_ONLY)
|
|
|
|
{
|
|
|
|
roomAccessCell.label.text = NSLocalizedStringFromTable(@"room_details_access_section_invited_only", @"Vector", nil);
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
roomAccessCell.enabled = ([joinRule isEqualToString:kMXRoomJoinRuleInvite]);
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
accessInvitedOnlyTickCell = roomAccessCell;
|
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE_APART_FROM_GUEST)
|
|
|
|
{
|
|
|
|
roomAccessCell.label.text = NSLocalizedStringFromTable(@"room_details_access_section_anyone_apart_from_guest", @"Vector", nil);
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
roomAccessCell.enabled = ([joinRule isEqualToString:kMXRoomJoinRulePublic] && [guestAccess isEqualToString:kMXRoomGuestAccessForbidden]);
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
accessAnyoneApartGuestTickCell = roomAccessCell;
|
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE)
|
|
|
|
{
|
|
|
|
roomAccessCell.label.text = NSLocalizedStringFromTable(@"room_details_access_section_anyone", @"Vector", nil);
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
roomAccessCell.enabled = ([joinRule isEqualToString:kMXRoomJoinRulePublic] && [guestAccess isEqualToString:kMXRoomGuestAccessCanJoin]);
|
2016-06-30 11:30:53 +00:00
|
|
|
|
|
|
|
accessAnyoneTickCell = roomAccessCell;
|
|
|
|
}
|
|
|
|
|
2016-07-06 07:38:38 +00:00
|
|
|
// Check whether the user can change this option
|
|
|
|
roomAccessCell.userInteractionEnabled = (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomJoinRules]);
|
|
|
|
roomAccessCell.checkBox.alpha = roomAccessCell.userInteractionEnabled ? 1.0f : 0.5f;
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
cell = roomAccessCell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (indexPath.section == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_INDEX)
|
|
|
|
{
|
2016-07-05 15:26:55 +00:00
|
|
|
TableViewCellWithCheckBoxAndLabel *historyVisibilityCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithCheckBoxAndLabel defaultReuseIdentifier] forIndexPath:indexPath];
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2016-07-11 22:13:05 +00:00
|
|
|
historyVisibilityCell.checkBoxLeadingConstraint.constant = historyVisibilityCell.separatorInset.left;
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
// Retrieve first the potential updated value for history visibility
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString *visibility = updatedItemsDict[kRoomSettingsHistoryVisibilityKey];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
// Use the actual value if no change is pending
|
|
|
|
if (!visibility)
|
|
|
|
{
|
|
|
|
visibility = mxRoomState.historyVisibility;
|
|
|
|
}
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_ANYONE)
|
|
|
|
{
|
2016-07-08 13:07:05 +00:00
|
|
|
historyVisibilityCell.label.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
2016-06-30 11:30:53 +00:00
|
|
|
historyVisibilityCell.label.text = NSLocalizedStringFromTable(@"room_details_history_section_anyone", @"Vector", nil);
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
historyVisibilityCell.enabled = ([visibility isEqualToString:kMXRoomHistoryVisibilityWorldReadable]);
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
historyVisibilityTickCells[kMXRoomHistoryVisibilityWorldReadable] = historyVisibilityCell;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY)
|
|
|
|
{
|
2016-07-08 13:07:05 +00:00
|
|
|
historyVisibilityCell.label.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
2016-06-30 11:30:53 +00:00
|
|
|
historyVisibilityCell.label.text = NSLocalizedStringFromTable(@"room_details_history_section_members_only", @"Vector", nil);
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
historyVisibilityCell.enabled = ([visibility isEqualToString:kMXRoomHistoryVisibilityShared]);
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
historyVisibilityTickCells[kMXRoomHistoryVisibilityShared] = historyVisibilityCell;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_INVITED)
|
|
|
|
{
|
2016-07-08 13:07:05 +00:00
|
|
|
historyVisibilityCell.label.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
2016-06-30 11:30:53 +00:00
|
|
|
historyVisibilityCell.label.text = NSLocalizedStringFromTable(@"room_details_history_section_members_only_since_invited", @"Vector", nil);
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
historyVisibilityCell.enabled = ([visibility isEqualToString:kMXRoomHistoryVisibilityInvited]);
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
historyVisibilityTickCells[kMXRoomHistoryVisibilityInvited] = historyVisibilityCell;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_JOINED)
|
|
|
|
{
|
2016-07-08 13:07:05 +00:00
|
|
|
historyVisibilityCell.label.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
2016-06-30 11:30:53 +00:00
|
|
|
historyVisibilityCell.label.text = NSLocalizedStringFromTable(@"room_details_history_section_members_only_since_joined", @"Vector", nil);
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
historyVisibilityCell.enabled = ([visibility isEqualToString:kMXRoomHistoryVisibilityJoined]);
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
historyVisibilityTickCells[kMXRoomHistoryVisibilityJoined] = historyVisibilityCell;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the user can change this option
|
|
|
|
historyVisibilityCell.userInteractionEnabled = (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomHistoryVisibility]);
|
|
|
|
historyVisibilityCell.checkBox.alpha = historyVisibilityCell.userInteractionEnabled ? 1.0f : 0.5f;
|
|
|
|
|
|
|
|
cell = historyVisibilityCell;
|
|
|
|
}
|
|
|
|
else if (indexPath.section == ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX)
|
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
if (indexPath.row == roomAddressNewAliasIndex)
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2016-07-12 12:41:16 +00:00
|
|
|
MXKTableViewCellWithLabelAndTextField *addAddressCell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsNewAddressCellViewIdentifier forIndexPath:indexPath];
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
// Retrieve the current edited value if any
|
|
|
|
NSString *currentValue = (addAddressTextField ? addAddressTextField.text : nil);
|
|
|
|
|
|
|
|
addAddressCell.mxkLabelLeadingConstraint.constant = 0;
|
2016-07-11 22:13:05 +00:00
|
|
|
addAddressCell.mxkTextFieldLeadingConstraint.constant = addAddressCell.separatorInset.left;
|
2016-07-11 15:53:47 +00:00
|
|
|
addAddressCell.mxkTextFieldTrailingConstraint.constant = 15;
|
|
|
|
|
|
|
|
addAddressCell.mxkLabel.text = nil;
|
|
|
|
|
|
|
|
addAddressCell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
addAddressCell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"plus_icon"]];
|
|
|
|
|
|
|
|
addAddressTextField = addAddressCell.mxkTextField;
|
2016-07-12 12:41:16 +00:00
|
|
|
addAddressTextField.placeholder = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_details_new_address_placeholder", @"Vector", nil), self.mainSession.matrixRestClient.homeserverSuffix];
|
2019-01-11 10:45:27 +00:00
|
|
|
if (ThemeService.shared.theme.placeholderTextColor)
|
2017-08-11 14:56:09 +00:00
|
|
|
{
|
|
|
|
addAddressTextField.attributedPlaceholder = [[NSAttributedString alloc]
|
|
|
|
initWithString:addAddressTextField.placeholder
|
2019-01-11 10:45:27 +00:00
|
|
|
attributes:@{NSForegroundColorAttributeName: ThemeService.shared.theme.placeholderTextColor}];
|
2017-08-11 14:56:09 +00:00
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
addAddressTextField.userInteractionEnabled = YES;
|
|
|
|
addAddressTextField.text = currentValue;
|
2019-01-11 10:45:27 +00:00
|
|
|
addAddressTextField.textColor = ThemeService.shared.theme.textSecondaryColor;
|
2016-07-11 15:53:47 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
addAddressTextField.tintColor = ThemeService.shared.theme.tintColor;
|
2016-07-11 15:53:47 +00:00
|
|
|
addAddressTextField.font = [UIFont systemFontOfSize:17];
|
|
|
|
addAddressTextField.borderStyle = UITextBorderStyleNone;
|
|
|
|
addAddressTextField.textAlignment = NSTextAlignmentLeft;
|
|
|
|
|
|
|
|
addAddressTextField.autocorrectionType = UITextAutocorrectionTypeNo;
|
|
|
|
addAddressTextField.spellCheckingType = UITextSpellCheckingTypeNo;
|
|
|
|
addAddressTextField.delegate = self;
|
|
|
|
|
|
|
|
cell = addAddressCell;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-12 12:41:16 +00:00
|
|
|
UITableViewCell *addressCell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAddressCellViewIdentifier forIndexPath:indexPath];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2016-07-11 15:53:47 +00:00
|
|
|
addressCell.textLabel.font = [UIFont systemFontOfSize:16];
|
2019-01-11 10:45:27 +00:00
|
|
|
addressCell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2016-07-11 15:53:47 +00:00
|
|
|
addressCell.textLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
|
|
|
addressCell.accessoryView = nil;
|
|
|
|
addressCell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
addressCell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
|
|
|
// Check whether there is no local addresses
|
|
|
|
if (localAddressesCount == 0 && indexPath.row == 0)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
addressCell.textLabel.text = NSLocalizedStringFromTable(@"room_details_no_local_addresses", @"Vector", nil);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSInteger row = (localAddressesCount ? indexPath.row : indexPath.row - 1);
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2016-07-11 15:53:47 +00:00
|
|
|
if (row < roomAddresses.count)
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2016-07-25 11:57:26 +00:00
|
|
|
NSString *alias = roomAddresses[row];
|
2016-07-11 15:53:47 +00:00
|
|
|
NSString *canonicalAlias;
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsCanonicalAliasKey])
|
2016-07-11 15:53:47 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
canonicalAlias = updatedItemsDict[kRoomSettingsCanonicalAliasKey];
|
2016-07-11 15:53:47 +00:00
|
|
|
}
|
|
|
|
else
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
canonicalAlias = mxRoomState.canonicalAlias;
|
|
|
|
}
|
|
|
|
|
|
|
|
addressCell.textLabel.text = alias;
|
|
|
|
|
|
|
|
// Check whether this alias is the main address
|
|
|
|
if (canonicalAlias)
|
|
|
|
{
|
|
|
|
if ([alias isEqualToString:canonicalAlias])
|
|
|
|
{
|
|
|
|
addressCell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"main_alias_icon"]];
|
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
cell = addressCell;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
if (indexPath.row == relatedGroupsNewGroupIndex)
|
|
|
|
{
|
|
|
|
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 = addCommunityCell.separatorInset.left;
|
|
|
|
addCommunityCell.mxkTextFieldTrailingConstraint.constant = 15;
|
|
|
|
|
|
|
|
addCommunityCell.mxkLabel.text = nil;
|
|
|
|
|
|
|
|
addCommunityCell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
addCommunityCell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"plus_icon"]];
|
|
|
|
|
|
|
|
addGroupTextField = addCommunityCell.mxkTextField;
|
|
|
|
addGroupTextField.placeholder = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_details_new_flair_placeholder", @"Vector", nil), self.mainSession.matrixRestClient.homeserverSuffix];
|
2019-01-11 10:45:27 +00:00
|
|
|
if (ThemeService.shared.theme.placeholderTextColor)
|
2018-01-19 16:08:44 +00:00
|
|
|
{
|
|
|
|
addGroupTextField.attributedPlaceholder = [[NSAttributedString alloc]
|
|
|
|
initWithString:addGroupTextField.placeholder
|
2019-01-11 10:45:27 +00:00
|
|
|
attributes:@{NSForegroundColorAttributeName: ThemeService.shared.theme.placeholderTextColor}];
|
2018-01-19 16:08:44 +00:00
|
|
|
}
|
|
|
|
addGroupTextField.userInteractionEnabled = YES;
|
|
|
|
addGroupTextField.text = currentValue;
|
2019-01-11 10:45:27 +00:00
|
|
|
addGroupTextField.textColor = ThemeService.shared.theme.textSecondaryColor;
|
2018-01-19 16:08:44 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
addGroupTextField.tintColor = ThemeService.shared.theme.tintColor;
|
2018-01-19 16:08:44 +00:00
|
|
|
addGroupTextField.font = [UIFont systemFontOfSize:17];
|
|
|
|
addGroupTextField.borderStyle = UITextBorderStyleNone;
|
|
|
|
addGroupTextField.textAlignment = NSTextAlignmentLeft;
|
|
|
|
|
|
|
|
addGroupTextField.autocorrectionType = UITextAutocorrectionTypeNo;
|
|
|
|
addGroupTextField.spellCheckingType = UITextSpellCheckingTypeNo;
|
|
|
|
addGroupTextField.delegate = self;
|
|
|
|
|
|
|
|
cell = addCommunityCell;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UITableViewCell *communityCell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAddressCellViewIdentifier forIndexPath:indexPath];
|
|
|
|
|
|
|
|
communityCell.textLabel.font = [UIFont systemFontOfSize:16];
|
2019-01-11 10:45:27 +00:00
|
|
|
communityCell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2018-01-19 16:08:44 +00:00
|
|
|
communityCell.textLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
|
|
|
communityCell.accessoryView = nil;
|
|
|
|
communityCell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
communityCell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
|
|
|
if (row < relatedGroups.count)
|
|
|
|
{
|
|
|
|
communityCell.textLabel.text = relatedGroups[row];
|
|
|
|
}
|
|
|
|
cell = communityCell;
|
|
|
|
}
|
|
|
|
}
|
2016-08-02 09:06:31 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_BANNED_USERS_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
UITableViewCell *addressCell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAddressCellViewIdentifier forIndexPath:indexPath];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-08-02 09:06:31 +00:00
|
|
|
addressCell.textLabel.font = [UIFont systemFontOfSize:16];
|
2019-01-11 10:45:27 +00:00
|
|
|
addressCell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2016-08-02 09:06:31 +00:00
|
|
|
addressCell.textLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
|
|
|
addressCell.accessoryView = nil;
|
|
|
|
addressCell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
addressCell.selectionStyle = UITableViewCellSelectionStyleNone;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-08-02 10:06:06 +00:00
|
|
|
addressCell.textLabel.text = bannedMembers[indexPath.row].userId;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-08-02 09:06:31 +00:00
|
|
|
cell = addressCell;
|
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_ADVANCED_SECTION_INDEX)
|
|
|
|
{
|
2016-11-03 10:57:08 +00:00
|
|
|
if (indexPath.row == 0)
|
2016-07-11 22:13:05 +00:00
|
|
|
{
|
2016-11-03 10:57:08 +00:00
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAdvancedCellViewIdentifier];
|
|
|
|
if (!cell)
|
|
|
|
{
|
|
|
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kRoomSettingsAdvancedCellViewIdentifier];
|
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
cell.textLabel.font = [UIFont systemFontOfSize:17];
|
|
|
|
cell.textLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_room_id", @"Vector", nil);
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
|
|
|
|
cell.detailTextLabel.text = mxRoomState.roomId;
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.detailTextLabel.textColor = ThemeService.shared.theme.textSecondaryColor;
|
2016-11-03 10:57:08 +00:00
|
|
|
cell.detailTextLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
}
|
2018-07-16 20:30:55 +00:00
|
|
|
else if (mxRoom.summary.isEncrypted)
|
2016-11-03 10:57:08 +00:00
|
|
|
{
|
2017-03-03 12:07:18 +00:00
|
|
|
if (indexPath.row == 1)
|
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
MXKTableViewCellWithLabelAndSwitch *roomBlacklistUnverifiedDevicesCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
[roomBlacklistUnverifiedDevicesCell.mxkSwitch addTarget:self action:@selector(toggleBlacklistUnverifiedDevice:) forControlEvents:UIControlEventValueChanged];
|
2019-01-11 10:45:27 +00:00
|
|
|
roomBlacklistUnverifiedDevicesCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-03-03 12:07:18 +00:00
|
|
|
roomBlacklistUnverifiedDevicesCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_e2e_encryption_blacklist_unverified_devices", @"Vector", nil);
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-03-03 13:03:27 +00:00
|
|
|
// For the switch value, use by order:
|
|
|
|
// - the MXCrypto.globalBlacklistUnverifiedDevices if its value is YES
|
|
|
|
// In this case, the switch is disabled.
|
|
|
|
// - the changed value made by the user
|
|
|
|
// - the value used by the crypto
|
2017-03-03 12:07:18 +00:00
|
|
|
BOOL blacklistUnverifiedDevices;
|
2017-03-03 13:03:27 +00:00
|
|
|
if (mxRoom.mxSession.crypto.globalBlacklistUnverifiedDevices)
|
2017-03-03 12:07:18 +00:00
|
|
|
{
|
2017-03-03 13:03:27 +00:00
|
|
|
blacklistUnverifiedDevices = YES;
|
2017-09-20 13:08:25 +00:00
|
|
|
roomBlacklistUnverifiedDevicesCell.mxkSwitch.enabled = NO;
|
2017-03-03 12:07:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
roomBlacklistUnverifiedDevicesCell.mxkSwitch.enabled = YES;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey])
|
2017-03-03 13:03:27 +00:00
|
|
|
{
|
|
|
|
blacklistUnverifiedDevices = [((NSNumber*)updatedItemsDict[kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey]) boolValue];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
blacklistUnverifiedDevices = [mxRoom.mxSession.crypto isBlacklistUnverifiedDevicesInRoom:mxRoom.roomId];
|
|
|
|
}
|
2017-03-03 12:07:18 +00:00
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
roomBlacklistUnverifiedDevicesCell.mxkSwitch.on = blacklistUnverifiedDevices;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-03-03 12:07:18 +00:00
|
|
|
cell = roomBlacklistUnverifiedDevicesCell;
|
2017-09-14 09:33:59 +00:00
|
|
|
|
|
|
|
// Force layout before reusing a cell (fix switch displayed outside the screen)
|
|
|
|
[cell layoutIfNeeded];
|
2017-03-03 12:07:18 +00:00
|
|
|
}
|
|
|
|
else if (indexPath.row == 2)
|
2016-11-03 10:57:08 +00:00
|
|
|
{
|
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAdvancedE2eEnabledCellViewIdentifier];
|
|
|
|
if (!cell)
|
|
|
|
{
|
|
|
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kRoomSettingsAdvancedE2eEnabledCellViewIdentifier];
|
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
cell.textLabel.font = [UIFont systemFontOfSize:17];
|
2016-11-07 15:31:48 +00:00
|
|
|
cell.textLabel.numberOfLines = 0;
|
2016-11-03 10:57:08 +00:00
|
|
|
cell.textLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_e2e_encryption_enabled", @"Vector", nil);
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-11-03 10:57:08 +00:00
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
}
|
2017-03-03 12:07:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check user's power level to know whether the user is allowed to turn on the encryption mode
|
2018-07-20 08:34:54 +00:00
|
|
|
MXRoomPowerLevels *powerLevels = [mxRoomState powerLevels];
|
2017-03-03 12:07:18 +00:00
|
|
|
NSInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-03-03 12:07:18 +00:00
|
|
|
if (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomEncryption])
|
2016-11-03 10:57:08 +00:00
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
MXKTableViewCellWithLabelAndSwitch *roomEncryptionCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
[roomEncryptionCell.mxkSwitch addTarget:self action:@selector(toggleEncryption:) forControlEvents:UIControlEventValueChanged];
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-03-03 12:07:18 +00:00
|
|
|
roomEncryptionCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_enable_e2e_encryption", @"Vector", nil);
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
roomEncryptionCell.mxkSwitch.on = (updatedItemsDict[kRoomSettingsEncryptionKey] != nil);
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-03-03 12:07:18 +00:00
|
|
|
cell = roomEncryptionCell;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAdvancedE2eEnabledCellViewIdentifier];
|
|
|
|
if (!cell)
|
|
|
|
{
|
|
|
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kRoomSettingsAdvancedE2eEnabledCellViewIdentifier];
|
2016-11-03 10:57:08 +00:00
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-03-03 12:07:18 +00:00
|
|
|
cell.textLabel.font = [UIFont systemFontOfSize:17];
|
|
|
|
cell.textLabel.numberOfLines = 0;
|
|
|
|
cell.textLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_e2e_encryption_disabled", @"Vector", nil);
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-03-03 12:07:18 +00:00
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
2016-11-03 10:57:08 +00:00
|
|
|
}
|
2016-07-11 22:13:05 +00:00
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
// Sanity check
|
|
|
|
if (!cell)
|
|
|
|
{
|
|
|
|
NSLog(@"[RoomSettingsViewController] cellForRowAtIndexPath: invalid indexPath");
|
|
|
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
|
|
|
|
}
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
if (indexPath.section == ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX && indexPath.row != roomAddressNewAliasIndex)
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
|
|
|
if (localAddressesCount != 0 || indexPath.row != 0)
|
|
|
|
{
|
2018-09-21 14:23:32 +00:00
|
|
|
// The user can only delete alias they has created, even if the Admin has set it as canonical.
|
|
|
|
// So, let the server answer if it's possible to delete an alias.
|
|
|
|
return YES;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX && indexPath.row != relatedGroupsNewGroupIndex)
|
|
|
|
{
|
|
|
|
// The user is allowed to remove a related group only if he is allowed to add a new one.
|
|
|
|
return (relatedGroupsNewGroupIndex != -1);
|
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
|
|
|
|
{
|
|
|
|
// iOS8 requires this method to enable editing (see editActionsForRowAtIndexPath).
|
|
|
|
}
|
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
- (MXKTableViewCellWithLabelAndSwitch*)getLabelAndSwitchCell:(UITableView*)tableview forIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
MXKTableViewCellWithLabelAndSwitch *cell = [tableview dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier] forIndexPath:indexPath];
|
|
|
|
|
|
|
|
cell.mxkLabelLeadingConstraint.constant = cell.separatorInset.left;
|
|
|
|
cell.mxkSwitchTrailingConstraint.constant = 15;
|
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.mxkLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2017-09-20 13:08:25 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor;
|
2017-09-20 13:08:25 +00:00
|
|
|
[cell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventValueChanged];
|
|
|
|
|
|
|
|
// Reset the stored `directoryVisibilitySwitch` if the corresponding cell is reused.
|
|
|
|
if (cell.mxkSwitch == directoryVisibilitySwitch)
|
|
|
|
{
|
|
|
|
directoryVisibilitySwitch = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force layout before reusing a cell (fix switch displayed outside the screen)
|
|
|
|
[cell layoutIfNeeded];
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
#pragma mark - UITableViewDelegate
|
|
|
|
|
2017-08-11 14:56:09 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
|
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.backgroundColor = ThemeService.shared.theme.backgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
|
|
// Update the selected background view
|
2019-01-11 10:45:27 +00:00
|
|
|
if (ThemeService.shared.theme.selectedBackgroundColor)
|
2017-08-11 14:56:09 +00:00
|
|
|
{
|
|
|
|
cell.selectedBackgroundView = [[UIView alloc] init];
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.selectedBackgroundView.backgroundColor = ThemeService.shared.theme.selectedBackgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tableView.style == UITableViewStylePlain)
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView.backgroundColor = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-06-30 11:30:53 +00:00
|
|
|
if (self.tableView == tableView)
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2015-11-20 14:20:15 +00:00
|
|
|
[self dismissFirstResponder];
|
2015-12-15 12:14:37 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
if (indexPath.section == ROOM_SETTINGS_MAIN_SECTION_INDEX)
|
2015-12-15 12:14:37 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
if (indexPath.row == ROOM_SETTINGS_MAIN_SECTION_ROW_PHOTO)
|
2015-12-15 12:14:37 +00:00
|
|
|
{
|
|
|
|
[self onRoomAvatarTap:nil];
|
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
else if (indexPath.row == ROOM_SETTINGS_MAIN_SECTION_ROW_TOPIC)
|
|
|
|
{
|
|
|
|
if (topicTextView.editable)
|
|
|
|
{
|
|
|
|
[self editRoomTopic];
|
|
|
|
}
|
|
|
|
}
|
2015-12-15 12:14:37 +00:00
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX)
|
|
|
|
{
|
2016-07-12 15:22:06 +00:00
|
|
|
BOOL isUpdated = NO;
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
if (indexPath.row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_INVITED_ONLY)
|
|
|
|
{
|
|
|
|
// Ignore the selection if the option is already enabled
|
2016-06-30 15:02:53 +00:00
|
|
|
if (! accessInvitedOnlyTickCell.isEnabled)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
|
|
|
// Enable this option
|
|
|
|
accessInvitedOnlyTickCell.enabled = YES;
|
|
|
|
// Disable other options
|
|
|
|
accessAnyoneApartGuestTickCell.enabled = NO;
|
|
|
|
accessAnyoneTickCell.enabled = NO;
|
|
|
|
|
|
|
|
// Check the actual option
|
|
|
|
if ([mxRoomState.joinRule isEqualToString:kMXRoomJoinRuleInvite])
|
|
|
|
{
|
|
|
|
// No change on room access
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsJoinRuleKey] = kMXRoomJoinRuleInvite;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2016-06-30 15:02:53 +00:00
|
|
|
// Update guest access to allow guest on invitation.
|
|
|
|
// Note: if guest_access is "forbidden" here, guests cannot join this room even if explicitly invited.
|
|
|
|
if ([mxRoomState.guestAccess isEqualToString:kMXRoomGuestAccessCanJoin])
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsGuestAccessKey] = kMXRoomGuestAccessCanJoin;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-12 15:22:06 +00:00
|
|
|
|
|
|
|
isUpdated = YES;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE_APART_FROM_GUEST)
|
|
|
|
{
|
|
|
|
// Ignore the selection if the option is already enabled
|
2016-06-30 15:02:53 +00:00
|
|
|
if (! accessAnyoneApartGuestTickCell.isEnabled)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
|
|
|
// Enable this option
|
|
|
|
accessAnyoneApartGuestTickCell.enabled = YES;
|
|
|
|
// Disable other options
|
|
|
|
accessInvitedOnlyTickCell.enabled = NO;
|
|
|
|
accessAnyoneTickCell.enabled = NO;
|
|
|
|
|
|
|
|
// Check the actual option
|
|
|
|
if ([mxRoomState.joinRule isEqualToString:kMXRoomJoinRulePublic] && [mxRoomState.guestAccess isEqualToString:kMXRoomGuestAccessForbidden])
|
|
|
|
{
|
|
|
|
// No change on room access
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([mxRoomState.joinRule isEqualToString:kMXRoomJoinRulePublic])
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsJoinRuleKey] = kMXRoomJoinRulePublic;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([mxRoomState.guestAccess isEqualToString:kMXRoomGuestAccessForbidden])
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsGuestAccessKey] = kMXRoomGuestAccessForbidden;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-12 15:22:06 +00:00
|
|
|
|
|
|
|
isUpdated = YES;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE)
|
|
|
|
{
|
|
|
|
// Ignore the selection if the option is already enabled
|
2016-06-30 15:02:53 +00:00
|
|
|
if (! accessAnyoneTickCell.isEnabled)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
|
|
|
// Enable this option
|
|
|
|
accessAnyoneTickCell.enabled = YES;
|
|
|
|
// Disable other options
|
|
|
|
accessInvitedOnlyTickCell.enabled = NO;
|
|
|
|
accessAnyoneApartGuestTickCell.enabled = NO;
|
|
|
|
|
|
|
|
// Check the actual option
|
|
|
|
if ([mxRoomState.joinRule isEqualToString:kMXRoomJoinRulePublic] && [mxRoomState.guestAccess isEqualToString:kMXRoomGuestAccessCanJoin])
|
|
|
|
{
|
|
|
|
// No change on room access
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([mxRoomState.joinRule isEqualToString:kMXRoomJoinRulePublic])
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsJoinRuleKey] = kMXRoomJoinRulePublic;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([mxRoomState.guestAccess isEqualToString:kMXRoomGuestAccessCanJoin])
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsGuestAccessKey] = kMXRoomGuestAccessCanJoin;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-12 15:22:06 +00:00
|
|
|
|
|
|
|
isUpdated = YES;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-12 15:22:06 +00:00
|
|
|
else if (indexPath.row == missingAddressWarningIndex)
|
|
|
|
{
|
|
|
|
// Scroll to room addresses section
|
|
|
|
NSIndexPath *addressIndexPath = [NSIndexPath indexPathForRow:0 inSection:ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX];
|
|
|
|
[tableView scrollToRowAtIndexPath:addressIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
|
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
if (isUpdated)
|
|
|
|
{
|
|
|
|
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX];
|
|
|
|
[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
else if (indexPath.section == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_INDEX)
|
|
|
|
{
|
2016-06-30 15:02:53 +00:00
|
|
|
// Ignore the selection if the option is already enabled
|
2016-07-05 15:26:55 +00:00
|
|
|
TableViewCellWithCheckBoxAndLabel *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
|
2016-06-30 15:02:53 +00:00
|
|
|
if (! selectedCell.isEnabled)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
2016-06-30 15:02:53 +00:00
|
|
|
MXRoomHistoryVisibility historyVisibility;
|
|
|
|
|
|
|
|
if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_ANYONE)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
2016-06-30 15:02:53 +00:00
|
|
|
historyVisibility = kMXRoomHistoryVisibilityWorldReadable;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2016-06-30 15:02:53 +00:00
|
|
|
else if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
2016-06-30 15:02:53 +00:00
|
|
|
historyVisibility = kMXRoomHistoryVisibilityShared;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2016-06-30 15:02:53 +00:00
|
|
|
else if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_INVITED)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
2016-06-30 15:02:53 +00:00
|
|
|
historyVisibility = kMXRoomHistoryVisibilityInvited;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2016-06-30 15:02:53 +00:00
|
|
|
else if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_JOINED)
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
2016-06-30 15:02:53 +00:00
|
|
|
historyVisibility = kMXRoomHistoryVisibilityJoined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (historyVisibility)
|
|
|
|
{
|
|
|
|
// Prompt the user before taking into account the change
|
|
|
|
[self shouldChangeHistoryVisibility:historyVisibility];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-30 15:02:53 +00:00
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX)
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
if (indexPath.row == roomAddressNewAliasIndex)
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
NSString *roomAlias = addAddressTextField.text;
|
|
|
|
if (!roomAlias.length || [self addRoomAlias:roomAlias])
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
// Reset the input field
|
|
|
|
addAddressTextField.text = nil;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
}
|
|
|
|
else if (localAddressesCount != 0 || indexPath.row != 0)
|
|
|
|
{
|
2016-08-26 11:15:12 +00:00
|
|
|
// Prompt user on selected room alias
|
|
|
|
UITableViewCell *addressCell = [tableView cellForRowAtIndexPath:indexPath];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2016-08-26 11:15:12 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2016-07-11 15:53:47 +00:00
|
|
|
|
2016-08-26 11:15:12 +00:00
|
|
|
[self promptUserOnSelectedRoomAlias:addressCell.textLabel];
|
2016-07-11 15:53:47 +00:00
|
|
|
|
2016-08-26 11:15:12 +00:00
|
|
|
});
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
if (indexPath.row == relatedGroupsNewGroupIndex)
|
|
|
|
{
|
|
|
|
NSString *groupId = addGroupTextField.text;
|
|
|
|
if (!groupId.length || [self addCommunity:groupId])
|
|
|
|
{
|
|
|
|
// Reset the input field
|
|
|
|
addGroupTextField.text = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-02 09:57:02 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_BANNED_USERS_SECTION_INDEX)
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
// Show the RoomMemberDetailsViewController on this member so that
|
2016-08-02 09:57:02 +00:00
|
|
|
// if the user has enough power level, he will be able to unban him
|
|
|
|
RoomMemberDetailsViewController *roomMemberDetailsViewController = [RoomMemberDetailsViewController roomMemberDetailsViewController];
|
2016-08-02 10:06:06 +00:00
|
|
|
[roomMemberDetailsViewController displayRoomMember:bannedMembers[indexPath.row] withMatrixRoom:mxRoom];
|
2016-08-02 09:57:02 +00:00
|
|
|
roomMemberDetailsViewController.delegate = self;
|
2016-11-10 14:21:28 +00:00
|
|
|
roomMemberDetailsViewController.enableVoipCall = NO;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-08-02 09:57:02 +00:00
|
|
|
[self.parentViewController.navigationController pushViewController:roomMemberDetailsViewController animated:NO];
|
|
|
|
}
|
2016-11-07 15:31:48 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_ADVANCED_SECTION_INDEX && indexPath.row == 0)
|
2016-07-11 22:13:05 +00:00
|
|
|
{
|
|
|
|
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
|
|
|
|
if (cell)
|
|
|
|
{
|
2016-07-12 15:22:06 +00:00
|
|
|
// Prompt user to copy the room id (use dispatch_async here to not be stuck by the table refresh).
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
[self promptUserToCopyRoomId:cell.detailTextLabel];
|
|
|
|
|
|
|
|
});
|
2016-07-11 22:13:05 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
NSMutableArray* actions;
|
|
|
|
|
|
|
|
// Add the swipe to delete only on addresses section
|
2016-07-11 15:53:47 +00:00
|
|
|
if (indexPath.section == ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX && indexPath.row != roomAddressNewAliasIndex)
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
|
|
|
if (localAddressesCount != 0 || indexPath.row != 0)
|
|
|
|
{
|
|
|
|
actions = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
// Patch: Force the width of the button by adding whitespace characters into the title string.
|
|
|
|
UITableViewRowAction *removeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
|
|
|
|
|
|
|
|
[self removeAddressAtIndexPath:indexPath];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
removeAction.backgroundColor = [MXKTools convertImageToPatternColor:@"remove_icon" backgroundColor:ThemeService.shared.theme.headerBackgroundColor patternSize:CGSizeMake(44, 44) resourceSize:CGSizeMake(24, 24)];
|
2016-07-08 13:07:05 +00:00
|
|
|
[actions insertObject:removeAction atIndex:0];
|
|
|
|
}
|
2016-06-30 15:02:53 +00:00
|
|
|
}
|
2018-01-19 16:08:44 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX && indexPath.row != relatedGroupsNewGroupIndex)
|
|
|
|
{
|
|
|
|
actions = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
// Patch: Force the width of the button by adding whitespace characters into the title string.
|
|
|
|
UITableViewRowAction *removeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
|
|
|
|
|
|
|
|
[self removeCommunityAtIndexPath:indexPath];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
removeAction.backgroundColor = [MXKTools convertImageToPatternColor:@"remove_icon" backgroundColor:ThemeService.shared.theme.headerBackgroundColor patternSize:CGSizeMake(44, 44) resourceSize:CGSizeMake(24, 24)];
|
2018-01-19 16:08:44 +00:00
|
|
|
[actions insertObject:removeAction atIndex:0];
|
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
return actions;
|
2016-06-30 15:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
- (void)shouldChangeHistoryVisibility:(MXRoomHistoryVisibility)historyVisibility
|
|
|
|
{
|
|
|
|
// Prompt the user before applying the change on room history visibility
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2016-06-30 15:02:53 +00:00
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_details_history_section_prompt_title", @"Vector", nil) message:NSLocalizedStringFromTable(@"room_details_history_section_prompt_msg", @"Vector", nil) preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
2018-01-19 02:43:28 +00:00
|
|
|
style:UIAlertActionStyleCancel
|
2017-07-14 14:41:25 +00:00
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"continue"]
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[self changeHistoryVisibility:historyVisibility];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCChangeHistoryVisibilityAlert"];
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
2016-06-30 15:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)changeHistoryVisibility:(MXRoomHistoryVisibility)historyVisibility
|
|
|
|
{
|
|
|
|
if (historyVisibility)
|
|
|
|
{
|
|
|
|
// Disable all history visibility options
|
|
|
|
NSArray *tickCells = historyVisibilityTickCells.allValues;
|
2016-07-05 15:26:55 +00:00
|
|
|
for (TableViewCellWithCheckBoxAndLabel *historyVisibilityTickCell in tickCells)
|
2016-06-30 15:02:53 +00:00
|
|
|
{
|
|
|
|
historyVisibilityTickCell.enabled = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable the selected option
|
|
|
|
historyVisibilityTickCells[historyVisibility].enabled = YES;
|
|
|
|
|
|
|
|
// Check the actual option
|
|
|
|
if ([mxRoomState.historyVisibility isEqualToString:historyVisibility])
|
|
|
|
{
|
|
|
|
// No change on history visibility
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsHistoryVisibilityKey] = historyVisibility;
|
2016-06-30 15:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
2015-11-20 14:20:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 14:23:32 +00:00
|
|
|
- (BOOL)canSetCanonicalAlias
|
|
|
|
{
|
|
|
|
BOOL canSetCanonicalAlias = NO;
|
|
|
|
if (self.mainSession)
|
|
|
|
{
|
|
|
|
// Check user's power level to know whether the user is allowed to set the main address
|
|
|
|
MXRoomPowerLevels *powerLevels = [mxRoomState powerLevels];
|
|
|
|
NSInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId];
|
|
|
|
|
|
|
|
if (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomAliases])
|
|
|
|
{
|
|
|
|
canSetCanonicalAlias = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return canSetCanonicalAlias;
|
|
|
|
}
|
|
|
|
|
2019-01-05 02:28:03 +00:00
|
|
|
- (void)shouldRemoveCanonicalAlias:(void (^)(void))didRemoveCanonicalAlias
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
|
|
|
// Prompt the user before removing the current main address
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_details_addresses_disable_main_address_prompt_title", @"Vector", nil) message:NSLocalizedStringFromTable(@"room_details_addresses_disable_main_address_prompt_msg", @"Vector", nil) preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
2018-01-19 02:43:28 +00:00
|
|
|
style:UIAlertActionStyleCancel
|
2017-07-14 14:41:25 +00:00
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"continue"]
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
// Remove the canonical address
|
|
|
|
if (self->mxRoomState.canonicalAlias.length)
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
self->updatedItemsDict[kRoomSettingsCanonicalAliasKey] = @"";
|
2017-07-14 14:41:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self->updatedItemsDict removeObjectForKey:kRoomSettingsCanonicalAliasKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX];
|
|
|
|
[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (self->updatedItemsDict.count != 0);
|
|
|
|
|
|
|
|
if (didRemoveCanonicalAlias)
|
|
|
|
{
|
|
|
|
didRemoveCanonicalAlias();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCRemoveCanonicalAliasAlert"];
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 12:14:37 +00:00
|
|
|
#pragma mark - MediaPickerViewController Delegate
|
|
|
|
|
|
|
|
- (void)dismissMediaPicker
|
|
|
|
{
|
|
|
|
if (mediaPicker)
|
|
|
|
{
|
|
|
|
[mediaPicker withdrawViewControllerAnimated:YES completion:nil];
|
|
|
|
mediaPicker = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 13:33:24 +00:00
|
|
|
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectImage:(NSData*)imageData withMimeType:(NSString *)mimetype isPhotoLibraryAsset:(BOOL)isPhotoLibraryAsset
|
2015-12-15 12:14:37 +00:00
|
|
|
{
|
|
|
|
[self dismissMediaPicker];
|
|
|
|
|
2017-11-17 13:33:24 +00:00
|
|
|
if (imageData)
|
2015-12-15 12:14:37 +00:00
|
|
|
{
|
2017-11-17 13:33:24 +00:00
|
|
|
UIImage *image = [UIImage imageWithData:imageData];
|
|
|
|
if (image)
|
|
|
|
{
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = YES;
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsAvatarKey] = image;
|
2017-11-17 13:33:24 +00:00
|
|
|
|
|
|
|
[self refreshRoomSettings];
|
|
|
|
}
|
2015-12-15 12:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 17:59:40 +00:00
|
|
|
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectVideo:(NSURL*)videoURL
|
2015-12-15 12:14:37 +00:00
|
|
|
{
|
|
|
|
// this method should not be called
|
|
|
|
[self dismissMediaPicker];
|
|
|
|
}
|
|
|
|
|
2016-08-02 09:57:02 +00:00
|
|
|
#pragma mark - MXKRoomMemberDetailsViewControllerDelegate
|
|
|
|
|
|
|
|
- (void)roomMemberDetailsViewController:(MXKRoomMemberDetailsViewController *)roomMemberDetailsViewController startChatWithMemberId:(NSString *)matrixId completion:(void (^)(void))completion
|
|
|
|
{
|
2016-11-02 13:32:02 +00:00
|
|
|
[[AppDelegate theDelegate] createDirectChatWithUserId:matrixId completion:completion];
|
2016-08-02 09:57:02 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 12:14:37 +00:00
|
|
|
#pragma mark - actions
|
|
|
|
|
2016-07-05 15:57:33 +00:00
|
|
|
- (void)onLeave:(id)sender
|
|
|
|
{
|
|
|
|
// Prompt user before leaving the room
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
|
|
|
|
|
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_participants_leave_prompt_title", @"Vector", nil)
|
|
|
|
message:NSLocalizedStringFromTable(@"room_participants_leave_prompt_msg", @"Vector", nil)
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
2018-01-19 02:43:28 +00:00
|
|
|
style:UIAlertActionStyleCancel
|
2017-07-14 14:41:25 +00:00
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"leave", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[self startActivityIndicator];
|
|
|
|
[self->mxRoom leave:^{
|
|
|
|
|
|
|
|
[self withdrawViewControllerAnimated:YES completion:nil];
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
[self stopActivityIndicator];
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Leave room failed");
|
|
|
|
// Alert user
|
|
|
|
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
|
|
|
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCLeaveAlert"];
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
2016-07-05 15:57:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 12:14:37 +00:00
|
|
|
- (void)onRoomAvatarTap:(UITapGestureRecognizer *)recognizer
|
|
|
|
{
|
|
|
|
mediaPicker = [MediaPickerViewController mediaPickerViewController];
|
|
|
|
mediaPicker.mediaTypes = @[(NSString *)kUTTypeImage];
|
|
|
|
mediaPicker.delegate = self;
|
|
|
|
UINavigationController *navigationController = [UINavigationController new];
|
|
|
|
[navigationController pushViewController:mediaPicker animated:NO];
|
|
|
|
|
|
|
|
[self presentViewController:navigationController animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
- (void)toggleRoomNotification:(UISwitch*)theSwitch
|
2015-12-15 17:17:20 +00:00
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
if (theSwitch.on == (mxRoom.isMute || mxRoom.isMentionsOnly))
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsMuteNotifKey];
|
2016-06-28 12:58:17 +00:00
|
|
|
}
|
2017-09-20 13:08:25 +00:00
|
|
|
else
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsMuteNotifKey] = @(theSwitch.on);
|
2016-07-05 14:31:07 +00:00
|
|
|
}
|
2017-09-20 13:08:25 +00:00
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleDirectChat:(UISwitch*)theSwitch
|
|
|
|
{
|
|
|
|
if (theSwitch.on == mxRoom.isDirect)
|
2016-11-03 10:57:08 +00:00
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsDirectChatKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsDirectChatKey] = @(theSwitch.on);
|
2017-09-20 13:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleEncryption:(UISwitch*)theSwitch
|
|
|
|
{
|
|
|
|
if (theSwitch.on)
|
|
|
|
{
|
|
|
|
// Prompt here user before turning on the data encryption
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
|
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"warning", @"Vector", nil)
|
|
|
|
message:NSLocalizedStringFromTable(@"room_details_advanced_e2e_encryption_prompt_message", @"Vector", nil)
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
2018-01-19 02:43:28 +00:00
|
|
|
style:UIAlertActionStyleCancel
|
2017-09-20 13:08:25 +00:00
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset switch change
|
|
|
|
theSwitch.on = NO;
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"]
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
self->updatedItemsDict[kRoomSettingsEncryptionKey] = @(YES);
|
2017-07-14 14:41:25 +00:00
|
|
|
|
2017-09-20 13:08:25 +00:00
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = self->updatedItemsDict.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCEnableEncryptionAlert"];
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsEncryptionKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleBlacklistUnverifiedDevice:(UISwitch*)theSwitch
|
|
|
|
{
|
|
|
|
if ([mxRoom.mxSession.crypto isBlacklistUnverifiedDevicesInRoom:mxRoom.roomId] != theSwitch.on)
|
|
|
|
{
|
|
|
|
updatedItemsDict[kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey] = @(theSwitch.on);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey];
|
2016-11-03 10:57:08 +00:00
|
|
|
}
|
2017-09-20 13:08:25 +00:00
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)toggleDirectoryVisibility:(UISwitch*)theSwitch
|
|
|
|
{
|
|
|
|
MXRoomDirectoryVisibility visibility = theSwitch.on ? kMXRoomDirectoryVisibilityPublic : kMXRoomDirectoryVisibilityPrivate;
|
|
|
|
|
|
|
|
// Check whether the actual settings has been retrieved
|
|
|
|
if (actualDirectoryVisibility)
|
2017-03-03 12:07:18 +00:00
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
if ([visibility isEqualToString:actualDirectoryVisibility])
|
2017-03-03 12:07:18 +00:00
|
|
|
{
|
2017-09-20 13:08:25 +00:00
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsDirectoryKey];
|
2017-03-03 12:07:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsDirectoryKey] = visibility;
|
2017-03-03 12:07:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-20 13:08:25 +00:00
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsDirectoryKey] = visibility;
|
2017-09-20 13:08:25 +00:00
|
|
|
}
|
2016-07-05 14:31:07 +00:00
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
|
2016-08-26 11:15:12 +00:00
|
|
|
- (void)setRoomAliasAsMainAddress:(NSString *)alias
|
2016-07-12 12:41:16 +00:00
|
|
|
{
|
2016-08-26 11:15:12 +00:00
|
|
|
NSString *currentCanonicalAlias = mxRoomState.canonicalAlias;
|
|
|
|
|
|
|
|
// Update the current canonical address
|
|
|
|
if ([alias isEqualToString:currentCanonicalAlias])
|
2016-07-12 12:41:16 +00:00
|
|
|
{
|
2016-08-26 11:15:12 +00:00
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsCanonicalAliasKey];
|
2016-07-12 12:41:16 +00:00
|
|
|
}
|
2016-08-26 11:15:12 +00:00
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsCanonicalAliasKey] = alias;
|
2016-08-26 11:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX];
|
|
|
|
[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
2016-07-12 12:41:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
- (void)removeAddressAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
NSInteger row = (localAddressesCount ? indexPath.row : indexPath.row - 1);
|
|
|
|
|
|
|
|
if (row < roomAddresses.count)
|
|
|
|
{
|
|
|
|
NSString *alias = roomAddresses[indexPath.row];
|
|
|
|
[self removeRoomAlias:alias];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-19 16:08:44 +00:00
|
|
|
- (void)removeCommunityAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
if (indexPath.row < relatedGroups.count)
|
|
|
|
{
|
|
|
|
NSString *groupId = relatedGroups[indexPath.row];
|
|
|
|
[self removeCommunity:groupId];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 13:07:05 +00:00
|
|
|
- (void)removeRoomAlias:(NSString*)roomAlias
|
|
|
|
{
|
|
|
|
NSString *canonicalAlias;
|
|
|
|
|
2019-01-07 23:24:11 +00:00
|
|
|
if (updatedItemsDict[kRoomSettingsCanonicalAliasKey])
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
canonicalAlias = updatedItemsDict[kRoomSettingsCanonicalAliasKey];
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
canonicalAlias = mxRoomState.canonicalAlias;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether this alias is the main address
|
|
|
|
if (canonicalAlias && [roomAlias isEqualToString:canonicalAlias])
|
|
|
|
{
|
|
|
|
// Prompt user before remove this alias which is the main address
|
|
|
|
[self shouldRemoveCanonicalAlias:^{
|
|
|
|
|
|
|
|
// The room alias can be removed now
|
|
|
|
[self removeRoomAlias:roomAlias];
|
|
|
|
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
// Check whether the alias has just been added
|
2019-01-07 23:24:11 +00:00
|
|
|
NSMutableArray<NSString *> *addedAlias = updatedItemsDict[kRoomSettingsNewAliasesKey];
|
2016-07-11 15:53:47 +00:00
|
|
|
if (addedAlias && [addedAlias indexOfObject:roomAlias] != NSNotFound)
|
2016-07-08 13:07:05 +00:00
|
|
|
{
|
2016-07-11 15:53:47 +00:00
|
|
|
[addedAlias removeObject:roomAlias];
|
|
|
|
|
|
|
|
if (!addedAlias.count)
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsNewAliasesKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
NSMutableArray<NSString *> *removedAlias = updatedItemsDict[kRoomSettingsRemovedAliasesKey];
|
2016-07-11 15:53:47 +00:00
|
|
|
if (!removedAlias)
|
|
|
|
{
|
|
|
|
removedAlias = [NSMutableArray array];
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsRemovedAliasesKey] = removedAlias;
|
2016-07-11 15:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[removedAlias addObject:roomAlias];
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
NSMutableIndexSet *mutableIndexSet = [NSMutableIndexSet indexSet];
|
|
|
|
|
|
|
|
if (roomAddresses.count <= 1)
|
|
|
|
{
|
|
|
|
// The user remove here all the room addresses, reload the room access section to display potential warning message
|
|
|
|
[mutableIndexSet addIndex:ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX];
|
|
|
|
}
|
|
|
|
|
|
|
|
[mutableIndexSet addIndex:ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX];
|
|
|
|
[self.tableView reloadSections:mutableIndexSet withRowAnimation:UITableViewRowAnimationAutomatic];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2016-07-11 15:53:47 +00:00
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-19 16:08:44 +00:00
|
|
|
- (void)removeCommunity:(NSString*)groupId
|
|
|
|
{
|
|
|
|
// Check whether the alias has just been added
|
2019-01-07 23:24:11 +00:00
|
|
|
NSMutableArray<NSString *> *addedGroup = updatedItemsDict[kRoomSettingsNewRelatedGroupKey];
|
2018-01-19 16:08:44 +00:00
|
|
|
if (addedGroup && [addedGroup indexOfObject:groupId] != NSNotFound)
|
|
|
|
{
|
|
|
|
[addedGroup removeObject:groupId];
|
|
|
|
|
|
|
|
if (!addedGroup.count)
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsNewRelatedGroupKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
NSMutableArray<NSString *> *removedGroup = updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey];
|
2018-01-19 16:08:44 +00:00
|
|
|
if (!removedGroup)
|
|
|
|
{
|
|
|
|
removedGroup = [NSMutableArray array];
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey] = removedGroup;
|
2018-01-19 16:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[removedGroup addObject:groupId];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX];
|
|
|
|
[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
|
2016-07-11 15:53:47 +00:00
|
|
|
- (BOOL)addRoomAlias:(NSString*)roomAlias
|
|
|
|
{
|
|
|
|
// Check whether the provided alias is valid
|
|
|
|
if ([MXTools isMatrixRoomAlias:roomAlias])
|
|
|
|
{
|
|
|
|
// Check whether this alias has just been deleted
|
2019-01-07 23:24:11 +00:00
|
|
|
NSMutableArray<NSString *> *removedAlias = updatedItemsDict[kRoomSettingsRemovedAliasesKey];
|
2016-07-11 15:53:47 +00:00
|
|
|
if (removedAlias && [removedAlias indexOfObject:roomAlias] != NSNotFound)
|
|
|
|
{
|
|
|
|
[removedAlias removeObject:roomAlias];
|
|
|
|
|
|
|
|
if (!removedAlias.count)
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsRemovedAliasesKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check whether this alias is not already defined for this room
|
2016-07-12 12:41:16 +00:00
|
|
|
else if ([roomAddresses indexOfObject:roomAlias] == NSNotFound)
|
2016-07-11 15:53:47 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
NSMutableArray<NSString *> *addedAlias = updatedItemsDict[kRoomSettingsNewAliasesKey];
|
2016-07-11 15:53:47 +00:00
|
|
|
if (!addedAlias)
|
|
|
|
{
|
|
|
|
addedAlias = [NSMutableArray array];
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsNewAliasesKey] = addedAlias;
|
2016-07-11 15:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[addedAlias addObject:roomAlias];
|
2016-07-12 15:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableIndexSet *mutableIndexSet = [NSMutableIndexSet indexSet];
|
|
|
|
|
|
|
|
if (!roomAddresses.count)
|
|
|
|
{
|
|
|
|
// The first added alias is defined as the main address by default.
|
|
|
|
// Update the current canonical address.
|
|
|
|
NSString *currentCanonicalAlias = mxRoomState.canonicalAlias;
|
|
|
|
if (currentCanonicalAlias && [roomAlias isEqualToString:currentCanonicalAlias])
|
|
|
|
{
|
|
|
|
// The right canonical alias is already defined
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsCanonicalAliasKey];
|
|
|
|
}
|
|
|
|
else
|
2016-07-12 12:41:16 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsCanonicalAliasKey] = roomAlias;
|
2016-07-12 12:41:16 +00:00
|
|
|
}
|
2016-07-12 15:22:06 +00:00
|
|
|
|
|
|
|
if (missingAddressWarningIndex != -1)
|
|
|
|
{
|
|
|
|
// Reload room access section to remove warning message
|
|
|
|
[mutableIndexSet addIndex:ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX];
|
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
}
|
2016-07-08 13:07:05 +00:00
|
|
|
|
2016-07-12 15:22:06 +00:00
|
|
|
[mutableIndexSet addIndex:ROOM_SETTINGS_ROOM_ADDRESSES_SECTION_INDEX];
|
|
|
|
[self.tableView reloadSections:mutableIndexSet withRowAnimation:UITableViewRowAnimationAutomatic];
|
2016-07-08 13:07:05 +00:00
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
return YES;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
// Prompt here user for invalid alias
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
NSString *alertMsg = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_details_addresses_invalid_address_prompt_msg", @"Vector", nil), roomAlias];
|
|
|
|
|
2017-07-14 14:41:25 +00:00
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_details_addresses_invalid_address_prompt_title", @"Vector", nil)
|
|
|
|
message:alertMsg
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"]
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCAddAliasAlert"];
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
2016-07-11 15:53:47 +00:00
|
|
|
|
|
|
|
return NO;
|
2016-07-08 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 16:08:44 +00:00
|
|
|
- (BOOL)addCommunity:(NSString*)groupId
|
|
|
|
{
|
|
|
|
// Check whether the provided id is valid
|
|
|
|
if ([MXTools isMatrixGroupIdentifier:groupId])
|
|
|
|
{
|
|
|
|
// Check whether this group has just been deleted
|
2019-01-07 23:24:11 +00:00
|
|
|
NSMutableArray<NSString *> *removedGroups = updatedItemsDict[kRoomSettingsRemovedRelatedGroupKey];
|
2018-01-19 16:08:44 +00:00
|
|
|
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)
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
NSMutableArray<NSString *> *addedGroup = updatedItemsDict[kRoomSettingsNewRelatedGroupKey];
|
2018-01-19 16:08:44 +00:00
|
|
|
if (!addedGroup)
|
|
|
|
{
|
|
|
|
addedGroup = [NSMutableArray array];
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsNewRelatedGroupKey] = addedGroup;
|
2018-01-19 16:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[addedGroup addObject:groupId];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX];
|
|
|
|
[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
|
|
|
|
[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 = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_details_flair_invalid_id_prompt_msg", @"Vector", nil), groupId];
|
|
|
|
|
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_details_flair_invalid_id_prompt_title", @"Vector", nil)
|
|
|
|
message:alertMsg
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"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;
|
|
|
|
}
|
|
|
|
|
2016-07-05 14:31:07 +00:00
|
|
|
#pragma mark - TableViewCellWithCheckBoxesDelegate
|
|
|
|
|
|
|
|
- (void)tableViewCellWithCheckBoxes:(TableViewCellWithCheckBoxes *)tableViewCellWithCheckBoxes didTapOnCheckBoxAtIndex:(NSUInteger)index
|
|
|
|
{
|
|
|
|
if (tableViewCellWithCheckBoxes == roomTagCell)
|
|
|
|
{
|
|
|
|
NSString *tappedRoomTag = (index == 0) ? kMXRoomTagFavourite : kMXRoomTagLowPriority;
|
|
|
|
BOOL isCurrentlySelected = [roomTagCell checkBoxValueAtIndex:index];
|
|
|
|
|
|
|
|
if (isCurrentlySelected)
|
|
|
|
{
|
|
|
|
// The user wants to unselect this tag
|
2016-06-28 12:58:17 +00:00
|
|
|
// Retrieve the current change on room tag (if any)
|
2019-01-07 23:24:11 +00:00
|
|
|
NSString *updatedRoomTag = updatedItemsDict[kRoomSettingsTagKey];
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
// Check the actual tag on mxRoom
|
2016-07-05 14:31:07 +00:00
|
|
|
if (mxRoom.accountData.tags[tappedRoomTag])
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
|
|
|
// The actual tag must be updated, check whether another tag is already set
|
|
|
|
if (!updatedRoomTag)
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsTagKey] = @"";
|
2016-06-28 12:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-05 14:31:07 +00:00
|
|
|
else if (updatedRoomTag && [updatedRoomTag isEqualToString:tappedRoomTag])
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
2016-07-05 14:31:07 +00:00
|
|
|
// Cancel the updated tag, but take into account the cancellation of another tag when 'tappedRoomTag' was selected.
|
|
|
|
if (mxRoom.accountData.tags.count)
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsTagKey] = @"";
|
2016-06-28 12:58:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
}
|
2016-07-05 14:31:07 +00:00
|
|
|
|
|
|
|
// Unselect the tag
|
|
|
|
[roomTagCell setCheckBoxValue:NO atIndex:index];
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-05 14:31:07 +00:00
|
|
|
// The user wants to select this room tag
|
|
|
|
// Check the actual tag on mxRoom
|
|
|
|
if (mxRoom.accountData.tags[tappedRoomTag])
|
2016-06-30 11:30:53 +00:00
|
|
|
{
|
2016-07-05 14:31:07 +00:00
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 23:24:11 +00:00
|
|
|
updatedItemsDict[kRoomSettingsTagKey] = tappedRoomTag;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2016-07-05 14:31:07 +00:00
|
|
|
|
|
|
|
// Select the tapped tag
|
|
|
|
[roomTagCell setCheckBoxValue:YES atIndex:index];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2016-07-05 14:31:07 +00:00
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
2015-12-15 12:14:37 +00:00
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|