First implementation (incomplete)

This commit is contained in:
ylecollen 2014-12-23 18:51:49 +01:00
parent 8f7ed9b1a1
commit 2d3e54463b
7 changed files with 598 additions and 45 deletions

View file

@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
71D2E4EC1A49814B000DE015 /* MemberActionsCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 71D2E4EB1A49814B000DE015 /* MemberActionsCell.m */; };
71DB9DC11A495B6400504A09 /* MemberViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71DB9DC01A495B6400504A09 /* MemberViewController.m */; };
D648B86A591308736E2D4078 /* libPods-matrixConsole.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8141B1E2401FFCC3C5B99234 /* libPods-matrixConsole.a */; };
F00B5DB91A1B9BCE00EA1C8D /* CustomImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = F00B5DB81A1B9BCE00EA1C8D /* CustomImageView.m */; };
F013EEEC1A40D437002BB093 /* matrixConsole-Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = F013EEEB1A40D437002BB093 /* matrixConsole-Defaults.plist */; };
@ -62,6 +64,10 @@
/* Begin PBXFileReference section */
13057A57E74FD5504196F47F /* Pods-matrixConsole.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-matrixConsole.release.xcconfig"; path = "Pods/Target Support Files/Pods-matrixConsole/Pods-matrixConsole.release.xcconfig"; sourceTree = "<group>"; };
71D2E4EA1A49814B000DE015 /* MemberActionsCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemberActionsCell.h; sourceTree = "<group>"; };
71D2E4EB1A49814B000DE015 /* MemberActionsCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MemberActionsCell.m; sourceTree = "<group>"; };
71DB9DBF1A495B6400504A09 /* MemberViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemberViewController.h; sourceTree = "<group>"; };
71DB9DC01A495B6400504A09 /* MemberViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MemberViewController.m; sourceTree = "<group>"; };
8141B1E2401FFCC3C5B99234 /* libPods-matrixConsole.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-matrixConsole.a"; sourceTree = BUILT_PRODUCTS_DIR; };
B7EC7E45C718BF2BBCE0CF48 /* Pods-matrixConsole.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-matrixConsole.debug.xcconfig"; path = "Pods/Target Support Files/Pods-matrixConsole/Pods-matrixConsole.debug.xcconfig"; sourceTree = "<group>"; };
F00B5DB71A1B9BCE00EA1C8D /* CustomImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomImageView.h; sourceTree = "<group>"; };
@ -197,6 +203,8 @@
F03EF5ED19F171EB00A0EE52 /* LoginViewController.m */,
F03EF5EE19F171EB00A0EE52 /* MasterTabBarController.h */,
F03EF5EF19F171EB00A0EE52 /* MasterTabBarController.m */,
71DB9DBF1A495B6400504A09 /* MemberViewController.h */,
71DB9DC01A495B6400504A09 /* MemberViewController.m */,
F03EF5F019F171EB00A0EE52 /* RecentsViewController.h */,
F03EF5F119F171EB00A0EE52 /* RecentsViewController.m */,
F03EF5F219F171EB00A0EE52 /* RoomViewController.h */,
@ -212,6 +220,8 @@
children = (
F00B5DB71A1B9BCE00EA1C8D /* CustomImageView.h */,
F00B5DB81A1B9BCE00EA1C8D /* CustomImageView.m */,
71D2E4EA1A49814B000DE015 /* MemberActionsCell.h */,
71D2E4EB1A49814B000DE015 /* MemberActionsCell.m */,
F0E84D3E1A1F9AEC005F2E42 /* RecentsTableViewCell.h */,
F0E84D3F1A1F9AEC005F2E42 /* RecentsTableViewCell.m */,
F02D707419F1DC9E007B47D3 /* RoomMemberTableCell.h */,
@ -471,6 +481,7 @@
F03EF5FA19F171EB00A0EE52 /* RoomViewController.m in Sources */,
F03EF5F819F171EB00A0EE52 /* MasterTabBarController.m in Sources */,
F03EF5F619F171EB00A0EE52 /* HomeViewController.m in Sources */,
71DB9DC11A495B6400504A09 /* MemberViewController.m in Sources */,
F0D942F61A31F3A300826CC1 /* RecentRoom.m in Sources */,
F03EF60219F19E7C00A0EE52 /* MediaManager.m in Sources */,
F03EF5F919F171EB00A0EE52 /* RecentsViewController.m in Sources */,
@ -483,6 +494,7 @@
F0D3C30C1A011EF10000D49E /* AppSettings.m in Sources */,
F03EF5F719F171EB00A0EE52 /* LoginViewController.m in Sources */,
F0D3C30F1A01330F0000D49E /* SettingsTableViewCell.m in Sources */,
71D2E4EC1A49814B000DE015 /* MemberActionsCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -5,6 +5,7 @@
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<scenes>
<!--Recents-->
@ -345,6 +346,7 @@
<outlet property="pictureView" destination="RW8-nh-DTj" id="1Lk-bd-tKv"/>
<outlet property="powerContainer" destination="wDo-tA-Ar7" id="sub-O0-L9d"/>
<outlet property="userLabel" destination="uVK-4R-arl" id="OhP-VD-vj0"/>
<segue destination="qlN-Mb-ZH7" kind="show" identifier="showMemberSheet" id="QMI-Ay-tFz"/>
</connections>
</tableViewCell>
</prototypes>
@ -445,6 +447,108 @@
</objects>
<point key="canvasLocation" x="1595" y="75"/>
</scene>
<!--DetailMember-->
<scene sceneID="q1J-Wz-aLa">
<objects>
<tableViewController id="qlN-Mb-ZH7" userLabel="DetailMember" customClass="MemberViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="euy-fV-mSK">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<view key="tableHeaderView" contentMode="scaleToFill" id="Dog-RG-0F9" userLabel="TableHeaderView">
<rect key="frame" x="0.0" y="64" width="600" height="100"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleAspectFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="PLk-7G-Li9" userLabel="PicturePickerButton">
<rect key="frame" x="10" y="12" width="75" height="75"/>
<constraints>
<constraint firstAttribute="width" secondItem="PLk-7G-Li9" secondAttribute="height" multiplier="1:1" id="BDm-oa-tFY"/>
<constraint firstAttribute="width" constant="75" id="PEb-3J-Qb3"/>
<constraint firstAttribute="height" constant="75" id="u7H-gw-Ry4"/>
</constraints>
<state key="normal" image="default-profile.png">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
</button>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" bounces="NO" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" editable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="e5s-dh-H4J">
<rect key="frame" x="95" y="-26" width="495" height="151"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="e5s-dh-H4J" firstAttribute="leading" secondItem="Dog-RG-0F9" secondAttribute="leading" constant="95" id="0qf-mY-DBa"/>
<constraint firstAttribute="centerY" secondItem="e5s-dh-H4J" secondAttribute="centerY" id="Bb2-vL-ktJ"/>
<constraint firstAttribute="trailing" secondItem="e5s-dh-H4J" secondAttribute="trailing" constant="10" id="aQ9-eM-Pzu"/>
<constraint firstAttribute="centerY" secondItem="PLk-7G-Li9" secondAttribute="centerY" id="kjF-HV-ZXu"/>
<constraint firstItem="PLk-7G-Li9" firstAttribute="leading" secondItem="Dog-RG-0F9" secondAttribute="leading" constant="10" id="vp2-QW-00a"/>
</constraints>
</view>
<prototypes>
<tableViewCell contentMode="scaleToFill" restorationIdentifier="MemberActionsCell" selectionStyle="default" indentationWidth="10" reuseIdentifier="MemberActionsCell" id="zRe-DS-U67" customClass="MemberActionsCell">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="zRe-DS-U67" id="C5i-Xc-2Zi">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1wm-Iq-0AV">
<rect key="frame" x="30" y="5" width="240" height="34"/>
<state key="normal" title="LeftButton">
<color key="titleColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="onButtonToggle:" destination="qlN-Mb-ZH7" eventType="touchUpInside" id="Wyh-9j-XfT"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fW1-mK-8cr" userLabel="rightButton">
<rect key="frame" x="330" y="5" width="247" height="34"/>
<state key="normal" title="rightButton">
<color key="titleColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onButtonToggle:" destination="qlN-Mb-ZH7" eventType="touchUpInside" id="qJQ-h5-V6K"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="centerY" secondItem="1wm-Iq-0AV" secondAttribute="centerY" id="1pP-t1-J2I"/>
<constraint firstAttribute="trailing" secondItem="fW1-mK-8cr" secondAttribute="trailing" constant="30" id="2Bz-HC-j4A"/>
<constraint firstItem="fW1-mK-8cr" firstAttribute="leading" secondItem="1wm-Iq-0AV" secondAttribute="trailing" constant="60" id="Dxq-lG-e5k"/>
<constraint firstAttribute="centerX" secondItem="fW1-mK-8cr" secondAttribute="centerX" multiplier="0.66" id="KzO-HL-tLc"/>
<constraint firstItem="1wm-Iq-0AV" firstAttribute="leading" secondItem="C5i-Xc-2Zi" secondAttribute="leading" constant="30" id="L8Z-iE-e3o"/>
<constraint firstAttribute="centerY" secondItem="fW1-mK-8cr" secondAttribute="centerY" id="WUV-OQ-JTN"/>
<constraint firstAttribute="centerX" secondItem="1wm-Iq-0AV" secondAttribute="centerX" multiplier="2" id="xQc-c2-Kz6"/>
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="2Bz-HC-j4A"/>
</mask>
</variation>
</tableViewCellContentView>
<connections>
<outlet property="leftButton" destination="1wm-Iq-0AV" id="aDO-vS-rnE"/>
<outlet property="rightButton" destination="fW1-mK-8cr" id="2xz-UI-18C"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="qlN-Mb-ZH7" id="ipl-VO-ZdA"/>
<outlet property="delegate" destination="qlN-Mb-ZH7" id="ceB-pW-r7c"/>
</connections>
</tableView>
<connections>
<outlet property="memberThumbnailButton" destination="PLk-7G-Li9" id="Rol-K2-IAS"/>
<outlet property="roomMemberMID" destination="e5s-dh-H4J" id="Upn-om-4du"/>
<outlet property="tableView" destination="euy-fV-mSK" id="MQl-lX-QSp"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="mrY-z4-HGF" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2297" y="74"/>
</scene>
<!--Home-->
<scene sceneID="3rt-8o-eGh">
<objects>

View file

@ -0,0 +1,27 @@
/*
Copyright 2014 OpenMarket Ltd
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.
*/
#import <UIKit/UIKit.h>
@interface MemberActionsCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIButton *rightButton;
@property (weak, nonatomic) IBOutlet UIButton *leftButton;
-(void) setLeftButtonText:(NSString*)text;
-(void) setRightButtonText:(NSString*)text;
@end

View file

@ -0,0 +1,42 @@
/*
Copyright 2014 OpenMarket Ltd
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.
*/
#import "MemberActionsCell.h"
@implementation MemberActionsCell
- (void)initButton:(UIButton*)button withText:(NSString*)text {
button.hidden = (text.length == 0);
button.layer.borderColor = [UIColor blackColor].CGColor;
button.layer.borderWidth = 1;
button.layer.cornerRadius = 5;
[button setTitle:text forState:UIControlStateNormal];
[button setTitle:text forState:UIControlStateHighlighted];
}
- (void) setLeftButtonText:(NSString*)text {
[self initButton:self.leftButton withText:text];
}
- (void) setRightButtonText:(NSString*)text {
[self initButton:self.rightButton withText:text];
}
@end

View file

@ -0,0 +1,42 @@
/*
Copyright 2014 OpenMarket Ltd
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.
*/
#import <UIKit/UIKit.h>
#import "MatrixHandler.h"
@interface MemberViewController : UITableViewController {
NSMutableArray* buttonsTitles;
UIView* pendingRequestMask;
}
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *memberThumbnailButton;
@property (weak, nonatomic) IBOutlet UITextView *roomMemberMID;
- (IBAction)onButtonToggle:(id)sender;
@property (strong, nonatomic) MXRoomMember *roomMember;
@property (strong, nonatomic) MXRoom *mxRoom;
@end

View file

@ -0,0 +1,356 @@
/*
Copyright 2014 OpenMarket Ltd
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.
*/
#import "MemberViewController.h"
#import "AppDelegate.h"
#import "MemberActionsCell.h"
#import "MediaManager.h"
@interface MemberViewController () {
id imageLoader;
id membersListener;
}
@property (strong, nonatomic) CustomAlert *actionMenu;
@end
@implementation MemberViewController
@synthesize mxRoom;
- (void)viewDidLoad {
[super viewDidLoad];
// remove the line separator color
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.rowHeight = 44;
self.tableView.allowsSelection = NO;
buttonsTitles = [[NSMutableArray alloc] init];
// ignore useless update
if (_roomMember) {
[self updateMemberInfo];
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
NSArray *mxMembersEvents = @[
kMXEventTypeStringRoomMember,
kMXEventTypeStringRoomPowerLevels
];
membersListener = [mxHandler.mxSession listenToEventsOfTypes:mxMembersEvents onEvent:^(MXEvent *event, MXEventDirection direction, id customObject) {
// consider only live event
if (direction == MXEventDirectionForwards) {
// Check the room Id (if any)
if (event.roomId && [event.roomId isEqualToString:mxRoom.state.roomId] == NO) {
// This event does not concern the current room members
return;
}
// Hide potential action sheet
if (self.actionMenu) {
[self.actionMenu dismiss:NO];
self.actionMenu = nil;
}
// Refresh members list
[self updateMemberInfo];
[self.tableView reloadData];
}
}];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (imageLoader) {
[MediaManager cancel:imageLoader];
imageLoader = nil;
}
if (membersListener) {
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
[mxHandler.mxSession removeListener:membersListener];
membersListener = nil;
}
}
- (void) updateMemberInfo {
self.title = _roomMember.displayname;
// set the thumbnail info
[[self.memberThumbnailButton imageView] setContentMode: UIViewContentModeScaleAspectFill];
[[self.memberThumbnailButton imageView] setClipsToBounds:YES];
imageLoader = [MediaManager loadPicture:_roomMember.avatarUrl
success:^(UIImage *image) {
[self.memberThumbnailButton setImage:image forState:UIControlStateNormal];
[self.memberThumbnailButton setImage:image forState:UIControlStateHighlighted];
}
failure:^(NSError *error) {
NSLog(@"Failed to download image (%@): %@", _roomMember.avatarUrl, error);
}];
self.roomMemberMID.text = _roomMember.userId;
}
- (void)setRoomMember:(MXRoomMember*) aRoomMember {
// ignore useless update
if (![self.roomMember.userId isEqualToString:aRoomMember.userId]) {
_roomMember = aRoomMember;
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
// Check user's power level before allowing an action (kick, ban, ...)
MXRoomPowerLevels *powerLevels = [mxRoom.state powerLevels];
NSUInteger memberPowerLevel = [powerLevels powerLevelOfUserWithUserID:_roomMember.userId];
NSUInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:mxHandler.userId];
[buttonsTitles removeAllObjects];
// Consider the case of the user himself
if ([_roomMember.userId isEqualToString:mxHandler.userId]) {
[buttonsTitles addObject:@"Leave"];
if (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomPowerLevels]) {
[buttonsTitles addObject:@"Set power level"];
}
} else {
// Consider membership of the selected member
switch (_roomMember.membership) {
case MXMembershipInvite:
case MXMembershipJoin: {
// Check conditions to be able to kick someone
if (oneSelfPowerLevel >= [powerLevels kick] && oneSelfPowerLevel >= memberPowerLevel) {
[buttonsTitles addObject:@"Kick"];
}
// Check conditions to be able to ban someone
if (oneSelfPowerLevel >= [powerLevels ban] && oneSelfPowerLevel >= memberPowerLevel) {
[buttonsTitles addObject:@"Ban"];
}
break;
}
case MXMembershipLeave: {
// Check conditions to be able to invite someone
if (oneSelfPowerLevel >= [powerLevels invite]) {
[buttonsTitles addObject:@"Invite"];
}
// Check conditions to be able to ban someone
if (oneSelfPowerLevel >= [powerLevels ban] && oneSelfPowerLevel >= memberPowerLevel) {
[buttonsTitles addObject:@"Ban"];
}
break;
}
case MXMembershipBan: {
// Check conditions to be able to unban someone
if (oneSelfPowerLevel >= [powerLevels ban] && oneSelfPowerLevel >= memberPowerLevel) {
[buttonsTitles addObject:@"Ban"];
}
break;
}
default: {
break;
}
}
// update power level
if (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomPowerLevels]) {
[buttonsTitles addObject:@"Set power level"];
}
[buttonsTitles addObject:@"Start chat"];
}
return (buttonsTitles.count + 1) / 2;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.tableView == aTableView) {
NSInteger row = indexPath.row;
MemberActionsCell* memberActionsCell = (MemberActionsCell*)[aTableView dequeueReusableCellWithIdentifier:@"MemberActionsCell" forIndexPath:indexPath];
NSString* leftTitle = nil;
NSString* rightTitle = nil;
if ((row * 2) < buttonsTitles.count) {
leftTitle = [buttonsTitles objectAtIndex:row * 2];
}
if (((row * 2) + 1) < buttonsTitles.count) {
rightTitle = [buttonsTitles objectAtIndex:(row * 2) + 1];
}
[memberActionsCell setLeftButtonText:leftTitle];
[memberActionsCell setRightButtonText:rightTitle];
return memberActionsCell;
}
return nil;
}
#pragma mark - button management
- (void) updateUserPowerLevel:(MXRoomMember*)roomMember
{
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
__weak typeof(self) weakSelf = self;
// Ask for userId to invite
self.actionMenu = [[CustomAlert alloc] initWithTitle:@"Power Level" message:nil style:CustomAlertStyleAlert];
if (![mxHandler.userId isEqualToString:roomMember.userId]) {
self.actionMenu.cancelButtonIndex = [self.actionMenu addActionWithTitle:@"Reset to default" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
weakSelf.actionMenu = nil;
// Reset user power level
[weakSelf.mxRoom setPowerLevelOfUserWithUserID:roomMember.userId powerLevel:0 success:^{
} failure:^(NSError *error) {
NSLog(@"Reset user power (%@) failed: %@", roomMember.userId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}];
}
[self.actionMenu addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = NO;
textField.text = [NSString stringWithFormat:@"%d", (int)([mxHandler getPowerLevel:roomMember inRoom:weakSelf.mxRoom] * 100)];
textField.placeholder = nil;
textField.keyboardType = UIKeyboardTypeDecimalPad;
}];
[self.actionMenu addActionWithTitle:@"OK" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
UITextField *textField = [alert textFieldAtIndex:0];
weakSelf.actionMenu = nil;
// Set user power level
[weakSelf.mxRoom setPowerLevelOfUserWithUserID:roomMember.userId powerLevel:[textField.text integerValue] success:^{
} failure:^(NSError *error) {
NSLog(@"Set user power (%@) failed: %@", roomMember.userId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}];
[self.actionMenu showInViewController:self];
}
- (IBAction)onButtonToggle:(id)sender {
if ([sender isKindOfClass:[UIButton class]]) {
NSString* text = ((UIButton*)sender).titleLabel.text;
if ([text isEqualToString:@"Leave"]) {
[self.mxRoom leave:^{
// Back to recents
[[AppDelegate theDelegate].masterTabBarController popRoomViewControllerAnimated:YES];
} failure:^(NSError *error) {
NSLog(@"Leave room %@ failed: %@", mxRoom.state.roomId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
} else if ([text isEqualToString:@"Set power level"]) {
[self updateUserPowerLevel:_roomMember];
} else if ([text isEqualToString:@"Kick"]) {
[mxRoom kickUser:_roomMember.userId
reason:nil
success:^{
}
failure:^(NSError *error) {
NSLog(@"Kick %@ failed: %@", _roomMember.userId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
} else if ([text isEqualToString:@"Ban"]) {
[mxRoom banUser:_roomMember.userId
reason:nil
success:^{
}
failure:^(NSError *error) {
NSLog(@"Ban %@ failed: %@", _roomMember.userId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
} else if ([text isEqualToString:@"Invite"]) {
[mxRoom inviteUser:_roomMember.userId
success:^{
}
failure:^(NSError *error) {
NSLog(@"Invite %@ failed: %@", _roomMember.userId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
} else if ([text isEqualToString:@"Unban"]) {
[mxRoom unbanUser:_roomMember.userId
success:^{
}
failure:^(NSError *error) {
NSLog(@"Unban %@ failed: %@", _roomMember.userId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
} else if ([text isEqualToString:@"Start chat"]) {
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
// Create new room
[mxHandler.mxRestClient createRoom:(_roomMember.displayname) ? _roomMember.displayname : _roomMember.userId
visibility:kMXRoomVisibilityPrivate
roomAlias:nil
topic:nil
success:^(MXCreateRoomResponse *response) {
// add the user
[mxHandler.mxRestClient inviteUser:_roomMember.userId toRoom:response.roomId success:^{
//NSLog(@"%@ has been invited (roomId: %@)", roomMember.userId, response.roomId);
} failure:^(NSError *error) {
NSLog(@"%@ invitation failed (roomId: %@): %@", _roomMember.userId, response.roomId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
// Open created room
[[AppDelegate theDelegate].masterTabBarController showRoom:response.roomId];
} failure:^(NSError *error) {
NSLog(@"Create room failed: %@", error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
}
}
@end

View file

@ -18,6 +18,7 @@
#import <MediaPlayer/MediaPlayer.h>
#import "RoomViewController.h"
#import "MemberViewController.h"
#import "RoomMessage.h"
#import "RoomMessageTableCell.h"
#import "RoomMemberTableCell.h"
@ -1426,53 +1427,10 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
#pragma mark - UITableView delegate
- (void) updateUserPowerLevel:(MXRoomMember*)roomMember
{
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
__weak typeof(self) weakSelf = self;
// Ask for userId to invite
self.actionMenu = [[CustomAlert alloc] initWithTitle:@"Power Level" message:nil style:CustomAlertStyleAlert];
if (![mxHandler.userId isEqualToString:roomMember.userId]) {
self.actionMenu.cancelButtonIndex = [self.actionMenu addActionWithTitle:@"Reset to default" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
weakSelf.actionMenu = nil;
// Reset user power level
[weakSelf.mxRoom setPowerLevelOfUserWithUserID:roomMember.userId powerLevel:0 success:^{
} failure:^(NSError *error) {
NSLog(@"Reset user power (%@) failed: %@", roomMember.userId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}];
}
[self.actionMenu addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = NO;
textField.text = [NSString stringWithFormat:@"%d", (int)([mxHandler getPowerLevel:roomMember inRoom:weakSelf.mxRoom] * 100)];
textField.placeholder = nil;
textField.keyboardType = UIKeyboardTypeDecimalPad;
}];
[self.actionMenu addActionWithTitle:@"OK" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
UITextField *textField = [alert textFieldAtIndex:0];
weakSelf.actionMenu = nil;
// Set user power level
[weakSelf.mxRoom setPowerLevelOfUserWithUserID:roomMember.userId powerLevel:[textField.text integerValue] success:^{
} failure:^(NSError *error) {
NSLog(@"Set user power (%@) failed: %@", roomMember.userId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}];
[self.actionMenu showInViewController:self];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Check table view members vs messages
if (tableView == self.membersTableView) {
/*
// List action(s) available on this member
__block MXRoomMember *roomMember = [members objectAtIndex:indexPath.row];
@ -1679,7 +1637,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
weakSelf.actionMenu = nil;
}];
[self.actionMenu showInViewController:self];
}
}*/
[tableView deselectRowAtIndexPath:indexPath animated:YES];
} else if (tableView == self.messagesTableView) {
// Dismiss keyboard when user taps on messages table view content
@ -2525,6 +2483,18 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
- (void)dismissMediaPicker {
[[AppDelegate theDelegate].masterTabBarController dismissMediaPicker];
}
#pragma mark - Segues
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showMemberSheet"]) {
NSIndexPath *indexPath = [self.membersTableView indexPathForSelectedRow];
MemberViewController* controller = [segue destinationViewController];
controller.roomMember = [members objectAtIndex:indexPath.row];
}
}
@end