2015-11-20 13:12:37 +00:00
|
|
|
/*
|
2016-06-23 16:51:44 +00:00
|
|
|
Copyright 2016 OpenMarket 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-06-28 12:58:17 +00:00
|
|
|
#import "TableViewCellWithSwitches.h"
|
2016-06-30 11:30:53 +00:00
|
|
|
#import "TableViewCellWithTickAndLabel.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-11-20 16:52:16 +00:00
|
|
|
#import "RageShakeManager.h"
|
|
|
|
|
2015-11-26 17:04:03 +00:00
|
|
|
#import "VectorDesignValues.h"
|
|
|
|
|
2015-12-15 09:46:34 +00:00
|
|
|
#import "AvatarGenerator.h"
|
|
|
|
|
2015-12-15 17:17:20 +00:00
|
|
|
#import "MXRoom+Vector.h"
|
|
|
|
|
2016-05-19 15:22:29 +00:00
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
#define ROOM_SETTINGS_MAIN_SECTION_INDEX 0
|
|
|
|
#define ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX 1
|
|
|
|
#define ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_INDEX 2
|
|
|
|
#define ROOM_SETTINGS_SECTION_COUNT 3
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
#define ROOM_SETTINGS_MAIN_SECTION_ROW_PHOTO 0
|
|
|
|
#define ROOM_SETTINGS_MAIN_SECTION_ROW_NAME 1
|
|
|
|
#define ROOM_SETTINGS_MAIN_SECTION_ROW_TOPIC 2
|
2016-06-28 12:58:17 +00:00
|
|
|
#define ROOM_SETTINGS_MAIN_SECTION_ROW_TAG 3
|
2016-06-23 16:51:44 +00:00
|
|
|
#define ROOM_SETTINGS_MAIN_SECTION_ROW_MUTE_NOTIFICATIONS 4
|
|
|
|
#define ROOM_SETTINGS_MAIN_SECTION_ROW_COUNT 5
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
#define ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_INVITED_ONLY 0
|
|
|
|
#define ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE_APART_FROM_GUEST 1
|
|
|
|
#define ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE 2
|
|
|
|
#define ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_DIRECTORY_TOGGLE 3
|
|
|
|
#define ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_COUNT 4
|
|
|
|
|
|
|
|
#define ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_ANYONE 0
|
|
|
|
#define ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY 1
|
|
|
|
#define ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_INVITED 2
|
|
|
|
#define ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_JOINED 3
|
|
|
|
#define ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_COUNT 4
|
|
|
|
|
2016-04-19 13:28:15 +00:00
|
|
|
#define ROOM_TOPIC_CELL_HEIGHT 124
|
2015-11-20 13:12:37 +00:00
|
|
|
|
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";
|
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-06-23 16:51:44 +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-06-28 12:58:17 +00:00
|
|
|
UISwitch *favouriteTagSwitch;
|
|
|
|
UISwitch *lowPriorityTagSwitch;
|
2015-11-20 16:07:45 +00:00
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
// Room Access items
|
|
|
|
TableViewCellWithTickAndLabel *accessInvitedOnlyTickCell;
|
|
|
|
TableViewCellWithTickAndLabel *accessAnyoneApartGuestTickCell;
|
|
|
|
TableViewCellWithTickAndLabel *accessAnyoneTickCell;
|
|
|
|
UISwitch *directoryVisibilitySwitch;
|
|
|
|
MXRoomDirectoryVisibility actualDirectoryVisibility;
|
|
|
|
|
|
|
|
// History Visibility items
|
2016-06-30 15:02:53 +00:00
|
|
|
NSMutableDictionary<MXRoomHistoryVisibility, TableViewCellWithTickAndLabel*> *historyVisibilityTickCells;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
// The potential image loader
|
|
|
|
MXKMediaLoader *uploader;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
MXKAlert *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
|
|
|
|
|
|
|
// switches
|
|
|
|
UISwitch *roomNotifSwitch;
|
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;
|
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-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-02-10 21:12:17 +00:00
|
|
|
// Setup `MXKViewControllerHandling` properties
|
|
|
|
self.defaultBarTintColor = kVectorNavBarTintColor;
|
|
|
|
self.enableBarTintColorStatusChange = NO;
|
|
|
|
self.rageShakeManager = [RageShakeManager sharedManager];
|
|
|
|
|
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-06-30 11:30:53 +00:00
|
|
|
[self.tableView registerClass:MXKTableViewCellWithLabelAndSwitch.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]];
|
|
|
|
[self.tableView registerClass:MXKTableViewCellWithLabelAndMXKImageView.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndMXKImageView defaultReuseIdentifier]];
|
|
|
|
[self.tableView registerClass:TableViewCellWithLabelAndLargeTextView.class forCellReuseIdentifier:[TableViewCellWithLabelAndLargeTextView defaultReuseIdentifier]];
|
2016-07-01 08:33:07 +00:00
|
|
|
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndTextField defaultReuseIdentifier]];
|
2016-06-28 12:58:17 +00:00
|
|
|
[self.tableView registerClass:TableViewCellWithSwitches.class forCellReuseIdentifier:[TableViewCellWithSwitches defaultReuseIdentifier]];
|
2016-06-30 11:30:53 +00:00
|
|
|
[self.tableView registerClass:TableViewCellWithTickAndLabel.class forCellReuseIdentifier:[TableViewCellWithTickAndLabel defaultReuseIdentifier]];
|
2016-06-28 12:58:17 +00:00
|
|
|
|
2015-12-02 07:32:39 +00:00
|
|
|
[self setNavBarButtons];
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 16:42:29 +00:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
2016-06-03 15:29:34 +00:00
|
|
|
// Screen tracking (via Google Analytics)
|
|
|
|
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
|
|
|
|
if (tracker)
|
|
|
|
{
|
2016-06-14 09:10:37 +00:00
|
|
|
[tracker set:kGAIScreenName value:@"RoomSettings"];
|
2016-06-03 15:29:34 +00:00
|
|
|
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
[self.tableView setContentOffset:CGPointMake(-self.tableView.contentInset.left, -self.tableView.contentInset.top) animated:YES];
|
|
|
|
|
|
|
|
}];
|
2015-11-20 16:42:29 +00:00
|
|
|
}
|
|
|
|
|
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-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-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;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
// Check whether a text input is currently edited
|
|
|
|
BOOL isNameEdited = nameTextField ? nameTextField.isFirstResponder : NO;
|
|
|
|
BOOL isTopicEdited = topicTextView ? topicTextView.isFirstResponder : NO;
|
|
|
|
|
|
|
|
// Trigger a full table reloadData
|
|
|
|
[super refreshRoomSettings];
|
|
|
|
|
|
|
|
// Restore the previous edited field
|
|
|
|
if (isNameEdited)
|
|
|
|
{
|
|
|
|
[self editRoomName];
|
|
|
|
}
|
|
|
|
else if (isTopicEdited)
|
|
|
|
{
|
|
|
|
[self editRoomTopic];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 14:20:15 +00:00
|
|
|
- (void)dismissFirstResponder
|
|
|
|
{
|
|
|
|
if ([topicTextView isFirstResponder])
|
|
|
|
{
|
|
|
|
[topicTextView resignFirstResponder];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([nameTextField isFirstResponder])
|
|
|
|
{
|
|
|
|
[nameTextField resignFirstResponder];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
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
|
|
|
|
[currentAlert dismiss:NO];
|
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
|
|
|
currentAlert = [[MXKAlert alloc] initWithTitle:nil message:NSLocalizedStringFromTable(@"room_details_with_updates", @"Vector", nil) style:MXKAlertStyleAlert];
|
|
|
|
|
|
|
|
currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"] style:MXKAlertActionStyleCancel handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
|
|
|
|
[strongSelf->updatedItemsDict removeAllObjects];
|
|
|
|
|
|
|
|
[strongSelf withdrawViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
[currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
[currentAlert showInViewController:self];
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:07:45 +00:00
|
|
|
#pragma mark - actions
|
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-06-23 16:51:44 +00:00
|
|
|
// Check whether the topic has been actually changed
|
|
|
|
if ((textView.text || currentTopic) && ([textView.text isEqualToString:currentTopic] == NO))
|
2015-11-27 13:02:37 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
[updatedItemsDict setObject:(textView.text ? textView.text : @"") forKey:kRoomSettingsTopicKey];
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)onTextFieldUpdate:(UITextField*)textField
|
|
|
|
{
|
|
|
|
if (nameTextField == textField)
|
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
NSString* currentName = mxRoomState.name;
|
2015-11-27 13:02:37 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
// Check whether the name has been actually changed
|
|
|
|
if ((textField.text || currentName) && ([textField.text isEqualToString:currentName] == NO))
|
2015-11-27 13:02:37 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
[updatedItemsDict setObject:(textField.text ? textField.text : @"") forKey:kRoomSettingsNameKey];
|
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
|
|
|
}
|
|
|
|
|
2015-11-27 14:16:16 +00:00
|
|
|
- (void)onSaveFailed:(NSString*)message withKey:(NSString*)key
|
|
|
|
{
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
[currentAlert dismiss:NO];
|
|
|
|
|
|
|
|
currentAlert = [[MXKAlert alloc] initWithTitle:nil message:message style:MXKAlertStyleAlert];
|
|
|
|
|
|
|
|
currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleCancel handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
|
|
|
|
// Discard related change
|
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:key];
|
|
|
|
|
|
|
|
// Save anything else
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
[currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"retry", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
// try again
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
2015-11-27 14:16:16 +00:00
|
|
|
|
|
|
|
[currentAlert showInViewController:self];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-06-28 12:58:17 +00:00
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsAvatarKey])
|
|
|
|
{
|
|
|
|
// Retrieve the current picture and make sure its orientation is up
|
|
|
|
UIImage *updatedPicture = [MXKTools forceImageOrientationUp:[updatedItemsDict objectForKey:kRoomSettingsAvatarKey]];
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
// Upload picture
|
|
|
|
uploader = [MXKMediaManager prepareUploaderWithMatrixSession:mxRoom.mxSession initialRange:0 andRange:1.0];
|
|
|
|
|
|
|
|
[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)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->uploader = nil;
|
|
|
|
|
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsAvatarKey];
|
|
|
|
[strongSelf->updatedItemsDict setObject:url forKey:kRoomSettingsAvatarURLKey];
|
|
|
|
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->uploader = nil;
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_avatar", @"Vector", nil) withKey:kRoomSettingsAvatarKey];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
NSString* photoUrl = [updatedItemsDict objectForKey:kRoomSettingsAvatarURLKey];
|
|
|
|
if (photoUrl)
|
2016-06-28 12:58:17 +00:00
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom setAvatar:photoUrl success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsAvatarURLKey];
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
strongSelf->pendingOperation = nil;
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_avatar", @"Vector", nil) withKey:kRoomSettingsAvatarURLKey];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
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
|
2016-06-30 11:30:53 +00:00
|
|
|
NSString* roomName = [updatedItemsDict objectForKey:kRoomSettingsNameKey];
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsNameKey];
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Rename room failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_room_name", @"Vector", nil) withKey:kRoomSettingsNameKey];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
2015-12-15 12:14:37 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// has a new room topic
|
2016-06-30 11:30:53 +00:00
|
|
|
NSString* roomTopic = [updatedItemsDict objectForKey:kRoomSettingsTopicKey];
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsTopicKey];
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
} 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)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
strongSelf->pendingOperation = nil;
|
2016-06-23 16:51:44 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_topic", @"Vector", nil) withKey:kRoomSettingsTopicKey];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
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
|
|
|
|
MXRoomGuestAccess guestAccess = [updatedItemsDict objectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
if (guestAccess)
|
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom setGuestAccess:guestAccess success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Update guest access failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_room_guest_access", @"Vector", nil) withKey:kRoomSettingsGuestAccessKey];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Room join rule
|
|
|
|
MXRoomJoinRule joinRule = [updatedItemsDict objectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
if (joinRule)
|
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom setJoinRule:joinRule success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Update join rule failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_room_join_rule", @"Vector", nil) withKey:kRoomSettingsJoinRuleKey];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// History visibility
|
|
|
|
MXRoomHistoryVisibility visibility = [updatedItemsDict objectForKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
if (visibility)
|
|
|
|
{
|
|
|
|
pendingOperation = [mxRoom setHistoryVisibility:visibility success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Update history visibility failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_history_visibility", @"Vector", nil) withKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2015-12-15 12:14:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
// Update here other room settings
|
2016-06-30 11:30:53 +00:00
|
|
|
NSString *roomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
|
|
|
|
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)
|
|
|
|
{
|
2015-11-20 16:07:45 +00:00
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
2015-11-27 13:02:37 +00:00
|
|
|
[strongSelf onSave:nil];
|
2016-06-23 16:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
2015-11-20 16:07:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsMuteNotifKey])
|
2015-11-20 16:07:45 +00:00
|
|
|
{
|
2016-06-28 12:58:17 +00:00
|
|
|
[mxRoom setMute:roomNotifSwitch.on completion:^{
|
2015-11-20 16:07:45 +00:00
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
if (weakSelf)
|
|
|
|
{
|
2015-11-20 16:07:45 +00:00
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsMuteNotifKey];
|
2015-11-27 13:02:37 +00:00
|
|
|
[strongSelf onSave:nil];
|
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
|
|
|
|
|
|
|
// Room directory visibility
|
|
|
|
MXRoomDirectoryVisibility directoryVisibility = [updatedItemsDict objectForKey:kRoomSettingsDirectoryKey];
|
|
|
|
if (directoryVisibility)
|
|
|
|
{
|
|
|
|
[mxRoom setDirectoryVisibility:directoryVisibility success:^{
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsDirectoryKey];
|
|
|
|
[strongSelf onSave:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] Update room directory visibility failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_room_directory_visibility", @"Vector", nil) withKey:kRoomSettingsDirectoryKey];
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
return ROOM_SETTINGS_SECTION_COUNT;
|
|
|
|
}
|
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
if (section == ROOM_SETTINGS_MAIN_SECTION_INDEX)
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
return 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)
|
|
|
|
{
|
|
|
|
return ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_COUNT;
|
|
|
|
}
|
|
|
|
else if (section == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
return ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_COUNT;
|
|
|
|
}
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
MXRoomPowerLevels *powerLevels = [mxRoom.state powerLevels];
|
|
|
|
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
|
|
|
{
|
2016-06-30 11:30:53 +00:00
|
|
|
MXKTableViewCellWithLabelAndSwitch *roomNotifCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier] forIndexPath:indexPath];
|
2015-12-15 17:17:20 +00:00
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
UIEdgeInsets separatorInset = roomNotifCell.separatorInset;
|
|
|
|
|
|
|
|
roomNotifCell.mxkLabelLeadingConstraint.constant = separatorInset.left;
|
|
|
|
roomNotifCell.mxkSwitchTrailingConstraint.constant = 15;
|
|
|
|
|
|
|
|
[roomNotifCell.mxkSwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
|
|
|
|
roomNotifCell.mxkSwitch.onTintColor = kVectorColorGreen;
|
2015-12-15 17:17:20 +00:00
|
|
|
|
|
|
|
roomNotifCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_mute_notifs", @"Vector", nil);
|
|
|
|
roomNotifSwitch = roomNotifCell.mxkSwitch;
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsMuteNotifKey])
|
2015-12-15 17:17:20 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
roomNotifSwitch.on = ((NSNumber*)[updatedItemsDict objectForKey:kRoomSettingsMuteNotifKey]).boolValue;
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-18 16:56:59 +00:00
|
|
|
roomNotifSwitch.on = mxRoom.isMute;
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
[roomNotifCell layoutIfNeeded];
|
2015-12-15 17:17:20 +00:00
|
|
|
cell = roomNotifCell;
|
|
|
|
}
|
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];
|
|
|
|
|
|
|
|
roomPhotoCell.mxkLabelLeadingConstraint.constant = 15;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-06-30 11:30:53 +00:00
|
|
|
roomPhotoCell.mxkImageView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
2015-12-15 09:46:34 +00:00
|
|
|
roomPhotoCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_photo", @"Vector", nil);
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsAvatarKey])
|
2015-12-15 09:46:34 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
roomPhotoCell.mxkImageView.image = (UIImage*)[updatedItemsDict objectForKey:kRoomSettingsAvatarKey];
|
2015-12-15 09:46:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-16 09:28:58 +00:00
|
|
|
[mxRoom 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-06-30 11:30:53 +00:00
|
|
|
TableViewCellWithLabelAndLargeTextView *roomTopicCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndLargeTextView defaultReuseIdentifier] forIndexPath:indexPath];
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
roomTopicCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_topic", @"Vector", nil);
|
2016-06-27 13:32:07 +00:00
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
topicTextView = roomTopicCell.mxkTextView;
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsTopicKey])
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-06-27 13:32:07 +00:00
|
|
|
topicTextView.text = (NSString*)[updatedItemsDict objectForKey: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
|
|
|
}
|
2015-11-27 14:16:16 +00:00
|
|
|
|
2016-06-27 13:32:07 +00:00
|
|
|
topicTextView.tintColor = kVectorColorGreen;
|
|
|
|
topicTextView.font = [UIFont systemFontOfSize:16];
|
|
|
|
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]);
|
|
|
|
topicTextView.textColor = kVectorTextColorGray;
|
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-01 08:33:07 +00:00
|
|
|
MXKTableViewCellWithLabelAndTextField *roomNameCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndTextField defaultReuseIdentifier] forIndexPath:indexPath];
|
|
|
|
|
|
|
|
UIEdgeInsets separatorInset = roomNameCell.separatorInset;
|
|
|
|
|
|
|
|
roomNameCell.mxkLabelLeadingConstraint.constant = separatorInset.left;
|
|
|
|
roomNameCell.mxkTextFieldTrailingConstraint.constant = 15;
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
roomNameCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_room_name", @"Vector", nil);
|
2016-06-27 13:32:07 +00:00
|
|
|
roomNameCell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
|
|
|
|
nameTextField = roomNameCell.mxkTextField;
|
|
|
|
|
|
|
|
nameTextField.tintColor = kVectorColorGreen;
|
2016-07-01 08:33:07 +00:00
|
|
|
nameTextField.borderStyle = UITextBorderStyleNone;
|
|
|
|
nameTextField.textAlignment = NSTextAlignmentRight;
|
2015-11-20 13:12:37 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsNameKey])
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-06-27 13:32:07 +00:00
|
|
|
nameTextField.text = (NSString*)[updatedItemsDict objectForKey: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]);
|
2016-06-27 13:32:07 +00:00
|
|
|
nameTextField.textColor = kVectorTextColorGray;
|
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-06-28 12:58:17 +00:00
|
|
|
TableViewCellWithSwitches *tagCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithSwitches defaultReuseIdentifier] forIndexPath:indexPath];
|
|
|
|
|
|
|
|
tagCell.switchesNumber = 2;
|
2015-12-16 09:28:58 +00:00
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
favouriteTagSwitch = tagCell.switches[0];
|
|
|
|
[favouriteTagSwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
|
|
|
|
favouriteTagSwitch.onTintColor = kVectorColorGreen;
|
|
|
|
|
|
|
|
lowPriorityTagSwitch = tagCell.switches[1];
|
|
|
|
[lowPriorityTagSwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
|
|
|
|
lowPriorityTagSwitch.onTintColor = kVectorColorGreen;
|
|
|
|
|
|
|
|
UILabel *label;
|
|
|
|
label = tagCell.labels[0];
|
|
|
|
label.text = NSLocalizedStringFromTable(@"room_details_favourite_tag", @"Vector", nil);
|
|
|
|
label = tagCell.labels[1];
|
|
|
|
label.text = NSLocalizedStringFromTable(@"room_details_low_priority_tag", @"Vector", nil);
|
|
|
|
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsTagKey])
|
2015-12-16 09:28:58 +00:00
|
|
|
{
|
2016-06-28 12:58:17 +00:00
|
|
|
NSString *roomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
|
|
|
|
if ([roomTag isEqualToString:kMXRoomTagFavourite])
|
|
|
|
{
|
|
|
|
favouriteTagSwitch.on = YES;
|
|
|
|
lowPriorityTagSwitch.on = NO;
|
|
|
|
}
|
|
|
|
else if ([roomTag isEqualToString:kMXRoomTagLowPriority])
|
|
|
|
{
|
|
|
|
favouriteTagSwitch.on = NO;
|
|
|
|
lowPriorityTagSwitch.on = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
favouriteTagSwitch.on = NO;
|
|
|
|
lowPriorityTagSwitch.on = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-30 11:30:53 +00:00
|
|
|
favouriteTagSwitch.on = (mxRoom.accountData.tags[kMXRoomTagFavourite] != 0);
|
|
|
|
lowPriorityTagSwitch.on = (mxRoom.accountData.tags[kMXRoomTagLowPriority] != 0);
|
2015-12-16 09:28:58 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
cell = tagCell;
|
2015-12-16 09:28:58 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
if (indexPath.row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_DIRECTORY_TOGGLE)
|
|
|
|
{
|
|
|
|
MXKTableViewCellWithLabelAndSwitch *directoryToggleCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier] forIndexPath:indexPath];
|
|
|
|
|
|
|
|
UIEdgeInsets separatorInset = directoryToggleCell.separatorInset;
|
|
|
|
|
|
|
|
directoryToggleCell.mxkLabelLeadingConstraint.constant = separatorInset.left;
|
|
|
|
directoryToggleCell.mxkSwitchTrailingConstraint.constant = 15;
|
|
|
|
|
|
|
|
directoryToggleCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_access_section_directory_toggle", @"Vector", nil);
|
|
|
|
|
|
|
|
directoryVisibilitySwitch = directoryToggleCell.mxkSwitch;
|
|
|
|
|
|
|
|
[directoryVisibilitySwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
|
|
|
|
directoryVisibilitySwitch.onTintColor = kVectorColorGreen;
|
|
|
|
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsDirectoryKey])
|
|
|
|
{
|
|
|
|
directoryVisibilitySwitch.on = ((NSNumber*)[updatedItemsDict objectForKey:kRoomSettingsDirectoryKey]).boolValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use the last retrieved value if any
|
|
|
|
directoryVisibilitySwitch.on = actualDirectoryVisibility ? [actualDirectoryVisibility isEqualToString:kMXRoomDirectoryVisibilityPublic] : NO;
|
|
|
|
|
|
|
|
// Trigger a request to check the actual directory visibility
|
|
|
|
[self startActivityIndicator];
|
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
|
|
|
pendingOperation = [mxRoom directoryVisibility:^(MXRoomDirectoryVisibility directoryVisibility) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
|
|
|
|
strongSelf->actualDirectoryVisibility = directoryVisibility;
|
|
|
|
|
|
|
|
// Check a potential change before update
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsDirectoryKey])
|
|
|
|
{
|
|
|
|
if (directoryVisibilitySwitch.on == ([directoryVisibility isEqualToString:kMXRoomDirectoryVisibilityPublic]))
|
|
|
|
{
|
|
|
|
// The requested change corresponds to the actual settings
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsDirectoryKey];
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
directoryVisibilitySwitch.on = ([directoryVisibility isEqualToString:kMXRoomDirectoryVisibilityPublic]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[strongSelf stopActivityIndicator];
|
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
NSLog(@"[RoomSettingsViewController] request to get directory visibility failed");
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
strongSelf->pendingOperation = nil;
|
|
|
|
|
|
|
|
[strongSelf stopActivityIndicator];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
cell = directoryToggleCell;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TableViewCellWithTickAndLabel *roomAccessCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithTickAndLabel defaultReuseIdentifier] forIndexPath:indexPath];
|
|
|
|
|
|
|
|
if (indexPath.row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_INVITED_ONLY)
|
|
|
|
{
|
|
|
|
roomAccessCell.label.text = NSLocalizedStringFromTable(@"room_details_access_section_invited_only", @"Vector", nil);
|
|
|
|
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsJoinRuleKey])
|
|
|
|
{
|
|
|
|
NSString *joinRule = [updatedItemsDict objectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
if ([joinRule isEqualToString:kMXRoomJoinRuleInvite])
|
|
|
|
{
|
|
|
|
roomAccessCell.enabled = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roomAccessCell.enabled = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roomAccessCell.enabled = ([mxRoomState.joinRule isEqualToString:kMXRoomJoinRuleInvite]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsJoinRuleKey] || [updatedItemsDict objectForKey:kRoomSettingsGuestAccessKey])
|
|
|
|
{
|
|
|
|
NSString *joinRule = [updatedItemsDict objectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
NSString *guestAccess = [updatedItemsDict objectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
|
|
|
|
if ([joinRule isEqualToString:kMXRoomJoinRulePublic] && [guestAccess isEqualToString:kMXRoomGuestAccessForbidden])
|
|
|
|
{
|
|
|
|
roomAccessCell.enabled = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roomAccessCell.enabled = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roomAccessCell.enabled = ([mxRoomState.joinRule isEqualToString:kMXRoomJoinRulePublic] && [mxRoomState.guestAccess isEqualToString:kMXRoomGuestAccessForbidden]);
|
|
|
|
}
|
|
|
|
|
|
|
|
accessAnyoneApartGuestTickCell = roomAccessCell;
|
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE)
|
|
|
|
{
|
|
|
|
roomAccessCell.label.text = NSLocalizedStringFromTable(@"room_details_access_section_anyone", @"Vector", nil);
|
|
|
|
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsJoinRuleKey] || [updatedItemsDict objectForKey:kRoomSettingsGuestAccessKey])
|
|
|
|
{
|
|
|
|
NSString *joinRule = [updatedItemsDict objectForKey:kRoomSettingsJoinRuleKey];
|
|
|
|
NSString *guestAccess = [updatedItemsDict objectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
|
|
|
|
if ([joinRule isEqualToString:kMXRoomJoinRulePublic] && [guestAccess isEqualToString:kMXRoomGuestAccessCanJoin])
|
|
|
|
{
|
|
|
|
roomAccessCell.enabled = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roomAccessCell.enabled = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roomAccessCell.enabled = ([mxRoomState.joinRule isEqualToString:kMXRoomJoinRulePublic] && [mxRoomState.guestAccess isEqualToString:kMXRoomGuestAccessCanJoin]);
|
|
|
|
}
|
|
|
|
|
|
|
|
accessAnyoneTickCell = roomAccessCell;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell = roomAccessCell;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (indexPath.section == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
TableViewCellWithTickAndLabel *historyVisibilityCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithTickAndLabel defaultReuseIdentifier] forIndexPath:indexPath];
|
|
|
|
|
|
|
|
if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_ANYONE)
|
|
|
|
{
|
|
|
|
historyVisibilityCell.label.text = NSLocalizedStringFromTable(@"room_details_history_section_anyone", @"Vector", nil);
|
|
|
|
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsHistoryVisibilityKey])
|
|
|
|
{
|
|
|
|
NSString *visibility = [updatedItemsDict objectForKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
if ([visibility isEqualToString:kMXRoomHistoryVisibilityWorldReadable])
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = ([mxRoomState.historyVisibility isEqualToString:kMXRoomHistoryVisibilityWorldReadable]);
|
|
|
|
}
|
|
|
|
|
2016-06-30 15:02:53 +00:00
|
|
|
[historyVisibilityTickCells setObject:historyVisibilityCell forKey:kMXRoomHistoryVisibilityWorldReadable];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY)
|
|
|
|
{
|
|
|
|
historyVisibilityCell.label.text = NSLocalizedStringFromTable(@"room_details_history_section_members_only", @"Vector", nil);
|
|
|
|
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsHistoryVisibilityKey])
|
|
|
|
{
|
|
|
|
NSString *visibility = [updatedItemsDict objectForKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
if ([visibility isEqualToString:kMXRoomHistoryVisibilityShared])
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = ([mxRoomState.historyVisibility isEqualToString:kMXRoomHistoryVisibilityShared]);
|
|
|
|
}
|
|
|
|
|
2016-06-30 15:02:53 +00:00
|
|
|
[historyVisibilityTickCells setObject:historyVisibilityCell forKey:kMXRoomHistoryVisibilityShared];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_INVITED)
|
|
|
|
{
|
|
|
|
historyVisibilityCell.label.text = NSLocalizedStringFromTable(@"room_details_history_section_members_only_since_invited", @"Vector", nil);
|
|
|
|
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsHistoryVisibilityKey])
|
|
|
|
{
|
|
|
|
NSString *visibility = [updatedItemsDict objectForKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
if ([visibility isEqualToString:kMXRoomHistoryVisibilityInvited])
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = ([mxRoomState.historyVisibility isEqualToString:kMXRoomHistoryVisibilityInvited]);
|
|
|
|
}
|
|
|
|
|
2016-06-30 15:02:53 +00:00
|
|
|
[historyVisibilityTickCells setObject:historyVisibilityCell forKey:kMXRoomHistoryVisibilityInvited];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
else if (indexPath.row == ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_MEMBERS_ONLY_SINCE_JOINED)
|
|
|
|
{
|
|
|
|
historyVisibilityCell.label.text = NSLocalizedStringFromTable(@"room_details_history_section_members_only_since_joined", @"Vector", nil);
|
|
|
|
|
|
|
|
if ([updatedItemsDict objectForKey:kRoomSettingsHistoryVisibilityKey])
|
|
|
|
{
|
|
|
|
NSString *visibility = [updatedItemsDict objectForKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
if ([visibility isEqualToString:kMXRoomHistoryVisibilityJoined])
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
historyVisibilityCell.enabled = ([mxRoomState.historyVisibility isEqualToString:kMXRoomHistoryVisibilityJoined]);
|
|
|
|
}
|
|
|
|
|
2016-06-30 15:02:53 +00:00
|
|
|
[historyVisibilityTickCells setObject:historyVisibilityCell forKey:kMXRoomHistoryVisibilityJoined];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2016-06-30 15:02:53 +00:00
|
|
|
|
|
|
|
cell = historyVisibilityCell;
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
if (!cell)
|
|
|
|
{
|
|
|
|
NSLog(@"[RoomSettingsViewController] cellForRowAtIndexPath: invalid indexPath");
|
|
|
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
|
|
|
|
}
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
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-06-30 11:30:53 +00:00
|
|
|
else if (indexPath.section == ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:kMXRoomJoinRuleInvite forKey:kRoomSettingsJoinRuleKey];
|
|
|
|
|
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
|
|
|
|
{
|
2016-06-30 15:02:53 +00:00
|
|
|
[updatedItemsDict setObject:kMXRoomGuestAccessCanJoin forKey:kRoomSettingsGuestAccessKey];
|
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
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:kMXRoomJoinRulePublic forKey:kRoomSettingsJoinRuleKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([mxRoomState.guestAccess isEqualToString:kMXRoomGuestAccessForbidden])
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:kMXRoomGuestAccessForbidden forKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:kMXRoomJoinRulePublic forKey:kRoomSettingsJoinRuleKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([mxRoomState.guestAccess isEqualToString:kMXRoomGuestAccessCanJoin])
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:kMXRoomGuestAccessCanJoin forKey:kRoomSettingsGuestAccessKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
TableViewCellWithTickAndLabel *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
- (void)shouldChangeHistoryVisibility:(MXRoomHistoryVisibility)historyVisibility
|
|
|
|
{
|
|
|
|
// Prompt the user before applying the change on room history visibility
|
|
|
|
[currentAlert dismiss:NO];
|
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
|
|
|
currentAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"room_details_history_section_prompt_title", @"Vector", nil) message:NSLocalizedStringFromTable(@"room_details_history_section_prompt_msg", @"Vector", nil) style:MXKAlertStyleAlert];
|
|
|
|
|
|
|
|
currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleCancel handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
[currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"continue"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
strongSelf->currentAlert = nil;
|
2016-06-30 11:30:53 +00:00
|
|
|
|
2016-06-30 15:02:53 +00:00
|
|
|
[strongSelf changeHistoryVisibility:historyVisibility];
|
2016-06-30 11:30:53 +00:00
|
|
|
}
|
2016-06-30 15:02:53 +00:00
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
[currentAlert showInViewController:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)changeHistoryVisibility:(MXRoomHistoryVisibility)historyVisibility
|
|
|
|
{
|
|
|
|
if (historyVisibility)
|
|
|
|
{
|
|
|
|
// Disable all history visibility options
|
|
|
|
NSArray *tickCells = historyVisibilityTickCells.allValues;
|
|
|
|
for (TableViewCellWithTickAndLabel *historyVisibilityTickCell in tickCells)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:historyVisibility forKey:kRoomSettingsHistoryVisibilityKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
2015-11-20 14:20:15 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectImage:(UIImage*)image withURL:(NSURL *)imageURL
|
|
|
|
{
|
|
|
|
[self dismissMediaPicker];
|
|
|
|
|
|
|
|
if (image)
|
|
|
|
{
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = YES;
|
|
|
|
|
2016-06-23 16:51:44 +00:00
|
|
|
[updatedItemsDict setObject:image forKey:kRoomSettingsAvatarKey];
|
2015-12-15 12:14:37 +00:00
|
|
|
|
2016-06-27 13:32:07 +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];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - actions
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
}
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
- (void)onSwitchUpdate:(UISwitch*)theSwitch
|
2015-12-15 17:17:20 +00:00
|
|
|
{
|
2016-06-28 12:58:17 +00:00
|
|
|
if (theSwitch == favouriteTagSwitch)
|
|
|
|
{
|
|
|
|
if (favouriteTagSwitch.on)
|
|
|
|
{
|
|
|
|
// Check the actual tag on mxRoom
|
|
|
|
if (mxRoom.accountData.tags[kMXRoomTagFavourite])
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:kMXRoomTagFavourite forKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force off the low priority toggle
|
|
|
|
lowPriorityTagSwitch.on = NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Retrieve the current change on room tag (if any)
|
|
|
|
NSString *updatedRoomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
|
|
|
|
|
|
|
|
// Check the actual tag on mxRoom
|
|
|
|
if (mxRoom.accountData.tags[kMXRoomTagFavourite])
|
|
|
|
{
|
|
|
|
// The actual tag must be updated, check whether another tag is already set
|
|
|
|
if (!updatedRoomTag)
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (updatedRoomTag && [updatedRoomTag isEqualToString:kMXRoomTagFavourite])
|
|
|
|
{
|
|
|
|
// Cancel the updated tag, but take into account the cancellation of the another tag (low priority) when favourite was selected
|
|
|
|
if (mxRoom.accountData.tags[kMXRoomTagLowPriority])
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (theSwitch == lowPriorityTagSwitch)
|
|
|
|
{
|
|
|
|
if (lowPriorityTagSwitch.on)
|
|
|
|
{
|
|
|
|
// Check the actual tag on mxRoom
|
|
|
|
if (mxRoom.accountData.tags[kMXRoomTagLowPriority])
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:kMXRoomTagLowPriority forKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force off the favourite toggle
|
|
|
|
favouriteTagSwitch.on = NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Retrieve the current change on room tag (if any)
|
|
|
|
NSString *updatedRoomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
|
|
|
|
|
|
|
|
// Check the actual tag on mxRoom
|
|
|
|
if (mxRoom.accountData.tags[kMXRoomTagLowPriority])
|
|
|
|
{
|
|
|
|
// The actual tag must be updated, check whether another tag is already set
|
|
|
|
if (!updatedRoomTag)
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (updatedRoomTag && [updatedRoomTag isEqualToString:kMXRoomTagLowPriority])
|
|
|
|
{
|
|
|
|
// Cancel the updated tag, but take into account the cancellation of the another tag (favourite) when low priority was selected
|
|
|
|
if (mxRoom.accountData.tags[kMXRoomTagFavourite])
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (theSwitch == roomNotifSwitch)
|
2015-12-15 17:17:20 +00:00
|
|
|
{
|
2016-03-18 16:56:59 +00:00
|
|
|
if (roomNotifSwitch.on == mxRoom.isMute)
|
2015-12-15 17:17:20 +00:00
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsMuteNotifKey];
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-23 16:51:44 +00:00
|
|
|
[updatedItemsDict setObject:[NSNumber numberWithBool:roomNotifSwitch.on] forKey:kRoomSettingsMuteNotifKey];
|
2015-12-15 17:17:20 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-30 11:30:53 +00:00
|
|
|
else if (theSwitch == directoryVisibilitySwitch)
|
|
|
|
{
|
|
|
|
MXRoomDirectoryVisibility visibility = directoryVisibilitySwitch.on ? kMXRoomDirectoryVisibilityPublic : kMXRoomDirectoryVisibilityPrivate;
|
|
|
|
|
|
|
|
// Check whether the actual settings has been retrieved
|
|
|
|
if (actualDirectoryVisibility)
|
|
|
|
{
|
|
|
|
if ([visibility isEqualToString:actualDirectoryVisibility])
|
|
|
|
{
|
|
|
|
[updatedItemsDict removeObjectForKey:kRoomSettingsDirectoryKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:visibility forKey:kRoomSettingsDirectoryKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[updatedItemsDict setObject:visibility forKey:kRoomSettingsDirectoryKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 12:58:17 +00:00
|
|
|
|
|
|
|
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
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
|
|
|
|
|
|
|
|
|