mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
1 - add MatrixSDKHandler::createPrivateOneToOneRoomWith
2 - can start chat with any matrix ID contained in a contact.
This commit is contained in:
parent
0f045f0bf9
commit
2e4112d94b
4 changed files with 72 additions and 66 deletions
|
@ -75,6 +75,9 @@ typedef enum : NSUInteger {
|
|||
// return a MatrixIDs list of 1:1 room members
|
||||
- (NSArray*)oneToOneRoomMemberMatrixIDs;
|
||||
|
||||
// create a private one to one chat room
|
||||
- (void)createPrivateOneToOneRoomWith:(NSString*)otherMatrixID;
|
||||
|
||||
// Return the suitable url to display the content thumbnail into the provided view size
|
||||
// Note: the provided view size is supposed in points, this method will convert this size in pixels by considering screen scale
|
||||
- (NSString*)thumbnailURLForContent:(NSString*)contentURI inViewSize:(CGSize)viewSize withMethod:(MXThumbnailingMethod)thumbnailingMethod;
|
||||
|
|
|
@ -542,6 +542,38 @@ static MatrixSDKHandler *sharedHandler = nil;
|
|||
return matrixIDs;
|
||||
}
|
||||
|
||||
// create a private one to one chat room
|
||||
- (void)createPrivateOneToOneRoomWith:(NSString*)otherMatrixID {
|
||||
// sanity check
|
||||
if (self.mxRestClient) {
|
||||
[self.mxRestClient createRoom:nil
|
||||
visibility:kMXRoomVisibilityPrivate
|
||||
roomAlias:nil
|
||||
topic:nil
|
||||
success:^(MXCreateRoomResponse *response) {
|
||||
|
||||
// invite the other user only if it is defined and not onself
|
||||
if (otherMatrixID && ![self.userId isEqualToString:otherMatrixID]) {
|
||||
// add the user
|
||||
[self.mxRestClient inviteUser:otherMatrixID toRoom:response.roomId success:^{
|
||||
} failure:^(NSError *error) {
|
||||
NSLog(@"%@ invitation failed (roomId: %@): %@", otherMatrixID, 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];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString*)thumbnailURLForContent:(NSString*)contentURI inViewSize:(CGSize)viewSize withMethod:(MXThumbnailingMethod)thumbnailingMethod {
|
||||
// Suppose this url is a matrix content uri, we use SDK to get the well adapted thumbnail from server
|
||||
// Convert first the provided size in pixels
|
||||
|
|
|
@ -248,52 +248,48 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl
|
|||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
NSArray* matrixIDs = contact.matrixIdentifiers;
|
||||
|
||||
|
||||
// matrix user ?
|
||||
if (matrixIDs.count) {
|
||||
// Display action menu: Add attachments, Invite user...
|
||||
|
||||
NSString* matrixID = [matrixIDs objectAtIndex:0];
|
||||
MatrixSDKHandler* mxHandler = [MatrixSDKHandler sharedHandler];
|
||||
|
||||
// display only if the matrix SDk is ready
|
||||
if ((mxHandler.status == MatrixSDKHandlerStatusServerSyncDone) || (mxHandler.status == MatrixSDKHandlerStatusStoreDataReady)) {
|
||||
// only 1 matrix ID
|
||||
if (matrixIDs.count == 1) {
|
||||
NSString* matrixID = [matrixIDs objectAtIndex:0];
|
||||
|
||||
self.startChatMenu = [[MXCAlert alloc] initWithTitle:[NSString stringWithFormat:@"Start chat with %@", matrixID] message:nil style:MXCAlertStyleAlert];
|
||||
|
||||
[self.startChatMenu addActionWithTitle:@"Cancel" style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
|
||||
weakSelf.startChatMenu = nil;
|
||||
}];
|
||||
|
||||
[self.startChatMenu addActionWithTitle:@"OK" style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
|
||||
weakSelf.startChatMenu = nil;
|
||||
|
||||
MatrixSDKHandler *mxHandler = [MatrixSDKHandler 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 = [[MXCAlert alloc] initWithTitle:[NSString stringWithFormat:@"Start chat with %@", matrixID] message:nil style:MXCAlertStyleAlert];
|
||||
|
||||
}];
|
||||
|
||||
[self.startChatMenu showInViewController:self];
|
||||
[self.startChatMenu addActionWithTitle:@"Cancel" style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
|
||||
weakSelf.startChatMenu = nil;
|
||||
}];
|
||||
|
||||
[self.startChatMenu addActionWithTitle:@"OK" style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
|
||||
weakSelf.startChatMenu = nil;
|
||||
|
||||
[mxHandler createPrivateOneToOneRoomWith:matrixID];
|
||||
}];
|
||||
} else {
|
||||
self.startChatMenu = [[MXCAlert alloc] initWithTitle:[NSString stringWithFormat:@"Start chat with "] message:nil style:MXCAlertStyleActionSheet];
|
||||
|
||||
for(NSString* matrixID in matrixIDs) {
|
||||
[self.startChatMenu addActionWithTitle:matrixID style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
|
||||
weakSelf.startChatMenu = nil;
|
||||
|
||||
[mxHandler createPrivateOneToOneRoomWith:matrixID];
|
||||
}];
|
||||
}
|
||||
|
||||
[self.startChatMenu addActionWithTitle:@"Cancel" style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
|
||||
weakSelf.startChatMenu = nil;
|
||||
}];
|
||||
}
|
||||
|
||||
[self.startChatMenu showInViewController:self];
|
||||
}
|
||||
} else {
|
||||
// invite to use matrix
|
||||
if (([MFMessageComposeViewController canSendText] ? contact.emailAddresses.count : 0) + (contact.phoneNumbers.count > 0)) {
|
||||
|
|
|
@ -509,32 +509,7 @@
|
|||
[[AppDelegate theDelegate].masterTabBarController showRoom:roomId];
|
||||
}
|
||||
else {
|
||||
// else create new room
|
||||
[mxHandler.mxRestClient createRoom:nil
|
||||
visibility:kMXRoomVisibilityPrivate
|
||||
roomAlias:nil
|
||||
topic:nil
|
||||
success:^(MXCreateRoomResponse *response) {
|
||||
[self removePendingActionMask];
|
||||
|
||||
// add the user
|
||||
[mxHandler.mxRestClient inviteUser:_mxRoomMember.userId toRoom:response.roomId success:^{
|
||||
//NSLog(@"%@ has been invited (roomId: %@)", roomMember.userId, response.roomId);
|
||||
} failure:^(NSError *error) {
|
||||
NSLog(@"%@ invitation failed (roomId: %@): %@", _mxRoomMember.userId, response.roomId, error);
|
||||
//Alert user
|
||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
}];
|
||||
|
||||
// Open created room
|
||||
[[AppDelegate theDelegate].masterTabBarController showRoom:response.roomId];
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
[self removePendingActionMask];
|
||||
NSLog(@"Create room failed: %@", error);
|
||||
//Alert user
|
||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
}];
|
||||
[mxHandler createPrivateOneToOneRoomWith:_mxRoomMember.userId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue