diff --git a/Vector.xcodeproj/project.pbxproj b/Vector.xcodeproj/project.pbxproj index 982aeeb43..4e18ea59a 100644 --- a/Vector.xcodeproj/project.pbxproj +++ b/Vector.xcodeproj/project.pbxproj @@ -202,6 +202,8 @@ F09EE0091C5134BE0078712F /* RoomOutgoingTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F09EE0011C5134BE0078712F /* RoomOutgoingTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.xib */; }; F0A1CD221B9F4BBA00F9C15C /* RoomParticipantsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0A1CD211B9F4BBA00F9C15C /* RoomParticipantsViewController.m */; }; F0A2413A1CB7E28F00E150C3 /* RoomParticipantsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0A241391CB7E28F00E150C3 /* RoomParticipantsViewController.xib */; }; + F0AF11F51D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F0AF11F31D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.m */; }; + F0AF11F61D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0AF11F41D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.xib */; }; F0BE3DF01C6CE17200AC3111 /* RoomMemberDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0BE3DEF1C6CE17200AC3111 /* RoomMemberDetailsViewController.m */; }; F0BE3DF21C6CE28300AC3111 /* RoomMemberDetailsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0BE3DF11C6CE28300AC3111 /* RoomMemberDetailsViewController.xib */; }; F0C34B611C15C28300C36F09 /* RoomOutgoingAttachmentBubbleCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F0C34B561C15C28300C36F09 /* RoomOutgoingAttachmentBubbleCell.m */; }; @@ -522,6 +524,9 @@ F0A1CD201B9F4BBA00F9C15C /* RoomParticipantsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomParticipantsViewController.h; sourceTree = ""; }; F0A1CD211B9F4BBA00F9C15C /* RoomParticipantsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomParticipantsViewController.m; sourceTree = ""; }; F0A241391CB7E28F00E150C3 /* RoomParticipantsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RoomParticipantsViewController.xib; sourceTree = ""; }; + F0AF11F21D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomIdOrAliasTableViewCell.h; sourceTree = ""; }; + F0AF11F31D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomIdOrAliasTableViewCell.m; sourceTree = ""; }; + F0AF11F41D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RoomIdOrAliasTableViewCell.xib; sourceTree = ""; }; F0BE3DEE1C6CE17200AC3111 /* RoomMemberDetailsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomMemberDetailsViewController.h; sourceTree = ""; }; F0BE3DEF1C6CE17200AC3111 /* RoomMemberDetailsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomMemberDetailsViewController.m; sourceTree = ""; }; F0BE3DF11C6CE28300AC3111 /* RoomMemberDetailsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RoomMemberDetailsViewController.xib; sourceTree = ""; }; @@ -783,6 +788,9 @@ F00C47821BFF77C800DBABC9 /* RoomList */ = { isa = PBXGroup; children = ( + F0AF11F21D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.h */, + F0AF11F31D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.m */, + F0AF11F41D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.xib */, 325F6A3F1C21D20F00C12F51 /* DirectoryRecentTableViewCell.h */, 325F6A401C21D20F00C12F51 /* DirectoryRecentTableViewCell.m */, 325F6A411C21D20F00C12F51 /* DirectoryRecentTableViewCell.xib */, @@ -1322,6 +1330,7 @@ F0026B531C916E68001D2C04 /* favouriteOff@2x.png in Resources */, F0BE3DF21C6CE28300AC3111 /* RoomMemberDetailsViewController.xib in Resources */, F0026B5D1C916E68001D2C04 /* notificationsOff@3x.png in Resources */, + F0AF11F61D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.xib in Resources */, F0C34CB21C16269D00C36F09 /* RoomIncomingAttachmentWithPaginationTitleBubbleCell.xib in Resources */, F0CC25671D099F30000819CA /* newmessages.png in Resources */, F03FBCCC1CBBF521000A5770 /* mod_icon@2x.png in Resources */, @@ -1506,6 +1515,7 @@ F09EE0021C5134BE0078712F /* RoomIncomingTextMsgWithoutSenderNameBubbleCell.m in Sources */, F001D76C1B821E4F00A162C3 /* MediaPickerViewController.m in Sources */, 71F7F5151C218D8900E7ED8F /* RecentCellData.m in Sources */, + F0AF11F51D1029CF00FEE52F /* RoomIdOrAliasTableViewCell.m in Sources */, F03DE2A51D0EFA6A00E8B65C /* AttachmentsViewController.m in Sources */, 71352D591C10569F001D50B0 /* AvatarGenerator.m in Sources */, 71F7F51D1C23079F00E7ED8F /* ContactTableViewCell.m in Sources */, diff --git a/Vector/Model/RoomList/RecentsDataSource.m b/Vector/Model/RoomList/RecentsDataSource.m index 7c1fe803b..815e03999 100644 --- a/Vector/Model/RoomList/RecentsDataSource.m +++ b/Vector/Model/RoomList/RecentsDataSource.m @@ -20,6 +20,7 @@ #import "VectorDesignValues.h" +#import "RoomIdOrAliasTableViewCell.h" #import "DirectoryRecentTableViewCell.h" #import "PublicRoomsDirectoryDataSource.h" @@ -41,6 +42,7 @@ NSMutableArray* conversationCellDataArray; NSMutableArray* lowPriorityCellDataArray; + NSInteger searchedRoomIdOrAliasSection; // used to display the potential room id or alias typed during search. NSInteger directorySection; NSInteger invitesSection; NSInteger favoritesSection; @@ -51,6 +53,9 @@ NSInteger shrinkedSectionsBitMask; NSMutableDictionary *roomTagsListenerByUserId; + + // The potential room id or alias typed in search input. + NSString *roomIdOrAlias; } @end @@ -66,6 +71,7 @@ conversationCellDataArray = [[NSMutableArray alloc] init]; lowPriorityCellDataArray = [[NSMutableArray alloc] init]; + searchedRoomIdOrAliasSection = -1; directorySection = -1; invitesSection = -1; favoritesSection = -1; @@ -253,7 +259,11 @@ { NSUInteger count = 0; - if (section == directorySection) + if (section == searchedRoomIdOrAliasSection) + { + count = 1; + } + else if (section == directorySection) { count = 1; } @@ -291,7 +301,7 @@ { UIView *sectionHeader = nil; - if (section < sectionsCount) + if (section < sectionsCount && section != searchedRoomIdOrAliasSection) { NSString* sectionTitle = @""; NSInteger sectionBitwise = 0; @@ -374,14 +384,26 @@ return sectionHeader; } -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)anIndexPath +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)theIndexPath { - NSIndexPath* indexPath = anIndexPath; - - // For the cell showing the public rooms directory search result, - // skip the MatrixKit mechanism and return directly the UITableViewCell - if (indexPath.section == directorySection) + NSIndexPath* indexPath = theIndexPath; + + if (indexPath.section == searchedRoomIdOrAliasSection) { + RoomIdOrAliasTableViewCell *roomIdOrAliasCell = [tableView dequeueReusableCellWithIdentifier:RoomIdOrAliasTableViewCell.defaultReuseIdentifier]; + if (!roomIdOrAliasCell) + { + roomIdOrAliasCell = [[RoomIdOrAliasTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[RoomIdOrAliasTableViewCell defaultReuseIdentifier]]; + } + + [roomIdOrAliasCell render:roomIdOrAlias]; + + return roomIdOrAliasCell; + } + else if (indexPath.section == directorySection) + { + // For the cell showing the public rooms directory search result, + // skip the MatrixKit mechanism and return directly the UITableViewCell DirectoryRecentTableViewCell *directoryCell = [tableView dequeueReusableCellWithIdentifier:DirectoryRecentTableViewCell.defaultReuseIdentifier]; if (!directoryCell) { @@ -395,7 +417,7 @@ if (self.droppingCellIndexPath && (self.droppingCellIndexPath.section == indexPath.section)) { - if ([anIndexPath isEqual:self.droppingCellIndexPath]) + if ([theIndexPath isEqual:self.droppingCellIndexPath]) { static NSString* cellIdentifier = @"VectorRecentsMovingCell"; @@ -423,31 +445,31 @@ return cell; } - if (anIndexPath.row > self.droppingCellIndexPath.row) + if (theIndexPath.row > self.droppingCellIndexPath.row) { - indexPath = [NSIndexPath indexPathForRow:anIndexPath.row-1 inSection:anIndexPath.section]; + indexPath = [NSIndexPath indexPathForRow:theIndexPath.row-1 inSection:theIndexPath.section]; } } - if (self.hiddenCellIndexPath && [anIndexPath isEqual:self.hiddenCellIndexPath]) + if (self.hiddenCellIndexPath && [theIndexPath isEqual:self.hiddenCellIndexPath]) { - indexPath = [NSIndexPath indexPathForRow:anIndexPath.row-1 inSection:anIndexPath.section]; + indexPath = [NSIndexPath indexPathForRow:theIndexPath.row-1 inSection:theIndexPath.section]; } return [super tableView:tableView cellForRowAtIndexPath:indexPath]; } -- (id)cellDataAtIndexPath:(NSIndexPath *)anIndexPath +- (id)cellDataAtIndexPath:(NSIndexPath *)theIndexPath { id cellData = nil; - NSInteger row = anIndexPath.row; - NSInteger section = anIndexPath.section; + NSInteger row = theIndexPath.row; + NSInteger section = theIndexPath.section; if (self.droppingCellIndexPath && (self.droppingCellIndexPath.section == section)) { - if (anIndexPath.row > self.droppingCellIndexPath.row) + if (theIndexPath.row > self.droppingCellIndexPath.row) { - row = anIndexPath.row - 1; + row = theIndexPath.row - 1; } } @@ -473,10 +495,15 @@ - (CGFloat)cellHeightAtIndexPath:(NSIndexPath *)indexPath { - // For the cell showing the public rooms directory search result, - // skip the MatrixKit mechanism and return directly the cell height + if (indexPath.section == searchedRoomIdOrAliasSection) + { + return RoomIdOrAliasTableViewCell.cellHeight; + } + if (indexPath.section == directorySection) { + // For the cell showing the public rooms directory search result, + // skip the MatrixKit mechanism and return directly the cell height return DirectoryRecentTableViewCell.cellHeight; } @@ -607,9 +634,15 @@ conversationCellDataArray = [[NSMutableArray alloc] init]; lowPriorityCellDataArray = [[NSMutableArray alloc] init]; - directorySection = favoritesSection = conversationSection = lowPrioritySection = invitesSection = -1; + searchedRoomIdOrAliasSection = directorySection = favoritesSection = conversationSection = lowPrioritySection = invitesSection = -1; sectionsCount = 0; + if (roomIdOrAlias.length) + { + // The current search pattern corresponds to a valid room id or room alias + searchedRoomIdOrAliasSection = sectionsCount++; + } + if (!_hidePublicRoomsDirectory) { // The public rooms directory cell is then visible whatever the search activity. @@ -751,6 +784,23 @@ #pragma mark - Override MXKRecentsDataSource - (void)searchWithPatterns:(NSArray *)patternsList { + // Check whether the typed input is a room alias or a room identifier. + roomIdOrAlias = nil; + if (patternsList.count == 1) + { + NSString *pattern = patternsList[0]; + + if ([MXTools isMatrixRoomAlias:pattern] || [MXTools isMatrixRoomIdentifier:pattern]) + { + // Display this room id/alias only if it is not already joined by the user + MXKAccountManager *accountManager = [MXKAccountManager sharedManager]; + if (![accountManager accountKnowingRoomWithRoomIdOrAlias:pattern]) + { + roomIdOrAlias = pattern; + } + } + } + [super searchWithPatterns:patternsList]; if (_publicRoomsDirectoryDataSource) diff --git a/Vector/Utils/AvatarGenerator.m b/Vector/Utils/AvatarGenerator.m index 0f4fb37f1..3ab7437c6 100644 --- a/Vector/Utils/AvatarGenerator.m +++ b/Vector/Utils/AvatarGenerator.m @@ -99,7 +99,7 @@ static UILabel* backgroundLabel = nil; */ + (UIImage*)avatarForText:(NSString*)aText andColorIndex:(NSUInteger)colorIndex { - if ([aText hasPrefix:@"@"] || [aText hasPrefix:@"#"]) + if ([aText hasPrefix:@"@"] || [aText hasPrefix:@"#"] || [aText hasPrefix:@"!"]) { aText = [aText substringFromIndex:1]; } diff --git a/Vector/ViewController/DirectoryViewController.m b/Vector/ViewController/DirectoryViewController.m index 01dd7d1fa..2f505ec1d 100644 --- a/Vector/ViewController/DirectoryViewController.m +++ b/Vector/ViewController/DirectoryViewController.m @@ -107,31 +107,9 @@ } else { - // Join the room before opening it - [self startActivityIndicator]; - - // We promote here join by room alias instead of room id - NSString *roomIdOrAlias = publicRoom.roomId; - if (publicRoom.aliases.count) - { - roomIdOrAlias = publicRoom.aliases.firstObject; - } - - [dataSource.mxSession joinRoom:roomIdOrAlias success:^(MXRoom *room) { - - [self stopActivityIndicator]; - - [self openRoomWithId:publicRoom.roomId inMatrixSession:dataSource.mxSession]; - - } failure:^(NSError *error) { - - [self stopActivityIndicator]; - - NSLog(@"[DirectoryVC] Failed to join public room (%@)", publicRoom.displayname); - - // Alert user - [[AppDelegate theDelegate] showErrorAsAlert:error]; - }]; + // Preview the public room + NSString *fragment = [NSString stringWithFormat:@"/room/%@", [publicRoom.roomId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + [[AppDelegate theDelegate] handleUniversalLinkFragment:fragment]; } } diff --git a/Vector/ViewController/RecentsViewController.m b/Vector/ViewController/RecentsViewController.m index dee2142f7..ad59a606b 100644 --- a/Vector/ViewController/RecentsViewController.m +++ b/Vector/ViewController/RecentsViewController.m @@ -31,6 +31,7 @@ #import "InviteRecentTableViewCell.h" #import "DirectoryRecentTableViewCell.h" +#import "RoomIdOrAliasTableViewCell.h" #import "AppDelegate.h" @@ -630,6 +631,18 @@ // Show the directory screen [homeViewController showPublicRoomsDirectory]; } + else if ([cell isKindOfClass:[RoomIdOrAliasTableViewCell class]]) + { + NSString *roomIdOrAlias = ((RoomIdOrAliasTableViewCell*)cell).titleLabel.text; + + if (roomIdOrAlias.length) + { + // Open the room or preview it + NSString *fragment = [NSString stringWithFormat:@"/room/%@", [roomIdOrAlias stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + [[AppDelegate theDelegate] handleUniversalLinkFragment:fragment]; + } + [tableView deselectRowAtIndexPath:indexPath animated:NO]; + } else { [super tableView:tableView didSelectRowAtIndexPath:indexPath]; diff --git a/Vector/ViewController/RoomViewController.m b/Vector/ViewController/RoomViewController.m index a4c507d30..c7ce4224f 100644 --- a/Vector/ViewController/RoomViewController.m +++ b/Vector/ViewController/RoomViewController.m @@ -1956,8 +1956,15 @@ // Attempt to join the room (keep reference on the potential eventId, the preview data will be removed automatically in case of success). NSString *eventId = roomPreviewData.eventId; + // We promote here join by room alias instead of room id when an alias is available. + NSString *roomIdOrAlias = roomPreviewData.roomId; + if (roomPreviewData.roomDataSource.room.state.aliases.count) + { + roomIdOrAlias = roomPreviewData.roomDataSource.room.state.aliases.firstObject; + } + // Note in case of simple link to a room the signUrl param is nil - [self joinRoomWithRoomId:roomPreviewData.roomId andSignUrl:roomPreviewData.emailInvitation.signUrl completion:^(BOOL succeed) { + [self joinRoomWithRoomIdOrAlias:roomIdOrAlias andSignUrl:roomPreviewData.emailInvitation.signUrl completion:^(BOOL succeed) { if (succeed) { diff --git a/Vector/Views/RoomList/DirectoryRecentTableViewCell.m b/Vector/Views/RoomList/DirectoryRecentTableViewCell.m index 3eb3a8f34..eb4e721e8 100644 --- a/Vector/Views/RoomList/DirectoryRecentTableViewCell.m +++ b/Vector/Views/RoomList/DirectoryRecentTableViewCell.m @@ -18,10 +18,20 @@ #import "PublicRoomsDirectoryDataSource.h" +#import "VectorDesignValues.h" + @implementation DirectoryRecentTableViewCell #pragma mark - Class methods +- (void)awakeFromNib +{ + [super awakeFromNib]; + + self.titleLabel.textColor = kVectorTextColorBlack; + self.descriptionLabel.textColor = kVectorTextColorGray; +} + - (void)render:(PublicRoomsDirectoryDataSource *)publicRoomsDirectoryDataSource { self.userInteractionEnabled = NO; diff --git a/Vector/Views/RoomList/DirectoryRecentTableViewCell.xib b/Vector/Views/RoomList/DirectoryRecentTableViewCell.xib index c77d88e80..023c927f2 100644 --- a/Vector/Views/RoomList/DirectoryRecentTableViewCell.xib +++ b/Vector/Views/RoomList/DirectoryRecentTableViewCell.xib @@ -1,8 +1,8 @@ - + - + @@ -13,7 +13,7 @@ - + @@ -33,7 +33,7 @@