Tap on a contact invite you to start a chat with

This commit is contained in:
ylecollen 2015-01-20 18:40:55 +01:00
parent 590886a99a
commit 3baa245871
2 changed files with 73 additions and 2 deletions

View file

@ -83,7 +83,7 @@
710210A31A67A4B600364868 /* ConsoleGrowingTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConsoleGrowingTextView.m; sourceTree = "<group>"; };
710CC3BE1A6E9F14006EE973 /* matrixUser.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = matrixUser.png; sourceTree = "<group>"; };
71193D231A6D64F900E59A9E /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
71193D271A6E3DC000E59A9E /* ContactsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ContactsViewController.h; path = ViewController/ContactsViewController.h; sourceTree = "<group>"; };
71193D271A6E3DC000E59A9E /* ContactsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactsViewController.h; sourceTree = "<group>"; };
71193D281A6E3DC000E59A9E /* ContactsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactsViewController.m; sourceTree = "<group>"; };
71193D2A1A6E433900E59A9E /* ContactTableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactTableCell.h; sourceTree = "<group>"; };
71193D2B1A6E433900E59A9E /* ContactTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactTableCell.m; sourceTree = "<group>"; };
@ -258,6 +258,7 @@
F03EF5E919F171EB00A0EE52 /* ViewController */ = {
isa = PBXGroup;
children = (
71193D271A6E3DC000E59A9E /* ContactsViewController.h */,
71193D281A6E3DC000E59A9E /* ContactsViewController.m */,
F03EF5EA19F171EB00A0EE52 /* HomeViewController.h */,
F03EF5EB19F171EB00A0EE52 /* HomeViewController.m */,
@ -356,7 +357,6 @@
F04EE51E1A3A01D500C64930 /* APNSHandler.m */,
F07A80D919DD9DE700B621A1 /* AppDelegate.h */,
F07A80DA19DD9DE700B621A1 /* AppDelegate.m */,
71193D271A6E3DC000E59A9E /* ContactsViewController.h */,
F0D3C30A1A011EF10000D49E /* AppSettings.h */,
F0D3C30B1A011EF10000D49E /* AppSettings.m */,
F03C470F1A02952800E445AB /* CustomAlert.h */,

View file

@ -21,6 +21,15 @@
#import "ContactTableCell.h"
#import "CustomAlert.h"
#import "MatrixHandler.h"
#import "AppDelegate.h"
@interface ContactsViewController ()
@property (strong, nonatomic) CustomAlert *startChatMenu;
@end
@implementation ContactsViewController
- (void)viewDidLoad {
@ -131,6 +140,68 @@
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ConsoleContact* contact = nil;
if (indexPath.section < sectionedContacts.sectionedContacts.count) {
NSArray *thisSection = [sectionedContacts.sectionedContacts objectAtIndex:indexPath.section];
if (indexPath.row < thisSection.count) {
contact = [thisSection objectAtIndex:indexPath.row];
}
}
NSArray* matrixIDs = contact.matrixIdentifiers;
if (matrixIDs.count) {
// Display action menu: Add attachments, Invite user...
__weak typeof(self) weakSelf = self;
NSString* matrixID = [matrixIDs objectAtIndex:0];
self.startChatMenu = [[CustomAlert alloc] initWithTitle:[NSString stringWithFormat:@"Start chat with %@", matrixID] message:nil style:CustomAlertStyleAlert];
[self.startChatMenu addActionWithTitle:@"Cancel" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
weakSelf.startChatMenu = nil;
}];
[self.startChatMenu addActionWithTitle:@"OK" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
weakSelf.startChatMenu = nil;
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
// else create new room
[mxHandler.mxRestClient createRoom:nil
visibility:kMXRoomVisibilityPrivate
roomAlias:nil
topic:nil
success:^(MXCreateRoomResponse *response) {
// add the user
[mxHandler.mxRestClient inviteUser:matrixID toRoom:response.roomId success:^{
} failure:^(NSError *error) {
NSLog(@"%@ invitation failed (roomId: %@): %@", matrixID, 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];
}];
}];
[self.startChatMenu showInViewController:self];
}
}
#pragma mark - Actions
- (void)onContactsRefresh:(NSNotification *)notif {