Move startPrivateOneToOneRoomWithUserId from MatrixHandler to AppDelegate.

This commit is contained in:
giomfo 2015-05-04 14:49:30 +02:00
parent 69c90c9c95
commit 02fd35292d
7 changed files with 63 additions and 49 deletions

View file

@ -23,8 +23,7 @@
+ (MatrixHandler *)sharedHandler;
// Reopens an existing private OneToOne room with this userId or creates a new one (if it doesn't exist)
- (void)startPrivateOneToOneRoomWithUserId:(NSString*)userId;
// user power level in a dedicated room
- (CGFloat)getPowerLevel:(MXRoomMember *)roomMember inRoom:(MXRoom *)room;

View file

@ -49,43 +49,6 @@ static MatrixHandler *sharedHandler = nil;
#pragma mark - Room handling
- (void)startPrivateOneToOneRoomWithUserId:(NSString*)userId {
if (self.mxRestClient) {
MXRoom* mxRoom = [self.mxSession privateOneToOneRoomWithUserId:userId];
// if the room exists
if (mxRoom) {
// open it
[[AppDelegate theDelegate].masterTabBarController showRoom:mxRoom.state.roomId];
} else {
// create a new room
[self.mxSession createRoom:nil
visibility:kMXRoomVisibilityPrivate
roomAlias:nil
topic:nil
success:^(MXRoom *room) {
// invite the other user only if it is defined and not onself
if (userId && ![self.mxSession.myUser.userId isEqualToString:userId]) {
// add the user
[room inviteUser:userId success:^{
} failure:^(NSError *error) {
NSLog(@"[MatrixHandler] %@ invitation failed (roomId: %@): %@", userId, room.state.roomId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
// Open created room
[[AppDelegate theDelegate].masterTabBarController showRoom:room.state.roomId];
} failure:^(NSError *error) {
NSLog(@"[MatrixHandler] Create room failed: %@", error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
}
}
- (CGFloat)getPowerLevel:(MXRoomMember *)roomMember inRoom:(MXRoom *)room {
CGFloat powerLevel = 0;

View file

@ -44,5 +44,12 @@
- (MXKAlert*)showErrorAsAlert:(NSError*)error;
/**
Reopen an existing private OneToOne room with this userId or creates a new one (if it doesn't exist)
@param userId
*/
- (void)startPrivateOneToOneRoomWithUserId:(NSString*)userId;
@end

View file

@ -532,6 +532,55 @@
}
}
#pragma mark - Matrix Rooms handling
- (void)startPrivateOneToOneRoomWithUserId:(NSString*)userId {
// TODO GFO: handle here multi sessions
NSArray *mxAccounts = [MXKAccountManager sharedManager].accounts;
if (mxAccounts.count) {
MXKAccount *mxAccount = mxAccounts.firstObject;
MXSession *mxSession = mxAccount.mxSession;
if (mxSession) {
MXRoom* mxRoom = [mxSession privateOneToOneRoomWithUserId:userId];
// if the room exists
if (mxRoom) {
// open it
[self.masterTabBarController showRoom:mxRoom.state.roomId];
} else {
// create a new room
[mxSession createRoom:nil
visibility:kMXRoomVisibilityPrivate
roomAlias:nil
topic:nil
success:^(MXRoom *room) {
// invite the other user only if it is defined and not onself
if (userId && ![mxSession.myUser.userId isEqualToString:userId]) {
// add the user
[room inviteUser:userId success:^{
} failure:^(NSError *error) {
NSLog(@"[AppDelegate] %@ invitation failed (roomId: %@): %@", userId, room.state.roomId, error);
//Alert user
[self showErrorAsAlert:error];
}];
}
// Open created room
[self.masterTabBarController showRoom:room.state.roomId];
} failure:^(NSError *error) {
NSLog(@"[AppDelegate] Create room failed: %@", error);
//Alert user
[self showErrorAsAlert:error];
}];
}
}
}
}
#pragma mark - SplitViewController delegate
- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {

View file

@ -18,7 +18,7 @@
#import "ContactDetailsTableCell.h"
#import "MatrixHandler.h"
#import "AppDelegate.h"
#import "RageShakeManager.h"
@ -110,7 +110,7 @@
if ([view isKindOfClass:[ContactDetailsTableCell class]]) {
dispatch_async(dispatch_get_main_queue(), ^{
[[MatrixHandler sharedHandler] startPrivateOneToOneRoomWithUserId:((ContactDetailsTableCell*)view).matrixUserIDLabel.text];
[[AppDelegate theDelegate] startPrivateOneToOneRoomWithUserId:((ContactDetailsTableCell*)view).matrixUserIDLabel.text];
});
}
}

View file

@ -18,7 +18,6 @@
// application info
#import "AppDelegate.h"
#import "MatrixHandler.h"
// contacts management
#import "ContactManager.h"
@ -370,7 +369,6 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl
__weak typeof(self) weakSelf = self;
NSArray* matrixIDs = contact.matrixIdentifiers;
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
// matrix user ?
if (matrixIDs.count) {
@ -390,7 +388,7 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl
[self.startChatMenu addActionWithTitle:@"OK" style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
weakSelf.startChatMenu = nil;
[mxHandler startPrivateOneToOneRoomWithUserId:matrixID];
[[AppDelegate theDelegate] startPrivateOneToOneRoomWithUserId:matrixID];
}];
} else {
self.startChatMenu = [[MXKAlert alloc] initWithTitle:[NSString stringWithFormat:@"Chat with "] message:nil style:MXKAlertStyleActionSheet];
@ -399,7 +397,7 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl
[self.startChatMenu addActionWithTitle:matrixID style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
weakSelf.startChatMenu = nil;
[mxHandler startPrivateOneToOneRoomWithUserId:matrixID];
[[AppDelegate theDelegate] startPrivateOneToOneRoomWithUserId:matrixID];
}];
}

View file

@ -190,8 +190,7 @@
if (_mxRoomMember.avatarUrl) {
// Suppose this url is a matrix content uri, we use SDK to get the well adapted thumbnail from server
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
thumbnailURL = [mxHandler.mxSession.matrixRestClient urlOfContentThumbnail:_mxRoomMember.avatarUrl toFitViewSize:self.memberThumbnailButton.frame.size withMethod:MXThumbnailingMethodCrop];
thumbnailURL = [self.mxSession.matrixRestClient urlOfContentThumbnail:_mxRoomMember.avatarUrl toFitViewSize:self.memberThumbnailButton.frame.size withMethod:MXThumbnailingMethodCrop];
NSString *cacheFilePath = [MXKMediaManager cachePathForMediaWithURL:thumbnailURL inFolder:kMXKMediaManagerAvatarThumbnailFolder];
// Check whether the image download is in progress
@ -266,7 +265,6 @@
}
- (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];
@ -527,7 +525,7 @@
} else if ([text isEqualToString:@"Start Chat"]) {
[self addPendingActionMask];
[[MatrixHandler sharedHandler] startPrivateOneToOneRoomWithUserId:_mxRoomMember.userId];
[[AppDelegate theDelegate] startPrivateOneToOneRoomWithUserId:_mxRoomMember.userId];
}
}
}